Decode function and dates
I have the following query:
select of_coy,of_div,
max(DECODE(of_takeon_date, 'MON', 1,0)) JAN,
max(DECODE(of_takeon_date, 'MON', 1,0)) FEB,
max(DECODE(of_takeon_date, 'MON', 1,0)) MAR,
max(DECODE(of_takeon_date, 'MON', 1,0)) APR,
max(DECODE(of_takeon_date, 'MON', 1,0)) MAY,
max(DECODE(of_takeon_date, 'MON', 1,0)) JUN,
max(DECODE(of_takeon_date, 'MON', 1,0)) JUL,
max(DECODE(of_takeon_date, 'MON', 1,0)) AUG,
max(DECODE(of_takeon_date, 'MON', 1,0)) SEP,
max(DECODE(of_takeon_date, 'MON', 1,0)) OCT,
max(DECODE(of_takeon_date, 'MON', 1,0)) NOV,
max(DECODE(of_takeon_date, 'MON', 1,0)) DEC
from mac.oprfile
where of_takeon_date > to_date('01-01-2010','DD-MM-YYYY')
GROUP BY of_coy,of_div
order by 1;
The output displayed is not what i want as it displays just zeros, what about the counts for the months of JAN,FEB,MAR
"OF_COY" "OF_DIV" "JAN" "FEB" "MAR" "APR" "MAY" "JUN" "JUL" "AUG" "SEP" "OCT" "NOV" "DEC"
01 01 0 0 0 0 0 0 0 0 0 0 0 0
01 02 0 0 0 0 0 0 0 0 0 0 0 0
01 03 0 0 0 0 0 0 0 0 0 0 0 0
01 04 0 0 0 0 0 0 0 0 0 0 0 0
01 07 0 0 0 0 0 0 0 0 0 0 0 0
01 08 0 0 0 0 0 0 0 0 0 0 0 0
01 09 0 0 0 0 0 0 0 0 0 0 0 0
01 12 0 0 0 0 0 0 0 0 0 0 0 0
01 22 0 0 0 0 0 0 0 0 0 0 0 0
02 01 0 0 0 0 0 0 0 0 0 0 0 0
04 01 0 0 0 0 0 0 0 0 0 0 0 0
please assist in fixing the sql query
Hi,
Use the following query for taking the sum based on the month.
select of_coy,of_div,
sum(max(DECODE(of_takeon_date, 'MON', 1,0))) JAN,
sum(max(DECODE(of_takeon_date, 'MON', 1,0))) FEB,
sum(max(DECODE(of_takeon_date, 'MON', 1,0))) MAR,
sum(max(DECODE(of_takeon_date, 'MON', 1,0))) APR,
sum(max(DECODE(of_takeon_date, 'MON', 1,0))) MAY,
sum(max(DECODE(of_takeon_date, 'MON', 1,0))) JUN,
sum(max(DECODE(of_takeon_date, 'MON', 1,0))) JUL,
sum(max(DECODE(of_takeon_date, 'MON', 1,0))) AUG,
sum(max(DECODE(of_takeon_date, 'MON', 1,0))) SEP,
sum(max(DECODE(of_takeon_date, 'MON', 1,0))) OCT,
sum(max(DECODE(of_takeon_date, 'MON', 1,0))) NOV,
sum(max(DECODE(of_takeon_date, 'MON', 1,0))) DEC
from mac.oprfile
where of_takeon_date > to_date('01-01-2010','DD-MM-YYYY')
GROUP BY of_coy,of_div
order by 1;
ex :- select first_name,department_id,
sum(decode(to_char(HIRE_DATE,'MON'),'JAN',1,0)) "JAN",
sum(decode(to_char(HIRE_DATE,'MON'),'FEB',1,0)) "FEB",
sum(decode(to_char(HIRE_DATE,'MON'),'MAR',1,0)) "MAR",
sum(decode(to_char(HIRE_DATE,'MON'),'APR',1,0)) "APR",
sum(decode(to_char(HIRE_DATE,'MON'),'MAY',1,0)) "MAY",
sum(decode(to_char(HIRE_DATE,'MON'),'JUN',1,0)) "JUN",
sum(decode(to_char(HIRE_DATE,'MON'),'JUL',1,0)) "JUL",
sum(decode(to_char(HIRE_DATE,'MON'),'AUG',1,0)) "AUG"
from emp
GROUP BY first_name,department_id
ORDER BY 1;
Regards,
NTR
Similar Messages
-
Hi:
Can some explain what the functional and data-source differences are between W_GL_BALANCE_F and W_GL_OTHER_F? Both seem to group by GROUP_ACCOUNT_NUM.
Thanks.That is not possible; all transaction in GL Other will end up in GL Balance.
The two tables are essentially having the same data but at different grain. Two main differences:
- GL Other have individual journal transactions; GL Balance have them summarized to the account level.
- GL Other is truly additive since its just individual journal transactions. i.e. you can just sum() any number of transactions and wont double count a trx; GL Balance is a monthly snapshot table. i.e. it provides account balance for all accounts for every month end, so you can never add two snapshots. -
How to invoke functions and data type( ex. sflight structure ) that is in t
Hi,experts,
I create a funcion(zz_test) that return sflight table type data. I need to invoke the function in the Webdynpro for java application.
I think I would import the funtion to local.
But I don't know how to import the function and the data type using SAP NetWeaver Developer Studio?
But I don't know how to invoke functions and data type( ex. sflight structure ) that is in the R/3 in the WDJ?
Do you give me some hints?
Thanks a lot!
Best regards,
taoHi Wang Tao,
For achieving this you need to user Adaptive RFC models.
This link explains you on the same :
http://help.sap.com/saphelp_nw70/helpdata/EN/6a/11f1f29526944e8580c5e59333d96d/frameset.htm
Thanks
Namrata -
I'm very much new to APEX and I've been looking into a performance issue our external APEX app is having, so if someone has any advice I would be very grateful.
I've narrowed the issue down to one page which uses a report region. This report runs an unrestricted select from a database view, the view is coded to use the v () function to get session values from items in the page at runtime to retrieve the relevant records. This should take sub second to retrieve the records and does so when we run the sql outside of apex when not using the v() function. running in APEX it is taking over 10 seconds to execute, it seems that this is purely related to using v() to retrieve from and to date values from items in the page and using these as range values. If I take the range restriction out of the view and add it to the select in the source of the page it is less than a second to execute.
Is this a know bug, has anyone come across this before?
this is using version 2.02 I believe.Hi,
as Lev has already pointed out by referencing the forum thread, rewrite your view to wrap the V calls with a "scalar subquery". eg:
WHERE WAREHOUSE_ID = (SELECT V('P5_WAREHOUSE_ID') FROM DUAL)For an explanation see http://inside-apex.blogspot.com/2006/11/caution-when-using-plsql-functions-in.html and also check out http://inside-apex.blogspot.com/2006/12/drop-in-replacement-for-v-and-nv.html
Patrick
My APEX Blog: http://inside-apex.blogspot.com
The ApexLib Framework: http://apexlib.sourceforge.net
The APEX Builder Plugin: http://sourceforge.net/projects/apexplugin/ -
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 -- -
Decode Function I asked this in the wrong section so I hope Im right now!
select
a11.SEQ_MEMB_ID,
a11.Auth_Number,
a11.Admit_Primary_Date,
a11.Reviewer,
Decode (a11.Reviewer,
CLC, '2',
HBR, '3',
RAB, '4')
a11.admit_primary_date
from windsoradm.auth_master a11;
I am trying to get if the Reviewer is CLC then they are code 2 HBR Code 3 etc and it does not work. I take out the decode function and the query works. I am getting ORA-00923 FROM KEYWORD NOT FOUND WHERE EXPECTED.Hi,
Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved.
Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
Simplify the problem as much as possible. Remove all tables and columns that play no role in this problem.
Always say which version of Oracle you're using.
This is the right forum for this question. Mark your question in the other forum {message:id=10266930} as "Answered", so people won't waste their time.
925518 wrote:
select
a11.SEQ_MEMB_ID,
a11.Auth_Number,
a11.Admit_Primary_Date,
a11.Reviewer,
Decode (a11.Reviewer,
CLC, '2',
HBR, '3',
RAB, '4')
a11.admit_primary_date
from windsoradm.auth_master a11;
I am trying to get if the Reviewer is CLC then they are code 2 HBR Code 3 etc and it does not work. I take out the decode function and the query works. I am getting ORA-00923 FROM KEYWORD NOT FOUND WHERE EXPECTED.That's the correct DECODE syntax, where CLC, HBR and RAB are columns, and you want to return a string (not a number) such as '2'.
If 'CLC', 'HBR' and 'RAB' are literal values, then enclose them in single-quotes. If you want to return a number, don't put it in quotes. (Anyhting inside single-quotes is a string literal.)
Perhaps you meant something like:
, DECODE ( a11.Reviewer
, 'CLC' , 1
, 'HBR' , 2
, 'RAB' , 3
) AS reviewer_codeThere's an error right after the DECODE. You can't use a11.admit_primary_date as a column alias. (This is probably what's causing the ORA-00923 error.) Either a11_admit_primary_date (with an underscore instead of a dot) or admit_primary_date would be okay. If a11.admit_priomary_date is the next column in the SELECT clause, put a comma befor it.
You need a FROM clause. -
Need help with DECODE function
Hello,
I am trying to use default within the decode function and every time I get a missing expression. I have searched everywhere and cant figure out what I'm doing wrong. Thanks
select decode (request_id,0,'No files found', DEFAULT)Hi,
Welcome to the forum!
When you use a default value, the last argument to DECODE is the actual value you want as a default.
For example:
SELECT ename
, deptno
, DECODE ( deptno
, 30 , 'Sales'
, 'All others' -- Default value
) AS dname
FROM scott.emp
ORDER BY ename
;Output:
ENAME DEPTNO DNAME
ADAMS 20 All others
ALLEN 30 Sales
BLAKE 30 Sales
CLARK 10 All others
FORD 20 All others
JAMES 30 Sales
JONES 20 All others
KING 10 All others
MARTIN 30 Sales
MILLER 10 All others
SCOTT 20 All others
SMITH 20 All others
TURNER 30 Sales
WARD 30 Sales
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
If you can show the problem using commonly available tables (such as those in the scott schema) then you don't need to post any sample data; just the results and the explanation.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ {message:id=9360002} -
DECODE function to validate date value and sort the records
Hi Friends,
I am looking for some query which can give me the required output,
I need to do this using SQL query only and I have tried using the MIN() and MAX() functions it was working fine with limited data, now after inserting the last record(in the below table) which has date for start_range and end_range in(mm/dd/yyyy hh24:mi:ss) format.
Because the data type is VARCHAR2 if I am using the MIN() function it is sorting as a string value, hence the min date is incorrect. I tried using validating the value to date or non date and tried to using MIN() and MAX() functions using the DECODE function, I am getting this error "ORA-01840: input value not long enough for date format".
select table_name,
DECODE(substr(START_RANGE,3,1)||substr(START_RANGE,6,1)||substr(START_RANGE,11,1)||substr(START_RANGE,14,1)||substr(START_RANGE,17,1),'// ::',
to_char(min(to_date(start_range,'mm/dd/yyyy hh24:mi:ss')),'MM/DD/YYYY HH24:MI:SS'),min(start_range)) MIN_RUNS_START_RANGE,
DECODE(substr(END_RANGE,3,1)||substr(A.END_RANGE,6,1)||substr(END_RANGE,11,1)||substr(END_RANGE,14,1)||substr(END_RANGE,17,1),'// ::',
to_char(max(to_date(END_RANGE,'mm/dd/yyyy hh24:mi:ss')),'MM/DD/YYYY HH24:MI:SS'),max(END_RANGE)) MAX_RUNS_END_RANGE
from MY_TABLE
GROUP BY table_name,
(substr(START_RANGE,3,1)||substr(START_RANGE,6,1)||substr(START_RANGE,11,1)||substr(START_RANGE,14,1)||substr(START_RANGE,17,1)),
(substr(END_RANGE,3,1)||substr(END_RANGE,6,1)||substr(END_RANGE,11,1)||substr(END_RANGE,14,1)||substr(END_RANGE,17,1))
Can sombody please advise what is the best way I can query this data with the required output.
The following are the source table and records and the out put records using the sql query.
MY_TABLE
TABLE_NAME(VARCHAR2),START_RANGE(VARCHAR2),END_RANGE(VARCHAR2)
TABLE1,1000,10000
TABLE2,ABCD,EEEE
TABLE3,01/12/2010 00:00:00,12/31/2010 23:59:59
TABLE1,10001,20000
TABLE2,EEEF,GGGG
TABLE3,01/01/2011 00:00:00,01/31/2011 23:59:59
OUTPUT :
TABLE_NAME,MIN(START_RANGE),MAX(END_RANGE)
TABLE1,1000,20000
TABLE2,ABCD,GGGG
TABLE3,01/12/2010 00:00:00,01/31/2011 23:59:59
Thanks
Kalycsi also think this is a very bad table design ...
but if you are not able to change it, you could split the select (date and non-date data) and combine the result with UNION like this:
with t as
SELECT 'TABLE1' table_name,'1000' start_range,'10000' end_range FROM dual UNION
SELECT 'TABLE2','ABCD','EEEE' FROM dual UNION
SELECT 'TABLE3','01/12/2010 00:00:00','12/31/2010 23:59:59' FROM dual UNION
SELECT 'TABLE1','10001','20000' FROM dual UNION
SELECT 'TABLE2','EEEF','GGGG' FROM dual UNION
SELECT 'TABLE3','01/01/2011 00:00:00','01/31/2011 23:59:59' FROM dual
SELECT table_name,
TO_CHAR(MIN(TO_DATE(start_range, 'MM/DD/YYYY HH24:MI:SS')), 'MM/DD/YYYY HH24:MI:SS'),
TO_CHAR(MAX(TO_DATE(end_range, 'MM/DD/YYYY HH24:MI:SS')), 'MM/DD/YYYY HH24:MI:SS')
FROM t
WHERE start_range LIKE '%/%/%:%:%'
GROUP BY table_name
UNION
SELECT table_name,
MIN(start_range),
MAX(end_range)
FROM t
WHERE start_range NOT LIKE '%/%/%:%:%'
GROUP BY
table_name;
TABLE_ MIN_VALUE MAX_VALUE
TABLE1 1000 20000
TABLE2 ABCD GGGG
TABLE3 01/12/2010 00:00:00 01/31/2011 23:59:59 -
SQL*Loader and DECODE function
Hi All,
I am loading data from data files into oracle tables and while loading the data using SQL*Loader, the following requirement needs to be fulfilled.
1) If OQPR < 300, RB = $ 0-299, SC = "SC1"
2) If 300 < OQPR < 1200, RB = $ 300-1199, SC = "SC2"
3) If 1200 < OQPR < 3000, RB = $ 1200-2999, SC = "SC3"
4) If OQPR > 3000 USD, RB = > $3000, SC = "SC4"
Here OPQR is a field in the data file.
Can anyone suggest how do we handle this using DECODE function? Triggers and PL/SQL functions are not to be used.
TIA.
Regards,
Ravi.The following expression gives you different values for your different intervals and boundaries :
SIGN(:OQPR - 300) + SIGN(:OQPR - 1200) + SIGN(:OQPR - 3000) -
Case statement and Decode function both are not working in Select cursor.
I have tried both the Case statement and Decode function in Select cursor, but both the things are not working. On the other hand both the things work in just select statement.
See the first column in select (PAR_FLAG), I need to have this evaluated along with other fields. Can you please suggest some thing to make this work. And also I would like to
know the reason why decode is not working, I heard some where Case statement do not work with 8i.
Author : Amit Juneja
Date : 06/20/2011
Description:
Updates the Diamond MEMBER_MASTER table with the values from
INC.MEM_NJ_HN_MEMBER_XREF table.
declare
rec_cnt number(12) := 0;
commit_cnt number(4) := 0;
cursor select_cur is
Select DECODE(1,
(Select 1
from hsd_prov_contract R
where R.seq_prov_id = PM.seq_prov_id
and R.line_of_business = H.line_of_business
and R.PCP_FLAG = 'Y'
and R.participation_flag = 'P'
and SYSDATE between R.EFFECTIVE_DATE AND
NVL(R.TERM_DATE,
TO_DATE('31-DEC-9999', 'DD-MON-YYYY'))),
'Y',
'N') PAR_FLAG,
H.SEQ_ELIG_HIST,
H.SEQ_MEMB_ID,
H.SEQ_SUBS_ID,
H.SUBSCRIBER_ID,
H.PERSON_NUMBER,
H.EFFECTIVE_DATE,
H.TERM_DATE,
H.TERM_REASON,
H.RELATIONSHIP_CODE,
H.SEQ_GROUP_ID,
H.PLAN_CODE,
H.LINE_OF_BUSINESS,
H.RIDER_CODE_1,
H.RIDER_CODE_2,
H.RIDER_CODE_3,
H.RIDER_CODE_4,
H.RIDER_CODE_5,
H.RIDER_CODE_6,
H.RIDER_CODE_7,
H.RIDER_CODE_8,
H.MEDICARE_STATUS_FLG,
H.OTHER_STATUS_FLAG,
H.HIRE_DATE,
H.ELIG_STATUS,
H.PREM_OVERRIDE_STEP,
H.PREM_OVERRIDE_AMT,
H.PREM_OVERRIDE_CODE,
H.SEQ_PROV_ID,
H.IPA_ID,
H.PANEL_ID,
H.SEQ_PROV_2_ID,
H.SECURITY_CODE,
H.INSERT_DATETIME,
H.INSERT_USER,
H.INSERT_PROCESS,
H.UPDATE_DATETIME,
H.UPDATE_USER,
H.UPDATE_PROCESS,
H.USER_DEFINED_1,
H.SALARY,
H.PEC_END_DATE,
H.REASON_CODE,
H.PEC_WAIVED,
H.BILL_EFFECTIVE_FROM_DATE,
H.BILLED_THRU_DATE,
H.PAID_THRU_DATE,
H.SUBSC_DEPT,
H.SUBSC_LOCATION,
H.USE_EFT_FLG,
H.BENEFIT_START_DATE,
H.SEQ_ENROLLMENT_RULE,
H.MCARE_RISK_ACCRETION_DATE,
H.MCARE_RISK_DELETION_DATE,
H.MCARE_RISK_REFUSED_DATE,
H.COMMENTS,
H.USER_DEFINED_2,
H.USER_DEFINED_3,
H.RATE_TYPE,
H.PCPAA_OCCURRED,
H.PRIVACY_ON,
H.PCP_CHANGE_REASON,
H.SITE_CODE,
H.SEQ_SITE_ADDRESS_ID,
PM.seq_prov_id rendered_prov
from hsd_member_elig_history H,
INC.PCP_REASSIGN_RPRT_DATA P,
hsd_prov_master PM
where P.subscriber_id = H.subscriber_id
and P.rendered_pcp = PM.provider_ID
and H.elig_status = 'Y'
and (H.term_date is NULL or H.term_date >= last_day(sysdate))
order by H.Seq_memb_id;
begin
for C in select_cur loop
rec_cnt := rec_cnt + 1;
update hsd_member_elig_history
set term_date = TRUNC(SYSDATE - 1),
term_reason = 'PCPTR',
update_datetime = SYSDATE,
update_user = USER,
update_process = 'TD33615'
where seq_elig_hist = C.seq_elig_hist
and seq_memb_id = C.seq_memb_id;
INSERT INTO HSD_MEMBER_ELIG_HISTORY
(SEQ_ELIG_HIST,
SEQ_MEMB_ID,
SEQ_SUBS_ID,
SUBSCRIBER_ID,
PERSON_NUMBER,
EFFECTIVE_DATE,
TERM_DATE,
TERM_REASON,
RELATIONSHIP_CODE,
SEQ_GROUP_ID,
PLAN_CODE,
LINE_OF_BUSINESS,
RIDER_CODE_1,
RIDER_CODE_2,
RIDER_CODE_3,
RIDER_CODE_4,
RIDER_CODE_5,
RIDER_CODE_6,
RIDER_CODE_7,
RIDER_CODE_8,
MEDICARE_STATUS_FLG,
OTHER_STATUS_FLAG,
HIRE_DATE,
ELIG_STATUS,
PREM_OVERRIDE_STEP,
PREM_OVERRIDE_AMT,
PREM_OVERRIDE_CODE,
SEQ_PROV_ID,
IPA_ID,
PANEL_ID,
SEQ_PROV_2_ID,
SECURITY_CODE,
INSERT_DATETIME,
INSERT_USER,
INSERT_PROCESS,
UPDATE_DATETIME,
UPDATE_USER,
UPDATE_PROCESS,
USER_DEFINED_1,
SALARY,
PEC_END_DATE,
REASON_CODE,
PEC_WAIVED,
BILL_EFFECTIVE_FROM_DATE,
BILLED_THRU_DATE,
PAID_THRU_DATE,
SUBSC_DEPT,
SUBSC_LOCATION,
USE_EFT_FLG,
BENEFIT_START_DATE,
SEQ_ENROLLMENT_RULE,
MCARE_RISK_ACCRETION_DATE,
MCARE_RISK_DELETION_DATE,
MCARE_RISK_REFUSED_DATE,
COMMENTS,
USER_DEFINED_2,
USER_DEFINED_3,
RATE_TYPE,
PCPAA_OCCURRED,
PRIVACY_ON,
PCP_CHANGE_REASON,
SITE_CODE,
SEQ_SITE_ADDRESS_ID)
values
(hsd_seq_elig_hist.nextval,
C.SEQ_MEMB_ID,
C.SEQ_SUBS_ID,
C.SUBSCRIBER_ID,
C.PERSON_NUMBER,
trunc(SYSDATE),
C.TERM_DATE,
C.TERM_REASON,
C.RELATIONSHIP_CODE,
C.SEQ_GROUP_ID,
C.PLAN_CODE,
C.LINE_OF_BUSINESS,
C.RIDER_CODE_1,
C.RIDER_CODE_2,
C.RIDER_CODE_3,
C.RIDER_CODE_4,
C.RIDER_CODE_5,
C.RIDER_CODE_6,
C.RIDER_CODE_7,
C.RIDER_CODE_8,
C.MEDICARE_STATUS_FLG,
C.OTHER_STATUS_FLAG,
C.HIRE_DATE,
C.ELIG_STATUS,
C.PREM_OVERRIDE_STEP,
C.PREM_OVERRIDE_AMT,
C.PREM_OVERRIDE_CODE,
C.SEQ_PROV_ID,
C.IPA_ID,
C.PANEL_ID,
C.SEQ_PROV_2_ID,
C.SECURITY_CODE,
SYSDATE,
USER,
'TD33615',
SYSDATE,
USER,
'TD33615',
C.USER_DEFINED_1,
C.SALARY,
C.PEC_END_DATE,
C.REASON_CODE,
C.PEC_WAIVED,
C.BILL_EFFECTIVE_FROM_DATE,
C.BILLED_THRU_DATE,
C.PAID_THRU_DATE,
C.SUBSC_DEPT,
C.SUBSC_LOCATION,
C.USE_EFT_FLG,
C.BENEFIT_START_DATE,
C.SEQ_ENROLLMENT_RULE,
C.MCARE_RISK_ACCRETION_DATE,
C.MCARE_RISK_DELETION_DATE,
C.MCARE_RISK_REFUSED_DATE,
C.COMMENTS,
C.USER_DEFINED_2,
C.USER_DEFINED_3,
C.RATE_TYPE,
C.PCPAA_OCCURRED,
C.PRIVACY_ON,
C.PCP_CHANGE_REASON,
C.SITE_CODE,
C.SEQ_SITE_ADDRESS_ID);
commit_cnt := commit_cnt + 1;
if (commit_cnt = 1000) then
dbms_output.put_line('Committed updates for 1000 records.');
commit;
commit_cnt := 0;
end if;
end loop;
commit;
dbms_output.put_line('Total number of MEMBER_ELIG_HISTROY records inserted : ' ||
rec_cnt);
exception
when others then
raise_application_error(-20001,
'An error was encountered - ' || sqlcode ||
' -error- ' || sqlerrm);
end;user10305724 wrote:
I have tried both the Case statement and Decode function in Select cursor, but both the things are not working. Please define what you mean by not working even if your computer screen is near the internet we can't see it.
You should also look at the FAQ about how to ask a question
SQL and PL/SQL FAQ
Particularly *9) Formatting with {noformat}{noformat} Tags* and posting your version.
know the reason why decode is not working, I heard some where Case statement do not work with 8i.
Does this mean you are using 8i? Then scalar sub queries - selects within the select list, are not supported, along with CASE in PL/SQL.
Select DECODE(1,
* (Select 1
from hsd_prov_contract R
where R.seq_prov_id = PM.seq_prov_id
and R.line_of_business = H.line_of_business
and R.PCP_FLAG = 'Y'
and R.participation_flag = 'P'
and SYSDATE between R.EFFECTIVE_DATE AND
NVL(R.TERM_DATE,
TO_DATE('31-DEC-9999', 'DD-MON-YYYY')))*,
'Y',
'N') PAR_FLAG,
>
exception
when others then
raise_application_error(-20001,
'An error was encountered - ' || sqlcode ||
' -error- ' || sqlerrm);
http://tkyte.blogspot.com/2008/01/why-do-people-do-this.html -
SQL Loader : Trim and Decode functions help please
Hi,
I have to load data from a flat file, for some columns i need to use TRIM and DECODE functions.It is a pipe delimited file.
I get syntax errors (one is below) same error listed for TRIM.
SQL*Loader-350: Syntax error at line xx.
Expecting "," or ")", found "DECODE".
===========
,FINAL_BILL_DATE CHAR(30) "TRIM(:FINAL_BILL_DATE)"
,BUSINESS_ID "DECODE(:BUSINESS_ID,'B',1,'C',2,'E',3,'G',4,'O',5,'R',6,'T',7,'U',8,'H',9,-1)"
Can anyone please help.
Thanks
CherrishHello Cherrish.
The error you are receiving leads me to believe that at some point prior to the DECODE on the line for BUSINESS_ID, probably some line even before the FINAL_BILL_DATE line, there a syntactical error causing the quotes before the DECODE to actually terminate some other syntax. Without all of the lines that could actually contribute to this, including the header details, this is the best I can advise.
Hope this helps,
Luke
Please mark the answer as helpful or answered if it is so. If not, provide additional details.
Always try to provide create table and insert table statements to help the forum members help you better. -
Using DECODE Function to change data
I am trying to use the Decode function in a SQL statement to find a field that has a specific type, and when it finds that type, I want to blank out the results in a different field.
For example:
DECODE(ADDR_TYPE,'HOME',PHONE='') HOME_PHONEsomething like:
SQL> with t as
2 (select 219 id,
3 'BUS' addr_type,
4 '505-555-5555' phone
5 from dual
6 union
7 select 219 id,
8 'HOME' addr_type,
9 null phone
10 from dual
11 union
12 select 220 id,
13 'BUS' addr_type,
14 '101-111-1111' phone
15 from dual
16 union
17 select 220 id,
18 'HOME' addr_type,
19 null phone
20 from dual
21 union
22 select 223 id,
23 'BUS' addr_type,
24 '202-222-2222' phone
25 from dual
26 union
27 select 224 id,
28 'HOME' addr_type,
29 '303-333-3333' phone
30 from dual
31 union
32 select 225 id,
33 'BUS' addr_type,
34 null phone
35 from dual
36 union
37 select 226 id,
38 'HOME' addr_type,
39 null phone
40 from dual)
41 select a.id,
42 a.addr_type,
43 decode(a.addr_type,'BUS',phone,null) phone
44 from (select id, addr_type, phone,
45 row_number() over (partition by id order by id, decode(addr_type,'BUS',1,2)) rn
46 from t) a
47 where a.rn = 1;
ID ADDR PHONE
219 BUS 505-555-5555
220 BUS 101-111-1111
223 BUS 202-222-2222
224 HOME
225 BUS
226 HOME
6 rows selected.
SQL> -
The find function doesn't expanding the xml nodes to search. If the xml is expanded , then find function highlights both matching tag and data. how to fix this.
== This happened ==
Every time Firefox opened<xsl:value-of select="x"/> produces a string that consists of all text nodes in x.
<xsl:copy-of select="x"/> produces an exact copy of x.
Go to http://www.zvon.org/ for more information like this. -
Dear All,
Does decode check the date in the table and returns some value from the same table? For example;
Select decode(original_date,1, (select new_date from ABC_Calendar) from ORG_Calendar;It should be like above.
ThanksHi Nicolus,
Here is the code with decode which I tested which failed. Now There is code and there should be help as there is problem. I would appreciate your help to resolve this issue.
SELECT ROWNUM,batchid,statusdate,decode(statusdate,statusdate, (select GREG from HIJ_CAL),(select GREG from HIJ_CAL)),nrofships,CITYNAME,delay_days,NULL Courier_Delivery_Time
FROM
SELECT batch,a.statusdate,(TRUNC(SYSDATE)-TRUNC(a.statusdate)) delay_days,(c.CITYNAME) CITYNNAME
FROM batch a , cityname c
WHERE TRUNC(a.statusdate) <=TRUNC(SYSDATE-3)
AND a.status=38 -
Function module to display the time and date in the report-sy-udate And s
Hi.
wish to have a function module which can display the system time and date through function module.
the format that this function module should display should be like this:
if its today-date and time then:
05-Jan-08 01.25.57 PM
please note that i want them to be in one single row in the top-of page
kinldy help on this.
thanks!hi,
check this.
https://forums.sdn.sap.com/click.jspa?searchID=19175181&messageID=4628668
Thanks
Maybe you are looking for
-
Help me, when trying to connect to iTunes or the iTunes Store I receive the following message. "iTunes could not connect to the iTunes Store." An unknown error occurred (-3212).
-
Using an external hard drive?help
my hard drive on my laptop is full so i purchased a 30gb external hard drive to serve the purpose of containg all my itunes library.i have dragged my entire library over to the external drive and has successfully duplicated in the external drive.my m
-
HT3204 my itunes cannot connect to the internet
my itunes cannot connect to the internet
-
I have a packing list that I'm trying to convert to excel. When I convert only the top portion, which is the address will convert or the items will be weird letters and symbols. How can I convert so that I can work with the data?
-
Using DBMS_XMLPROCESSOR.
I am trying to use the DBMS_XSLPROCESSOR package to format an XML.This is my first attempt. The XML below is in a file. <?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="SDI8I.xsl"?> <SDIEXTRACT> <SDI num="1"> <