DECODE Function in Oracle Froms 6.0
I have discovered that in Oracle Forms 6.0 (Version 6.0.5.34.0) the DECODE Function performs an implicit TO_CHAR conversion that the DECODE Function in the Oracle 8 database does not.
I discovered this when working with dates on the form. Dates prior to 2000 were not formatting correctly and all dates were not sorting correctly. By adding TO_DATE with the correct format mask outside of the DECODE statement the correct results were returned.
When trouble shooting this through SQL Navigator connected directly to the database, the correct results were returned without having to use the TO_DATE function.
Why don't you have any join conditions specified for your two inline views cr and de?
If you want help with a query you should post DDL and inserts statements to create enough test data for someone to produce the set of results that you are looking for.
HTH -- Mark D Powell --
Similar Messages
-
DECODE function in Oracle gives duplicate data
Hi,
I want to retrieve distinct result using decode function and given below are the queries for that.
SELECT DISTINCT O.*, DECODE(TA,'AP',AMT,'AC1',AMT,'AC2',AMT,'AC3',AMT,'AC4',AMT,NULL) AS CA,
DECODE(TA,'AD1',AMT,NULL) AS DA FROM HT O, HIS H, V_CV
WHERE O.HID=H.HID AND H.HTYP='TRN' AND O.HID = V.HID AND V.CID = '5' ORDER BY CA ASC;
which gives me
HID TA PT AMT CA DA
2 A V 4.1 4.1 null
3 C V 14.02 14.02 null
1 D V 5.1 null 5.1
4 D V 6.21 null 6.21
which is correct but i want to do sorting on two different column which do not exit in the database and they are dynamic.So i Modified the Query but i am getting duplicate results
SELECT DISTINCT O.*,
DECODE(o.TA,cr.TA,o.AMT,NULL) AS CA,
DECODE(o.TA,de.TA,o.AMT,NULL) AS DA
FROM HT O,
HIS H,
V_CV,
(select TA from RTD where Ttype= 'C') cr,
(select TA from RTD where Ttype= 'D') de
WHERE
O.HID=H.HID
AND H.HTYP='TRN'
AND O.HID = V.HID
AND V.CID = '5'
ORDER BY CA ASC
which gives me
HID TA PT AMT CA DA
2 A V 4.1 4.1 null
3 C V 14.02 14.02 null
3 C V 14.02 null null
1 D V 5.1 null 5.1
1 D V 5.1 null null
4 D V 6.21 null 6.21
2 A V 4.1 null null
which is obviously giving HID 2,3,1 as duplicate value since DECODE select a value and compares with all item where i want only single comparison.
Any help regarding this would be appreciated.
Edited by: Pawanchoure on Jul 5, 2011 7:14 AMWhy don't you have any join conditions specified for your two inline views cr and de?
If you want help with a query you should post DDL and inserts statements to create enough test data for someone to produce the set of results that you are looking for.
HTH -- Mark D Powell -- -
About Decode Function in oracle(on 28th)
Hi all
Can i use Decode function with Distinct as following.
SUM(DISTINCT DECODE(LR.QUESTIONNAIRE_ID,62, L.WORK_SPACE))
RegardsHi,
The argument to SUM can be any numeric expression, including a DECODE statement that evaluates to a number.
"SUM (DISTINCT ..." is very suspicious. If you have three rows, with values 1, 1 and 3, the "SUM (DISTINCT" is 4. Is that what you want?
Perhaps your problem is that whenever you have more than one row, they will always be identical (e.g., a one-to-may join), so you have rows with 1, 1, and 1, from which you want to return 1. Most people do that by adding the value to the GROUP BY list, or by using MAX or MIN instead of SUM: they get the same results, but the code is clearer, and it works on non-numeric columns. -
How to use decode function in oracle apex 3.2.1
Hello Friends,
how to use decode
var_decode := 'decode'||'('|| var1 ||','|| -800000000000000||','||'.A'||','||
appreciate your help.
regards/kumar
Edited by: kumar73 on Apr 23, 2010 12:25 PM
Edited by: kumar73 on Apr 23, 2010 12:27 PMHey just on this particular point, there's a handy PL/SQL method for escaping quotation characters which may reduce the complexity of the string.
For example, if I had a string:
I can't understand why quoting my 'quote' characters never seems to "work"!and I wanted to pass that into a variable, I could do this:
vc_foo:= 'I can''t understand why my ''quote'' characters never seems to "work"!';or I could use the q function, whereby you enclose your string within a quote delimiter of your choice, like so:
vc_foo:= q'^I can't understand why quoting my 'quote' characters never seems to "work"!^';
note: I used the caret (^) character by convention but any valid character will do
...all of which leaves your original string more or less unadulterated.
I find this particularly useful for generating dynamic SQL and dynamic PL/SQL, as it leave the query looking a tad more readable, although if you are chaining together multiple strings with double-pipes, it can make it a little muddier. I find it particularly useful if I'm going to deal with string data from, for example, a field with Irish-derived surnames such as "O'Reilly"...
Give it a go! -
Hi all,
i want to know abt decode function in oracle-sql
i..e passing the parameters in decode using decode using ":" bind parameter
select JOB, decode(:j,'CLERK','MANAGER','ANALYST','EXEC',JOB) FROM EMP;
i declared the j variable in sql environment
VARIABLE J VARCHAR2(20);
i exec the query
and passed as the clerk as input parameter
but iam getting the o/p as
JOB DECODE(:J
MANAGER MANAGER
MANAGER MANAGER
MANAGER MANAGER
SALESMAN SALESMAN
SALESMAN SALESMAN
SALESMAN SALESMAN
CLERK CLERK
SALESMAN SALESMAN
ANALYST ANALYST
CLERK CLERK
ANALYST ANALYST
JOB DECODE(:J
CLERK CLERK
12 rows selected.
SQL> PRINT J;
J
im not getting o/p
so please hlelp me only : should be used not &
this is my first thread.
execuse me if any mistakes
tons of thanks in advance to allSORRY DAVE,ROD FOR NOT BEING CLEAR,
IAM WORKING WITH EMP TABLE THE DATA IN IT IS LIKE THIS
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7499 chaitu SALESMAN 7698 20-FEB-81 1600 300 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7900 JAMES CLERK 7698 03-DEC-81 950 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7369 SMITH CLERK 7902 17-DEC-80 800 20
7788 SCOTT ANALYST 7566 09-DEC-82 3000 20
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7876 ADAMS CLERK 7788 12-JAN-83 1100 20
AND I USED DECODE FUNCTION
select JOB BEFOREPROMOTION, decode(job,'CLERK','MANAGER','ANALYST','EXEC') PROMOTION FROM EMP
BEFOREPRO PROMOTI
MANAGER
MANAGER
MANAGER
SALESMAN
SALESMAN
SALESMAN
CLERK MANAGER
SALESMAN
ANALYST EXEC
CLERK MANAGER
ANALYST EXEC
I..E ALL THE CLERKS TO MANAGERS AND SAME THING WITH ANALYST
OK
NOW I WILL SHOW U ANOTHER QUERY
select job,decode(job,'CLERK','MANAGER','ANALYST','EXEC',JOB) FROM EMP where job=&job;
Enter value for job: 'CLERK'
old 1: select job,decode(job,'CLERK','MANAGER','ANALYST','EXEC',JOB) FROM EMP where job=&job
new 1: select job,decode(job,'CLERK','MANAGER','ANALYST','EXEC',JOB) FROM EMP where job='CLERK'
JOB DECODE(JO
CLERK MANAGER
CLERK MANAGER
CLERK MANAGER
HERE OBSERVE THAT I PASSED JOB ='CLERKS AS PARAMETER AFTER EXECUTING THE QUERY
IT ASKED LIKE THIS AND SHOWED THE REPLACED VALUES
Enter value for job: 'CLERK'
AS SHOWN ABOVE
FOR THIS TO PASS VALUE
IN TO THE QUERY BY USING AMPERSAND('&')
TO TAKE INPUT AS CLERK
IT CHECKED AND RETURNED THE VALUE
IN THE SIMILAR WAY CAN I USE ":" COLON
TO PASS PARAMETERS
IN TO THE QUERY
CAN I USE IT
REGARDS,
PHANI
Edited by: user10652894 on Nov 26, 2008 3:24 AM -
How to convert rows into columns with decode function
Hi,
How to convert rows into columns with the help of decode function in oracle.
thanks and regards
P Prakashsay
col1 col2
1 10
2 20
3 30
then use
select col1,
sum(decode(col2,10,10)) "new1"
sum(decode(col2,20,20))"new2"
sum(decode(col2,30,30))"new3"
from table_name
group by col1;
we used sum u can use ny function if wont u have to give the column name i.e col2 name also
so i think u got it nw
regards -
Hi,
I have a field in my table that stores an ID which is encoded using a C function. (third party database)
I have also been provided the C function that decodes that field to display the actual value. I have compiled this code using Visual Studio .Net 2003 to a dll file, but do not know how to use it in Oracle. Or are there other ways to use this decode function in Oracle?
I am on 9i database, Windows 2003 server.
Any help is appreciated.
Thank you.Hi, see:
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:9087161189226 -
Issue While Calling a Function in Crystal from Oracle
Post Author: digik
CA Forum: Crystal Reports
Hi there,
I have a function in Oracle which fetches values in to table type. When I run this query in Oracle SQL Plus it is giving me records. But the same query in Crystal is giving zero records?
Function SQL
Create or Replace Function getReport(numTrades IN NUMBER,AsOfDateFrom IN DATE,AsOfDateTo IN DATE,compareDate IN DATE,productType IN VARCHAR2,dataGrade IN NUMBER,DataGradeThreshold IN NUMBER)Return top_movers_type_tableAStableRow top_movers_type := top_movers_type(NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL);resulttable top_movers_type_table := top_movers_type_table(); IDvar VARCHAR2(12); CURR_DATEvar DATE; PRODUCTvar VARCHAR2(6); DESCRIPTIONvar VARCHAR2(100); COUPONvar NUMBER(14,10); SETLMNT_DATEvar DATE; CURR_PRICEvar NUMBER(14,10); COMPARE_PRICEvar NUMBER(14,10); PRICE_DELTAvar NUMBER(24,20); PRICE_DELTA_PCTvar NUMBER(24,20); TRD_AMT_OR_UPBvar NUMBER(20,2); UPB_PRICE_DELTAvar NUMBER(35,15); COMPARE_DATEvar DATE; DATA_GRADEvar NUMBER(4,0); TRADE_PRICEvar NUMBER(14,10); TRADE_DATEvar DATE; PROD_SPECIFIC_FLDvar VARCHAR2(10); COMPARE_PRICE_FROMvar VARCHAR2(10); TOT_COUNTvar NUMBER(10); CURSOR TopmoversCursor IS select ID,CURR_DATE, PRODUCT, DESCRIPTION, COUPON, SETLMNT_DATE, CURR_PRICE, COMPARE_PRICE, PRICE_DELTA, PRICE_DELTA_PCT, TRD_AMT_OR_UPB, UPB_PRICE_DELTA, COMPARE_DATE, DATA_GRADE, TRADE_PRICE, TRADE_DATE, PROD_SPECIFIC_FLD, COMPARE_PRICE_FROM, TOT_COUNT from ( select SECU_CUSIP_ID ID, FA_MTM_EFF_DT CURR_DATE, FA_TYP_DESC PRODUCT , FA_PTR COUPON, TRD_STLM_DT SETLMNT_DATE, CURR_PRC CURR_PRICE, DATA_QLTY_CD DATA_GRADE, TRD_PRC_PCT TRADE_PRICE, SECU_TRD_DT TRADE_DATE, SECU_STAMPS_TYP_DESC DESCRIPTION, COMPARE_PRC COMPARE_PRICE, UPB TRD_AMT_OR_UPB, COMPARE_DATE COMPARE_DATE, COMPARE_PRC_FROM COMPARE_PRICE_FROM, PROD_SPC_FLD PROD_SPECIFIC_FLD, PRC_DELTA PRICE_DELTA, ABS_PRC_DELTA, UPB_PRICE_DELTA, PRC_DELTA_PCT PRICE_DELTA_PCT, dense_rank() over (order by ABS_PRC_DELTA desc) as TOPN, count(SECU_CUSIP_ID) over () as TOT_COUNT from ( select SECU_CUSIP_ID, FA_MTM_EFF_DT,FA_TYP_DESC,FA_PTR, TRD_STLM_DT, CURR_PRC ,DATA_QLTY_CD, TRD_PRC_PCT , SECU_TRD_DT, SECU_STAMPS_TYP_DESC , COMPARE_PRC, UPB, COMPARE_DATE, COMPARE_PRC_FROM, PROD_SPC_FLD, (CURR_PRC - COMPARE_PRC) as PRC_DELTA, abs(CURR_PRC - COMPARE_PRC) as ABS_PRC_DELTA, ((CURR_PRC - COMPARE_PRC)*100)/COMPARE_PRC as PRC_DELTA_PCT, ((CURR_PRC - COMPARE_PRC) * UPB)/100000000 as UPB_PRICE_DELTA from ( select F1.SECU_CUSIP_ID, F1.FA_MTM_EFF_DT,F1.FA_TYP_DESC,F1.FA_PTR, F1.TRD_STLM_DT, F1.FA_MTM_PRC_PCT as CURR_PRC ,F1.DATA_QLTY_CD, F1.TRD_PRC_PCT , F1.SECU_TRD_DT, decode(MVS.SECU_STAMPS_TYP_DESC,null,'N/A','','N/A',MVS.SECU_STAMPS_TYP_DESC) SECU_STAMPS_TYP_DESC , NVL(F2.FA_MTM_PRC_PCT,F1.TRD_PRC_PCT) COMPARE_PRC, F1.FA_CURR_UPB_AMT/1000000 as UPB, NVL(F2.FA_MTM_EFF_DT,F1.SECU_TRD_DT) as COMPARE_DATE, Decode(F2.FA_MTM_PRC_PCT,null,'TRADE','INVENTORY') as COMPARE_PRC_FROM, DECODE(F1.FA_TYP_DESC, 'AGNCY',REMIC_AGNC_DTL.REMIC_CLS_PRIN_PMT_TYP_CD, 'MBS',MBS_DTL.MBS_WALA_NO, 'ARM',ARM_DTL.MBS_WALA_NO, 'REMIC',REMIC_DTL.REMIC_TYP_CD, 'MFMBS',MF_MBS_DTL.SECU_YLD_MANT_DELTA_TERM, 'CAB','N/A', 'PCERT','N/A', 'MRB','N/A', 'STRIP','N/A', 'SFWL','N/A', 'ARMWL','N/A', 'MFWL','N/A','NULL') as PROD_SPC_FLD from FA_MARK F1 , FA_MARK F2, MV_SEC_TYP MVS, MBS_DTL, MRB_DTL, MF_MBS_DTL ,REMIC_AGNC_DTL ,REMIC_DTL, ARM_DTL where F1.SECU_CUSIP_ID = F2.SECU_CUSIP_ID () and F1.FA_MTM_ID = MBS_DTL.FA_MTM_ID () and F1.FA_MTM_ID = MRB_DTL.FA_MTM_ID () and F1.FA_MTM_ID = MF_MBS_DTL.FA_MTM_ID () and F1.FA_MTM_ID = REMIC_AGNC_DTL.FA_MTM_ID () and F1.FA_MTM_ID = REMIC_DTL.FA_MTM_ID () and F1.FA_MTM_ID = ARM_DTL.FA_MTM_ID () and F1.FA_TYP_DESC = F2.FA_TYP_DESC () and F1.TRD_STAT_CD = F2.TRD_STAT_CD () and F1.SECU_STAMPS_TYP_CD = MVS.SECU_STAMPS_TYP_CD () and F1.FA_MTM_EFF_DT >= '01-May-2007' and F1.FA_MTM_EFF_DT <= '31-May-2007' and F1.DATA_QLTY_CD >= 1 and F1.DATA_QLTY_CD <= 10 and F1.TRD_STAT_CD = 5 and F1.FA_TYP_DESC = 'MBS' and F2.FA_MTM_EFF_DT() = '30-Apr-2007' and F2.DATA_QLTY_CD ()>= 1 and F2.DATA_QLTY_CD (+)<= 10 ) where COMPARE_PRC > 0 order by ABS_PRC_DELTA desc ) ) where TOPN <= numTrades;BEGIN
OPEN TopmoversCursor(numTrades ,AsOfDateFrom ,AsOfDateTo ,compareDate ,productType ,dataGrade ,DataGradeThreshold); LOOP FETCH TopmoversCursor INTO IDvar,CURR_DATEvar, PRODUCTvar, DESCRIPTIONvar, COUPONvar, SETLMNT_DATEvar, CURR_PRICEvar, COMPARE_PRICEvar, PRICE_DELTAvar, PRICE_DELTA_PCTvar, TRD_AMT_OR_UPBvar, UPB_PRICE_DELTAvar, COMPARE_DATEvar, DATA_GRADEvar, TRADE_PRICEvar, TRADE_DATEvar, PROD_SPECIFIC_FLDvar, COMPARE_PRICE_FROMvar, TOT_COUNTvar; EXIT WHEN TopmoversCursor%NOTFOUND; ResultTable.extend; ResultTable(resultTable.Last):= top_movers_type(IDvar,CURR_DATEvar, PRODUCTvar, DESCRIPTIONvar, COUPONvar, SETLMNT_DATEvar, CURR_PRICEvar, COMPARE_PRICEvar, PRICE_DELTAvar, PRICE_DELTA_PCTvar, TRD_AMT_OR_UPBvar, UPB_PRICE_DELTAvar, COMPARE_DATEvar, DATA_GRADEvar, TRADE_PRICEvar, TRADE_DATEvar, PROD_SPECIFIC_FLDvar, COMPARE_PRICE_FROMvar, TOT_COUNTvar); END LOOP;CLOSE TopmoversCursor;RETURN resultTable;END getReport;/
Select Query
select * from (getReport(1,sysdate,sysdate,sysdate,0,2,4))Post Author: digik
CA Forum: Crystal Reports
Hi there,
I have a function in Oracle which fetches values in to table type. When I run this query in Oracle SQL Plus it is giving me records. But the same query in Crystal is giving zero records?
Function SQL
Create or Replace Function getReport(numTrades IN NUMBER,AsOfDateFrom IN DATE,AsOfDateTo IN DATE,compareDate IN DATE,productType IN VARCHAR2,dataGrade IN NUMBER,DataGradeThreshold IN NUMBER)Return top_movers_type_tableAStableRow top_movers_type := top_movers_type(NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL);resulttable top_movers_type_table := top_movers_type_table(); IDvar VARCHAR2(12); CURR_DATEvar DATE; PRODUCTvar VARCHAR2(6); DESCRIPTIONvar VARCHAR2(100); COUPONvar NUMBER(14,10); SETLMNT_DATEvar DATE; CURR_PRICEvar NUMBER(14,10); COMPARE_PRICEvar NUMBER(14,10); PRICE_DELTAvar NUMBER(24,20); PRICE_DELTA_PCTvar NUMBER(24,20); TRD_AMT_OR_UPBvar NUMBER(20,2); UPB_PRICE_DELTAvar NUMBER(35,15); COMPARE_DATEvar DATE; DATA_GRADEvar NUMBER(4,0); TRADE_PRICEvar NUMBER(14,10); TRADE_DATEvar DATE; PROD_SPECIFIC_FLDvar VARCHAR2(10); COMPARE_PRICE_FROMvar VARCHAR2(10); TOT_COUNTvar NUMBER(10); CURSOR TopmoversCursor IS select ID,CURR_DATE, PRODUCT, DESCRIPTION, COUPON, SETLMNT_DATE, CURR_PRICE, COMPARE_PRICE, PRICE_DELTA, PRICE_DELTA_PCT, TRD_AMT_OR_UPB, UPB_PRICE_DELTA, COMPARE_DATE, DATA_GRADE, TRADE_PRICE, TRADE_DATE, PROD_SPECIFIC_FLD, COMPARE_PRICE_FROM, TOT_COUNT from ( select SECU_CUSIP_ID ID, FA_MTM_EFF_DT CURR_DATE, FA_TYP_DESC PRODUCT , FA_PTR COUPON, TRD_STLM_DT SETLMNT_DATE, CURR_PRC CURR_PRICE, DATA_QLTY_CD DATA_GRADE, TRD_PRC_PCT TRADE_PRICE, SECU_TRD_DT TRADE_DATE, SECU_STAMPS_TYP_DESC DESCRIPTION, COMPARE_PRC COMPARE_PRICE, UPB TRD_AMT_OR_UPB, COMPARE_DATE COMPARE_DATE, COMPARE_PRC_FROM COMPARE_PRICE_FROM, PROD_SPC_FLD PROD_SPECIFIC_FLD, PRC_DELTA PRICE_DELTA, ABS_PRC_DELTA, UPB_PRICE_DELTA, PRC_DELTA_PCT PRICE_DELTA_PCT, dense_rank() over (order by ABS_PRC_DELTA desc) as TOPN, count(SECU_CUSIP_ID) over () as TOT_COUNT from ( select SECU_CUSIP_ID, FA_MTM_EFF_DT,FA_TYP_DESC,FA_PTR, TRD_STLM_DT, CURR_PRC ,DATA_QLTY_CD, TRD_PRC_PCT , SECU_TRD_DT, SECU_STAMPS_TYP_DESC , COMPARE_PRC, UPB, COMPARE_DATE, COMPARE_PRC_FROM, PROD_SPC_FLD, (CURR_PRC - COMPARE_PRC) as PRC_DELTA, abs(CURR_PRC - COMPARE_PRC) as ABS_PRC_DELTA, ((CURR_PRC - COMPARE_PRC)*100)/COMPARE_PRC as PRC_DELTA_PCT, ((CURR_PRC - COMPARE_PRC) * UPB)/100000000 as UPB_PRICE_DELTA from ( select F1.SECU_CUSIP_ID, F1.FA_MTM_EFF_DT,F1.FA_TYP_DESC,F1.FA_PTR, F1.TRD_STLM_DT, F1.FA_MTM_PRC_PCT as CURR_PRC ,F1.DATA_QLTY_CD, F1.TRD_PRC_PCT , F1.SECU_TRD_DT, decode(MVS.SECU_STAMPS_TYP_DESC,null,'N/A','','N/A',MVS.SECU_STAMPS_TYP_DESC) SECU_STAMPS_TYP_DESC , NVL(F2.FA_MTM_PRC_PCT,F1.TRD_PRC_PCT) COMPARE_PRC, F1.FA_CURR_UPB_AMT/1000000 as UPB, NVL(F2.FA_MTM_EFF_DT,F1.SECU_TRD_DT) as COMPARE_DATE, Decode(F2.FA_MTM_PRC_PCT,null,'TRADE','INVENTORY') as COMPARE_PRC_FROM, DECODE(F1.FA_TYP_DESC, 'AGNCY',REMIC_AGNC_DTL.REMIC_CLS_PRIN_PMT_TYP_CD, 'MBS',MBS_DTL.MBS_WALA_NO, 'ARM',ARM_DTL.MBS_WALA_NO, 'REMIC',REMIC_DTL.REMIC_TYP_CD, 'MFMBS',MF_MBS_DTL.SECU_YLD_MANT_DELTA_TERM, 'CAB','N/A', 'PCERT','N/A', 'MRB','N/A', 'STRIP','N/A', 'SFWL','N/A', 'ARMWL','N/A', 'MFWL','N/A','NULL') as PROD_SPC_FLD from FA_MARK F1 , FA_MARK F2, MV_SEC_TYP MVS, MBS_DTL, MRB_DTL, MF_MBS_DTL ,REMIC_AGNC_DTL ,REMIC_DTL, ARM_DTL where F1.SECU_CUSIP_ID = F2.SECU_CUSIP_ID () and F1.FA_MTM_ID = MBS_DTL.FA_MTM_ID () and F1.FA_MTM_ID = MRB_DTL.FA_MTM_ID () and F1.FA_MTM_ID = MF_MBS_DTL.FA_MTM_ID () and F1.FA_MTM_ID = REMIC_AGNC_DTL.FA_MTM_ID () and F1.FA_MTM_ID = REMIC_DTL.FA_MTM_ID () and F1.FA_MTM_ID = ARM_DTL.FA_MTM_ID () and F1.FA_TYP_DESC = F2.FA_TYP_DESC () and F1.TRD_STAT_CD = F2.TRD_STAT_CD () and F1.SECU_STAMPS_TYP_CD = MVS.SECU_STAMPS_TYP_CD () and F1.FA_MTM_EFF_DT >= '01-May-2007' and F1.FA_MTM_EFF_DT <= '31-May-2007' and F1.DATA_QLTY_CD >= 1 and F1.DATA_QLTY_CD <= 10 and F1.TRD_STAT_CD = 5 and F1.FA_TYP_DESC = 'MBS' and F2.FA_MTM_EFF_DT() = '30-Apr-2007' and F2.DATA_QLTY_CD ()>= 1 and F2.DATA_QLTY_CD (+)<= 10 ) where COMPARE_PRC > 0 order by ABS_PRC_DELTA desc ) ) where TOPN <= numTrades;BEGIN
OPEN TopmoversCursor(numTrades ,AsOfDateFrom ,AsOfDateTo ,compareDate ,productType ,dataGrade ,DataGradeThreshold); LOOP FETCH TopmoversCursor INTO IDvar,CURR_DATEvar, PRODUCTvar, DESCRIPTIONvar, COUPONvar, SETLMNT_DATEvar, CURR_PRICEvar, COMPARE_PRICEvar, PRICE_DELTAvar, PRICE_DELTA_PCTvar, TRD_AMT_OR_UPBvar, UPB_PRICE_DELTAvar, COMPARE_DATEvar, DATA_GRADEvar, TRADE_PRICEvar, TRADE_DATEvar, PROD_SPECIFIC_FLDvar, COMPARE_PRICE_FROMvar, TOT_COUNTvar; EXIT WHEN TopmoversCursor%NOTFOUND; ResultTable.extend; ResultTable(resultTable.Last):= top_movers_type(IDvar,CURR_DATEvar, PRODUCTvar, DESCRIPTIONvar, COUPONvar, SETLMNT_DATEvar, CURR_PRICEvar, COMPARE_PRICEvar, PRICE_DELTAvar, PRICE_DELTA_PCTvar, TRD_AMT_OR_UPBvar, UPB_PRICE_DELTAvar, COMPARE_DATEvar, DATA_GRADEvar, TRADE_PRICEvar, TRADE_DATEvar, PROD_SPECIFIC_FLDvar, COMPARE_PRICE_FROMvar, TOT_COUNTvar); END LOOP;CLOSE TopmoversCursor;RETURN resultTable;END getReport;/
Select Query
select * from (getReport(1,sysdate,sysdate,sysdate,0,2,4)) -
SQL Devloper Migration from SQL SerProcedurs created as Functions in Oracle
Hi All,
This is the first time I am using SQL Deveoper to migrate SQL Server database to Oracle.
I have SQL Developer 3 and I did migration from SQL Sever 2008 to Oracle 10g using online migration.
Everything was done perfectly, but there are some extra tables created in Oracle which are not present in SQL Server database.
And also I observed lot of programs which are stored procedures in SQL Server are converted as functions in Oracle.
Does someone knows how to fix this problem.
ThanksHi,
A SQL*Server stored procedure can be converted to an Oracle function depending on how it is written and what it is doing. In the documentation -
Oracle® SQL Developer
Supplementary Information for Microsoft SQL Server and
Sybase Adaptive Server Migrations
In Chapter 3 in the section -
3.4.2 Function
It says under Table 3-6 -
In Microsoft SQL Server or Sybase
Adaptive Server, you can convert a stored
procedure to a function in Oracle because
the stored procedure in Microsoft SQL
Server or Sybase Adaptive Server can
RETURN an integer value to the calling
routine using a RETURN statement. A
stored procedure returns a status value to
the calling routine even in the absence of
a RETURN statement. The returned status
is equal to ZERO if the procedure
execution is successful or NON-ZERO if
the procedure fails for some reason. The
RETURN statement can return only
integer values
And what tables do you see in oracle that are not there in SQL*Server ? Some tables are created as part of the migration as they are needed to have the same functionality as in SQL*Server.
Does your migrated Oracle database work in the same way as the SQL*Server database ? If not, then please give use specific examples and we can follow up.
Regards,
Mike -
Oracle from DB2 federation - function mapping
I need to map an Oracle function (instr) from an InfoSphere function (postion) from the DB2 database, so this is more of a DB2 question, but never could get an answer out of DB2ools ;-)
I have created the wrapper, server, user mapping and nicknames in DB2, but need to create a function mapping in DB2 between their "position(search, source, code) to our instr(search, source). This is a mapping of system functions, so I am not sure if it is possible... and their documentation is kludgy at best. The problem is this: POSITION(search, source, code), where code represents UTF-16, UTF-32 or code page translation. I want to force this syntax to pass to Oracle as INSTR(search, source), dropping their 'code'.
This is the only function that does not work properly from the DB2 side to us. If anyone has the DB2 create function mapping command to do the above, my appreciation for the answer and condolences that you actually had to go thru the reams of IBM documentation.Addendum ...
OK I found what the DIGIT function does.
I am not sure if there is a function in Oracle that maps directly to DIGIT function in DB2
but you can do something like this:
select lpad(replace(to_char(abs(n)),'.'),
(select to_number(data_precision) from user_tab_columns where table_name = 'A' and column_name = 'N'),'0')
from a
In the SQL above n is the column in table A. Data_precision column gets the size of the column.
Option 2:
You could write your own function in Oracle to do what the SQL above does
create or replace function digit (col_val in number, col_name IN varchar2, tab_name IN varchar2) return varchar2
as
v_val varchar2(100);
v_prec number;
begin
select to_number(data_precision) into v_prec from user_tab_columns where table_name = upper(tab_name) and column_name = upper(col_name);
v_val := lpad(replace(to_char(abs(col_val)),'.'),v_prec,'0');
return v_val;
end;
Then use the function as follows:
select digit(n,'N','A') from a
Shakti
http://www.impact-sol.com
Developers of Guggi Oracle - Tool for DBAs and Developers
Message was edited by:
skgoel -
How to run the Oracle Triggers,Functions and Procedures from java
Hi ,
I want to execute the Oracle's Triggers, Functions and Procedures from java as like executing the SQL commands by using Execute statements.
Or can we have some other option for doing this.
Plz help me ...you can use CallableStatement interface of JDBC to execute any DBMS triger,stored procedure ....
refer any of the JDBC book for extra help
hope you got it
Azeem Ahmed -
Using oracle decode function in ssQueryText
Hi,
I am populating the values for ssQueryText, ssSortField etc from the fragment parameters. Then i am using these field values in fragment jsp, put those values in the serverbean and executing the service. I am getting the results, and the results are also sorted the way i want.
The problem is i want to fetch the data from the DB, while fetching i want to check a column value, based on the value i want to temporarily modify that column value and only after modifying i want to sort the data in the table based on the value of modified column.
If some one has tried this earlier please suggest.
Thanks,
Santoshstmt.executeQuery("select blahblahblah, DECODE(fieldName, password), blahblahblah FROM blahblah...")
-
Oracle version: 9.2.0.1.0
Procob version: 9.2.0.1.0
Cobol version: 3.1.11
O.S. version: Windows XP
We have a pro*cobol file with the next conversion rule into a select defined with a cursor.
NVL(TO_CHAR(A.F_ALTA,'YYYYMMDD'),' '),
NVL(TO_CHAR(A.F_ESTADO,'YYYYMMDD'),' '),
we store the result data through a fetch of the cursor into two variables (W-F-ALTA and W-F-ESTADO) When the program executes an insert of these two values in a target table, we define the next conversion rule:
TO_DATE(DECODE(:W-F-ALTA,' ',NULL,:W-F-ALTA),'YYYYMMDD'),
TO_DATE(DECODE(:W-F-ESTADO,' ',NULL,:W-F-ESTADO),'YYYYMMDD')
Pro*Cobol and Cobol does not have errors when we precompile and compile the program but, when we execute the generated exe file, Oracle displays the next error:
ORA-01841 (full) year must be between -4713 and +9999, and not be 0
We think that the DECODE function is not understood by the cobol or pro*cobol interpreter. If we execute the same code without the DECODE function (only with TO_DATE function) there is no errors in the execution of the program
somebody knows if there are reported problems with this DECODE function in Pro*Cobol or Cobol and how to solve them?
ThanksTO_DATE(DECODE(:W-F-ALTA,' ',NULL,:W-F-ALTA),'YYYYMMDD'),
TO_DATE(DECODE(:W-F-ESTADO,' ',NULL,:W-F-ESTADO),'YYYYMMDD')The problem is with the input values of :W-F-ALTA and :W-F-ESTADO. Using the first line as an example, what you are saying is if :W-F-ALTA is ' ', substitute it with NULL, any other value should be :W-F-ALTA, then output the TO_DATE value of whatever the result is.
So if the value of :W-F-ALTA is the wrong charater or in the wrong input format, TO_DATE function does not understand it.
See examples of success and failures below with your Bind variables substituted with typical values.
SQL> select TO_DATE(DECODE(' ',' ',NULL,'20060830'),'YYYYMMDD') from dual;
TO_DATE(D
SQL> select TO_DATE(DECODE('1999-01-01',' ','NULL','20060830'),'YYYYMMDD') from dual;
TO_DATE(D
30-AUG-06
SQL> select TO_DATE(DECODE('SHOULD_ERROR',' ','NULL','SHOULD_ERROR'),'YYYYMMDD') from dual;
select TO_DATE(DECODE('SHOULD_ERROR',' ','NULL','SHOULD_ERROR'),'YYYYMMDD') from dual
ERROR at line 1:
ORA-01841: (full) year must be between -4713 and +9999, and not be 0
SQL> select TO_DATE(DECODE('20060830',' ','NULL','20060830'),'YYYYMMDD') from dual;
TO_DATE(D
30-AUG-06
SQL> select TO_DATE(DECODE('12345678',' ','NULL','12345678'),'YYYYMMDD') from dual;
select TO_DATE(DECODE('12345678',' ','NULL','12345678'),'YYYYMMDD') from dual
ERROR at line 1:
ORA-01843: not a valid month
SQL> -
Problem using DECODE() function with a Query of Queries
I
posted
on my blog about an issue I was having trying to use the PL/SQL
DECODE() function with a Coldfusion Query of Queries. This function
works fine when you query a database for information. However, when
you query another query, it seems that CF doesn't recognize it. I
got errors stating that it found a left parenthesis where it
expected a FROM key word. Here is a simplified version of what I am
trying to do:
quote:
<!--- Simulated query; similar to what I was calling from
my database --->
<cfscript>
qOriginal = queryNew("Name,Email,CountryCode",
"VarChar,VarChar,VarChar");
newRow = queryAddRow(qOriginal, 5);
querySetCell(qOriginal, "Name", "Joe", 1);
querySetCell(qOriginal, "Email", "[email protected]", 1);
querySetCell(qOriginal, "CountryCode", "AMER", 1);
querySetCell(qOriginal, "Name", "Sally", 2);
querySetCell(qOriginal, "Email", "[email protected]", 2);
querySetCell(qOriginal, "CountryCode", "AMER", 2);
querySetCell(qOriginal, "Name", "Bob", 3);
querySetCell(qOriginal, "Email", "[email protected]", 3);
querySetCell(qOriginal, "CountryCode", "ASIA", 3);
querySetCell(qOriginal, "Name", "Mary", 4);
querySetCell(qOriginal, "Email", "[email protected]", 4);
querySetCell(qOriginal, "CountryCode", "EURO", 4);
querySetCell(qOriginal, "Name", "John", 5);
querySetCell(qOriginal, "Email", "[email protected]", 5);
querySetCell(qOriginal, "CountryCode", "EURO", 5);
</cfscript>
<cfquery name="qCountries" dbtype="query">
SELECT DISTINCT(CountryCode) AS CountryCode,
DECODE(states, "AMER", "North America & Canada",
"EURO", "Europe & Africa", "ASIA", "Japan &
Asia","") CountryName
FROM qOriginal
ORDER BY CountryCode
</cfquery>
<cfdump var="#qCountries#">
<!--- ========== END OF CODE ========== --->
So running this returned the following error:
Query Of Queries syntax error.
Encountered "(. Incorrect Select Statement, Expecting a
'FROM', but encountered '(' instead, A select statement should have
a 'FROM' construct.
Does anybody know why this doesn't work? Is it just not
supported? Please note that I have also tried to use the CASE()
function instead of DECODE() and that resulted in basically the
same error. For now I an looping over my distinct query with a
switch statement and manually loading a new query with the data how
I want it. But it would be a lot cleaner and less code to have the
DECODE() to work. Thx!DECODE() is an Oracle function, not generic SQL. Q-of-Q is a
very limited subset of SQL and lacks many functions and clauses
available in standard SQL, especially what you may be used to using
in your particular RDBMS.
See
Query
of Queries user guide
Phil -
Hi All,
I am new to sql. I want to use decode for BLOB datatype. For this i written a query like below.
Here user_data is of type BLOB.
select DECODE(length(user_data), 0, null, file_data) user_data from user_table;
I have tried the other way by using case like below. Its worked fine
select
CASE
WHEN LENGTH(user_data )=0
THEN NULL
ELSE user_data
END user_data from user_table;
What i made wrong in the first query?
Thanks
Jimmi>
Its just a wrong typo
>
Thanks.
The problem is that this decode
select DECODE(length(user_data), 0, null, file_data) user_data from user_table; expects you to return a number and you are returning a BLOB.
Were you getting 'ORA-00932: inconsistent datatypes: expected BLOB got NUMBER'?
See the DECODE function in the SQL doc
http://docs.oracle.com/cd/B28359_01/server.111/b28286/functions042.htm
Maybe you are looking for
-
I am thinking about getting an LCD TV with a DVI input for use with my iMac G5 17" 2.0. Is it a bad idea to get one over a 24inchs ? or does it not matter if I get a 32" or 40 even? If so why?
-
Custom fields not displayed inside 'Add. fields' tab of KS01/KS02 tcodes
Hi Experts, I have created a new sub screen 0999 inside program SAPLXKM1 . This subscreen is being called from PBO of screen 0399 / 3399 of SAPLKMA1. During cost center creation (KS01) , one new tab 'Add. fields ' has been added but 0999 screen field
-
Can't I change the directory structure?
Hello Everybody, So far everything is working when use the default directory structure,i.e. mydomain/applications/myWebApp/WEB-INF/classes/some package structure. But we have application with lot of html files which call
-
My iPod touch won't turn on and I don't know what to do?
My iPod touch was running slow so I decided to shut it down completely and then restart it, but now it won't turn on again. The apple will appear like its starting up but then it just goes black again in a continuous cycle. I've tried plugging it in
-
Lync 2013 mobile sign in error
I try sign in to Lync in my Windows Phone, and get error - Check my password. My password correct. For diagnose I enable "Failed Request Tracing Rules" on IIS on Lync 2013 Server and view only one warning from DirectoryListingModule - HttpStatus 403