Performace : SQL with CASE
Hi,
Why execution plan for SQL1 & SQL2 are same?
Is there any performace impact(as compare to normal select) if we put CASE statement in SQL?
SQL1
SELECT
CASE WHEN PCS_SKEY < 1 then NULL ELSE PCS_SKEY END PCS_SKEY,
CASE WHEN MDT_SKEY < 1 then NULL ELSE MDT_SKEY END MDT_SKEY,
CASE WHEN DLS_SKEY < 1 then NULL ELSE DLS_SKEY END DLS_SKEY,
CASE WHEN MVI_SKEY < 1 then NULL ELSE MVI_SKEY END MVI_SKEY
FROM F_REG
SQL2
SELECT
PCS_SKEY,
MDT_SKEY,
DLS_SKEY,
MVI_SKEY
FROM F_REG
Explain Plan
SQL1:
Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
SELECT STATEMENT Optimizer Mode=ALL_ROWS 4 M 38755
TABLE ACCESS FULL SMMTDW.F_REG 4 M 64 M 38755
SQL2:
Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
SELECT STATEMENT Optimizer Mode=ALL_ROWS 4 M 38755
TABLE ACCESS FULL SMMTDW.F_REG 4 M 64 M 38755
Similar Messages
-
Is there any way to simplyfy this sql using case when or any other condition
Hi,
Please ca you advise me to simplyfy the given sql
SELECT
CASE
WHEN AxleNo=1 and AxleType = 'OFFSIDE OUTER'
THEN SIZE
END AS off_1st_size_txt_out,
CASE
WHEN AxleNo=1 and AxleType = 'OFFSIDE OUTER'
THEN make
END AS off_1st_make_txt_out,
CASE
WHEN AxleNo=1 and AxleType = 'OFFSIDE OUTER'
THEN pattern
END AS off_1st_pat_txt_out,
CASE
WHEN AxleNo=1 and AxleType = 'OFFSIDE OUTER'
THEN TreadDepth1
END AS off_1st_size_out,
CASE
WHEN AxleNo=1 and AxleType = 'OFFSIDE OUTER'
THEN TreadDepth2
END AS off_1st_make_out,
CASE
WHEN AxleNo=1 and AxleType = 'OFFSIDE OUTER'
THEN TreadDepth3
END AS off_1st_pat_out,
--1st near side outer
CASE
WHEN AxleNo=1 and AxleType = 'NEARSIDE OUTER'
THEN SIZE
END AS near_1st_size_txt_out,
CASE
WHEN AxleNo=1 and AxleType = 'NEARSIDE OUTER'
THEN make
END AS near_1st_make_txt_out,
CASE
WHEN AxleNo=1 and AxleType = 'NEARSIDE OUTER'
THEN pattern
END AS near_1st_pat_txt_out,
CASE
WHEN AxleNo=1 and AxleType = 'NEARSIDE OUTER'
THEN TreadDepth1
END AS near_1st_size_out,
CASE
WHEN AxleNo=1 and AxleType = 'NEARSIDE OUTER'
THEN TreadDepth2
END AS near_1st_make_out,
CASE
WHEN AxleNo=1 and AxleType = 'NEARSIDE OUTER'
THEN TreadDepth3
END AS near_1st_pat_out,
--2nd Offside Outer
CASE
WHEN AxleNo=2 and AxleType = 'OFFSIDE OUTER'
THEN SIZE
END AS off_2nd_size_txt_out,
CASE
WHEN AxleNo=2 and AxleType = 'OFFSIDE OUTER'
THEN make
END AS off_2nd_make_txt_out,
CASE
WHEN AxleNo=2 and AxleType = 'OFFSIDE OUTER'
THEN pattern
END AS off_2nd_pat_txt_out,
CASE
WHEN AxleNo=2 and AxleType = 'OFFSIDE OUTER'
THEN TreadDepth1
END AS off_2nd_size_out,
CASE
WHEN AxleNo=2 and AxleType = 'OFFSIDE OUTER'
THEN TreadDepth2
END AS off_2nd_make_out,
CASE
WHEN AxleNo=1 and AxleType = 'OFFSIDE OUTER'
THEN TreadDepth3
END AS off_2nd_pat_out
from my fleets
With Many Thanks
Pol
polachanHello,
the same result ( maybe with records in slightly different order ), you can obtain using this code snippet.
SELECT SIZE AS off_1st_size_txt_out,
make AS off_1st_make_txt_out,
pattern AS off_1st_pat_txt_out,
TreadDepth1 AS off_1st_size_out,
TreadDepth2 AS off_1st_make_out,
TreadDepth3 AS off_1st_pat_out,
NULL AS near_1st_size_txt_out,
NULL AS near_1st_make_txt_out,
NULL AS near_1st_pat_txt_out,
NULL AS near_1st_size_out,
NULL AS near_1st_make_out,
NULL AS near_1st_pat_out,
NULL AS off_2nd_size_txt_out,
NULL AS off_2nd_make_txt_out,
NULL AS off_2nd_pat_txt_out,
NULL AS off_2nd_size_out,
NULL AS off_2nd_make_out,
NULL AS off_2nd_pat_out
WHERE AxleNo=1 and AxleType = 'OFFSIDE OUTER'
from my fleets
UNION
SELECT NULL AS off_1st_size_txt_out,
NULL AS off_1st_make_txt_out,
NULL AS off_1st_pat_txt_out,
NULL AS off_1st_size_out,
NULL AS off_1st_make_out,
NULL AS off_1st_pat_out,
SIZE AS near_1st_size_txt_out,
make AS near_1st_make_txt_out,
pattern AS near_1st_pat_txt_out,
TreadDepth1 AS near_1st_size_out,
TreadDepth2 AS near_1st_make_out,
TreadDepth3 AS near_1st_pat_out,
NULL AS off_2nd_size_txt_out,
NULL AS off_2nd_make_txt_out,
NULL AS off_2nd_pat_txt_out,
NULL AS off_2nd_size_out,
NULL AS off_2nd_make_out,
NULL AS off_2nd_pat_out
WHERE AxleNo=1 and AxleType = 'NEARSIDE OUTER'
from my fleets
UNION
SELECT NULL AS off_1st_size_txt_out,
NULL AS off_1st_make_txt_out,
NULL AS off_1st_pat_txt_out,
NULL AS off_1st_size_out,
NULL AS off_1st_make_out,
NULL AS off_1st_pat_out,
NULL AS near_1st_size_txt_out,
NULL AS near_1st_make_txt_out,
NULL AS near_1st_pat_txt_out,
NULL AS near_1st_size_out,
NULL AS near_1st_make_out,
NULL AS near_1st_pat_out,
SIZE AS off_2nd_size_txt_out,
make AS off_2nd_make_txt_out,
pattern AS off_2nd_pat_txt_out,
TreadDepth1 AS off_2nd_size_out,
TreadDepth2 AS off_2nd_make_out,
TreadDepth3 AS off_2nd_pat_out
WHERE AxleNo=2 and AxleType = 'OFFSIDE OUTER'
from my fleets
If you find it easier to understand and to maintain. The result is made using "UNION" .
Šimon -
CLOB with case statement not working getting error
Can anyone help on this
I write this sql
select Case when to_clob(PROPERTY) = 'is_intradesk=Y' then 'Internal' end
from JPM_CP;
Where PROPERTY column is clob column and its giving the error "ORA-00932: inconsistent datatypes: expected - got CLOB"
Is it not possible to use clob columns with case or decode !Its working but it does not fulfill my purpose
In you answer it is looking for position right! means, does the column contain the value('Intradesk=Y' ) or not. means
I am looking for exact match with CLOB column values, that is Clob column(PROPERTY) contains the exact value that value which I am comparing with i.e 'Intradesk=Y'
I need this
select * from table where clob_column = 'value' (exact).
Edited by: sajalkdas on Feb 4, 2011 3:28 PM -
11g outer join with case statement - strange results.
Hello All,
I am experiencing a strange issues in 11g while using case statement.
I am not able to reproduce this using sample data. Not sure what is wrong.
I am not narrowing it to say the usage of case statemnt is giving wrong results, but that is my observation when I am doing trail and error testing.
Here are the details.
My Version
SQL> select * from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
CORE 11.2.0.2.0 Production
TNS for Linux: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production
SQL> My Query
SELECT *
FROM (SELECT DISTINCT mf.schedule,
mf.cptcode,
NVL (mf.modifier, '00') modifier2,
CASE
WHEN mf.feetype = 'H'
AND mf.multiplier IS NOT NULL THEN
' 0.00'
WHEN (mf.feetype != 'H'
OR mf.feetype IS NULL)
AND mf.rbrvsvalue IS NOT NULL
AND mf.multiplier IS NOT NULL THEN
LPAD ( TRIM (TO_CHAR ( (mf.rbrvsvalue * mf.multiplier) / 100, 9999999.99)), 10)
ELSE
NULL
END
fee
FROM provider.mpifee mf, mpi_udffee.udffeeactivecptcodes vld
WHERE mf.schedule = 'SAPG1'
AND mf.cptcode = vld.cptcode
AND NVL (mf.modifier, 'NULL') = NVL (vld.modifier, 'NULL')) inline_fee,
(SELECT arc.schedule col1, arc.procedurecode col2, NVL (arc.modifier, '00') AS col3
FROM mpi_udffee.udffeeancfeedata arc
WHERE monthofextract = '201202'
AND arc.schedule = 'SAPG1'
AND TRUNC (SYSDATE - 10) BETWEEN arc.recordeffectivedate AND arc.recordterminationdate) inline_data
WHERE inline_fee.schedule = inline_data.col1(+)
AND inline_fee.cptcode = inline_data.col2(+)
AND inline_fee.modifier2 = inline_data.col3(+);
In the above query the inline view inline_data returns zero rows. but NVL is still getting applied for col3 and I am getting 00 in the results( strange ).
Results:
SCHEDULE CPTCO MODIFIER2 FEE COL1 COL2 COL3
SAPG1 49590 00 667.32 00
SAPG1 49611 00 781.03 00
SAPG1 49905 00 443.79 00
SAPG1 50205 00 883.56 00
SAPG1 50220 00 1315.15 00
SAPG1 50230 00 1638.74 00
SAPG1 50234 00 1666.16 00
SAPG1 50250 00 1566.14 00
SAPG1 50327 00 262.04 00
SAPG1 50541 00 1183.31 00
SAPG1 50620 00 1156.88 00
SAPG1 50650 00 1321.96 00
497 rows selected.
Just the inline view inline_data,
SQL> SELECT arc.schedule col1, arc.procedurecode col2, NVL (arc.modifier, '00') AS col3
2 FROM mpi_udffee.udffeeancfeedata arc
3 WHERE monthofextract = '201202'
4 AND arc.schedule = 'SAPG1'
5 AND TRUNC (SYSDATE - 10) BETWEEN arc.recordeffectivedate AND arc.recordterminationdate;
no rows selectedMuch unusual thing is when I just remove the case statement from the inline view "inline_fee", I am getting right results,
SELECT *
FROM (SELECT DISTINCT mf.schedule,
mf.cptcode,
NVL (mf.modifier, '00') modifier2 <-- Removed Case statement here
FROM provider.mpifee mf, mpi_udffee.udffeeactivecptcodes vld
WHERE mf.schedule = 'SAPG1'
AND mf.cptcode = vld.cptcode
AND NVL (mf.modifier, 'NULL') = NVL (vld.modifier, 'NULL')) inline_fee,
(SELECT arc.schedule col1, arc.procedurecode col2, NVL (arc.modifier, '00') AS col3
FROM mpi_udffee.udffeeancfeedata arc
WHERE monthofextract = '201202'
AND arc.schedule = 'SAPG1'
AND TRUNC (SYSDATE - 10) BETWEEN arc.recordeffectivedate AND arc.recordterminationdate) inline_data
WHERE inline_fee.schedule = inline_data.col1(+)
AND inline_fee.cptcode = inline_data.col2(+)
AND inline_fee.modifier2 = inline_data.col3(+);
SCHEDULE CPTCO MODIFIER2 COL1 COL2 COL3
SAPG1 46730 00
SAPG1 46735 00
SAPG1 46748 00
SAPG1 46760 00
SAPG1 46942 00
SAPG1 46945 00
SAPG1 47015 00
SAPG1 47125 00
SAPG1 47350 00
SAPG1 47505 00
SAPG1 47553 00interestingly explain plan for both the statements are exactly same,
SELECT STATEMENT ALL_ROWSCost: 138 Bytes: 1,078,274 Cardinality: 11,471
9 HASH JOIN RIGHT OUTER Cost: 138 Bytes: 1,078,274 Cardinality: 11,471
2 PARTITION RANGE EMPTY Cost: 2 Bytes: 150 Cardinality: 3
1 TABLE ACCESS FULL TABLE MPI_UDFFEE.UDFFEEANCFEEDATA Cost: 2 Bytes: 150 Cardinality: 3
8 VIEW MPI_UDFFEE. Cost: 135 Bytes: 504,724 Cardinality: 11,471
7 HASH UNIQUE Cost: 135 Bytes: 539,137 Cardinality: 11,471
6 HASH JOIN Cost: 134 Bytes: 539,137 Cardinality: 11,471
3 TABLE ACCESS FULL TABLE MPI_UDFFEE.UDFFEEACTIVECPTCODES Cost: 13 Bytes: 177,345 Cardinality: 25,335
5 PARTITION LIST SINGLE Cost: 120 Bytes: 600,600 Cardinality: 15,015 Partition #: 8
4 INDEX RANGE SCAN INDEX (UNIQUE) REPRICE.PK_MPIFEE Cost: 120 Bytes: 600,600 Cardinality: 15,015 Partition #: 9 Partitions accessed #11Is there anything wrong with the query? If not have anyone come across this issue or posted it as a bug or is there a patch?
Update:
when I set the parameter "_complex_view_merging"=false I am getting the right results even with case statement. But I don want to do some thing unsupported.
Are there any other viable solutions?
I appreciate the help.
Thanks,
G.
Edited by: Ganesh Srivatsav on Apr 10, 2012 12:37 PMHi Tubby,
Right, the query transformation is going wrong. Following is from trace,
SELECT "INLINE_FEE"."SCHEDULE" "SCHEDULE",
"INLINE_FEE"."CPTCODE" "CPTCODE",
"INLINE_FEE"."MODIFIER2" "MODIFIER2",
"INLINE_FEE"."FEE" "FEE",
"ARC"."SCHEDULE" "COL1",
"ARC"."PROCEDURECODE" "COL2",
CASE
WHEN "ARC".ROWID IS NOT NULL THEN NVL ("ARC"."MODIFIER", '00')
ELSE NULL
END
"COL3"
FROM (SELECT DISTINCT "MF"."SCHEDULE" "SCHEDULE",
"MF"."CPTCODE" "CPTCODE",
NVL ("MF"."MODIFIER", :B2) "MODIFIER2",
CASE
WHEN ("MF"."FEETYPE" = :B3
AND "MF"."MULTIPLIER" IS NOT NULL) THEN
:B4
WHEN ( ("MF"."FEETYPE" <> :B5
OR "MF"."FEETYPE" IS NULL)
AND "MF"."RBRVSVALUE" IS NOT NULL
AND "MF"."MULTIPLIER" IS NOT NULL) THEN
LPAD ( TRIM (TO_CHAR ( "MF"."RBRVSVALUE" * "MF"."MULTIPLIER" / :B6, :B7)), :B8)
ELSE
NULL
END
"FEE"
FROM "PROVIDER"."MPIFEE" "MF", "MPI_UDFFEE"."UDFFEEACTIVECPTCODES" "VLD"
WHERE "MF"."SCHEDULE" = 'SAPG1'
AND "MF"."CPTCODE" = "VLD"."CPTCODE"
AND NVL ("MF"."MODIFIER", 'NULL') = NVL ("VLD"."MODIFIER", 'NULL')) "INLINE_FEE",
"MPI_UDFFEE"."UDFFEEANCFEEDATA" "ARC"
WHERE "INLINE_FEE"."SCHEDULE" = "ARC"."SCHEDULE"(+)
AND "INLINE_FEE"."CPTCODE" = "ARC"."PROCEDURECODE"(+)
AND "INLINE_FEE"."MODIFIER2" = CASE
WHEN ("ARC".ROWID(+) IS NOT NULL) THEN NVL ("ARC"."MODIFIER"(+), '00')
ELSE NULL
END
AND "ARC"."MONTHOFEXTRACT"(+) = '201202'
AND "ARC"."SCHEDULE"(+) = 'SAPG1'
AND TRUNC (SYSDATE-10) >= "ARC"."RECORDEFFECTIVEDATE"(+)
AND TRUNC (SYSDATE-10) <= "ARC"."RECORDTERMINATIONDATE"(+)Does this refer to a specific bug?
Thanks,
G. -
Can we use NATIVE PL-SQL with OWB ?
Is there a performance advantage to use it with OWB.
We work with owb9.0.2. We are going to migrate to owb10g soon.You may be able to, however I have never done so. I would expect that you can just call native PL/SQL from something like SQL Plus? In that case you may be able to use it in custom functions...
Jean-Pierre -
Tuning sql with analytic function
Dear friends I've developed one sql :
with REP as
(select /*+ MATERIALIZE */ branch_code,
row_number() over(partition by branch_code, account order by bkg_date desc ) R,
account,
bkg_date,
lcy_closing_bal
from history t
select REP1.branch_code,
REP1.account,
REP1.bkg_date,
REP1.lcy_closing_bal,
NULL AS second,
REP2.bkg_date bkg_date2,
REP2.lcy_closing_bal lcy_closing_bal2,
NULL AS third,
REP3.bkg_date bkg_date3,
REP3.lcy_closing_bal lcy_closing_bal3
from (SELECT * FROM REP WHERE R=1) REP1, (SELECT * FROM REP WHERE R=2) REP2, (SELECT * FROM REP WHERE R=3) REP3
where
(REP1.BRANCH_CODE = REP2.BRANCH_CODE(+) AND REP1.ACCOUNT = REP2.ACCOUNT(+)) AND
(REP1.BRANCH_CODE = REP3.BRANCH_CODE(+) AND REP1.ACCOUNT = REP3.ACCOUNT(+))The point is I want to restrict (tune) REP before it used ,because , as you can see I need maximum three value from REP (where R=1,R=2,R=3) . Which analytic function and with wich options I have to use to receive only 3 values in each branch_code,account groups at the materializing time ?Radrigez wrote:
Dear friends I've developed one sql :
with REP as
from (SELECT * FROM REP WHERE R=1) REP1,
(SELECT * FROM REP WHERE R=2) REP2,
(SELECT * FROM REP WHERE R=3) REP3
where
(REP1.BRANCH_CODE = REP2.BRANCH_CODE(+) AND REP1.ACCOUNT = REP2.ACCOUNT(+)) AND
(REP1.BRANCH_CODE = REP3.BRANCH_CODE(+) AND REP1.ACCOUNT = REP3.ACCOUNT(+))
The first step is to put your subquery (which doesn't need to be materialized) into an inline view and restrict the result set on r in (1,2,3) as suggested by thtsang - you don't need to query the same result set three times.
Then you're looking at a simple pivot operation (assuming the number of rows you want per branch and account is fixed). If you're on 11g search the manuals for PIVOT, on earlier versions you can do this with a decode() or case() operator.
Step 1 (which could go into another factored subquery) would be something like:
select
branch_code, account,
case r = 1 then bkg_date end bkg_date,
case r = 1 then lcy_closing_bal end lcy_closing_bal,
case r = 2 then bkg_date end bkg_date2,
case r = 2 then lcy_closing_bal end lcy_closing_bal2,
case r = 3 then bkg_date end bkg_date3,
case r = 3 then lcy_closing_bal end lcy_closing_bal3
from
repThis gives you the eight necessary columns, but still (up to) three rows per branch/account.
Then you aggregate this (call it rep1) on branch and account.
select
branch_code, account,
max(bkg_date),
max(lcy_closing_bal),
max(bkg_date2),
max(lcy_closing_bal2),
max(bkg_date3),
max(lcy_closing_bal3)
from
rep1
group by
branch_code, account
order by
branch_code, accountRegards
Jonathan Lewis
http://jonathanlewis.wordpress.com
Author: <b><em>Oracle Core</em></b> -
Help with Case Usage or similar
Has anybody tried using similar to below case usage in where clause. Is there any other way i can get this done.
To summarize the query, month starts from 7th of current month to 6th of next month. Query has to dynamically assume that. Please let me know.
Thanks ahead for assistance.
select * from table tc
where tc.column=x and
(case when (to_char(sysdate, 'DD')/7)>=1 THEN
trunc(tc.CREATED_DATE) between to_date('07-'||to_char(sysdate, 'MM-YYYY'), 'DD-MM-YYYY') and
to_date('06-'||to_char(add_months(sysdate, 1), 'MM-YYYY'), 'DD-MM-YYYY')
else
trunc(tc.CREATED_DATE) between to_date('07-'||to_char(add_months(sysdate, -1), 'MM-YYYY'), 'DD-MM-YYYY') and
to_date('06-'||to_char(sysdate, 'MM-YYYY'), 'DD-MM-YYYY')
END)I missed a piece of the calculation. I tried the below query with Aug 6th and 7th. It should work for any day - including SYSDATE;
SQL> with tc as (
select trunc(sysdate -60 + rownum) created_date
from dual
connect by rownum <= 100)
select *
from tc
where created_date between trunc(to_date('06-AUG-07','DD-MON-YY')-6,'MM')+6
and trunc(add_months(to_date('06-AUG-07','DD-MON-YY')-6,1),'MM')+5
CREATED_DATE
07-JUL-07
08-JUL-07
05-AUG-07
06-AUG-07
31 rows selected.
SQL> with tc as (
select trunc(sysdate -60 + rownum) created_date
from dual
connect by rownum <= 100)
select *
from tc
where created_date between trunc(to_date('07-AUG-07','DD-MON-YY')-6,'MM')+6
and trunc(add_months(to_date('07-AUG-07','DD-MON-YY')-6,1),'MM')+5
CREATED_DATE
07-AUG-07
08-AUG-07
05-SEP-07
06-SEP-07
31 rows selected. -
it is possible to write something approaching an if..then..else statement in SQL with 'generalized' conditions in the if statement.
Attached is the query for the payment register, in which I've written a series of decode statements, one for each possible value of the payment code. The query works OK - however, its specific and as the number of paycodes expand (and they do), the report won't pick up the new paycode until the code is changed. More importantly, the report won't be correct until someone 'discovers' that a paycode is missing, which might take months.
If I were writing the equivalent of this series of decode statements in Focus, it would be something like this:
DEFINE.......
PAYMED/D12.2 = IF PAYMENT_CD LE 18
THEN PAYMENT_AMT
ELSE 0 ;
PAYIND/D12.2 = IF PAYMENT_CD GE 19 AND PAYMENT_CD LE 49
THEN PAYMENT_AMT
ELSE 0 ;
PAYEXP/D12.2 = IF PAYMENT_CD GE 70
THEN PAYMENT_AMT
ELSE 0 ;
PAYREC/D12.2 = IF PAYMENT_CD GE 50 AND PAYMENT_CD LE 69
THEN PAYMENT_AMT
ELSE 0;
END
IN SQL/PLUS:
SELECT ACCOUNT_NAME,
LOCATION_1,
CLMNT_LAST_NAME,
CLAIM_NBR,
DATE_OF_INJURY,
DATE_CHECK_REGISTER,
PAYEE_NAME_1,
PAYMENT_CD,
SERV_OFC,
CPO_CHECK_NBR,
PAYMENT_FORM,
DECODE(PAYMENT_CD, 20, PAYMENT_AMT, 21, PAYMENT_AMT,
22, PAYMENT_AMT, 23, PAYMENT_AMT, 25, PAYMENT_AMT,
26, PAYMENT_AMT, 27, PAYMENT_AMT, 28, PAYMENT_AMT,
29, PAYMENT_AMT, 30, PAYMENT_AMT, 31, PAYMENT_AMT,
32, PAYMENT_AMT, 33, PAYMENT_AMT, 34, PAYMENT_AMT,
35, PAYMENT_AMT, 36, PAYMENT_AMT, 37, PAYMENT_AMT,
39, PAYMENT_AMT, 40, PAYMENT_AMT, 41, PAYMENT_AMT,
42, PAYMENT_AMT, 43, PAYMENT_AMT, 44, PAYMENT_AMT,
45, PAYMENT_AMT, 46, PAYMENT_AMT, 47, PAYMENT_AMT,
48, PAYMENT_AMT, 49, PAYMENT_AMT, NULL) INDEMNITY,
DECODE(PAYMENT_CD, 0, PAYMENT_AMT, 1, PAYMENT_AMT,
2, PAYMENT_AMT, 3, PAYMENT_AMT, 4, PAYMENT_AMT,
5, PAYMENT_AMT, 6, PAYMENT_AMT, 7, PAYMENT_AMT,
8, PAYMENT_AMT, 9, PAYMENT_AMT, 10, PAYMENT_AMT,
11, PAYMENT_AMT, 12, PAYMENT_AMT, 13, PAYMENT_AMT,
14, PAYMENT_AMT, 15, PAYMENT_AMT, 18, PAYMENT_AMT,
17, PAYMENT_AMT, NULL) MEDICAL,
DECODE(PAYMENT_CD, 70, PAYMENT_AMT, 71, PAYMENT_AMT,
72, PAYMENT_AMT, 73, PAYMENT_AMT, 74, PAYMENT_AMT,
75, PAYMENT_AMT, 76, PAYMENT_AMT, 77, PAYMENT_AMT,
78, PAYMENT_AMT, 79, PAYMENT_AMT, 80, PAYMENT_AMT,
81, PAYMENT_AMT, 82, PAYMENT_AMT, 83, PAYMENT_AMT,
84, PAYMENT_AMT, 85, PAYMENT_AMT, 86, PAYMENT_AMT,
87, PAYMENT_AMT, 88, PAYMENT_AMT, 89, PAYMENT_AMT,
90, PAYMENT_AMT, NULL) EXPENSES,
DECODE(PAYMENT_CD, 50, PAYMENT_AMT, 51, PAYMENT_AMT,
52, PAYMENT_AMT, 53, PAYMENT_AMT, 54, PAYMENT_AMT,
55, PAYMENT_AMT, 56, PAYMENT_AMT, 57, PAYMENT_AMT,
58, PAYMENT_AMT, NULL) RECOVERIES,
DECODE(PAYMENT_FORM, 'N', PAYMENT_AMT, NULL) NONCASH,
DATE_FROM_SERVICE,
DATE_THRU_SERVICE
FROM &INPUT_TABLES
WHERE &SECURITYCOND
DATE_OF_PAYMENT BETWEEN :START_DATE AND :END_DATE
ORDER BY LOCATION_1, CPO_CHECK_NBR
As you can see, this is both much easier to write and covers the possibility of expansion of paycodes (expansions always fit in these defined ranges).
My question is, then, is it possible to write something like this in SQL and, if so, could you give me some sample code? (I'm one of those people who learn best from looking at the code as opposed to a set of instructions)Here is one way you could do it.
Create a table that has columns like:
Payment_code varchar2(2),
Effective_Date Date,
Payment_type varchar2(20),
Expiration_Date Date)
Payment type for example could be
I- indemnity
M- medical
R- recovery
E- expenses
Let the table name for example be PAYMENT_CODE.
The select query would look like
SELECT ACCOUNT_NAME,
LOCATION_1,
CLMNT_LAST_NAME,
CLAIM_NBR,
DATE_OF_INJURY,
DATE_CHECK_REGISTER,
PAYEE_NAME_1,
PAYMENT_CD,
SERV_OFC,
CPO_CHECK_NBR,
PAYMENT_FORM,
DECODE(p.payment_type,'E',PAYMENT_AMOUNT,0) expenses,
DECODE(p.payment_type,'I',PAYMENT_AMOUNT,0) indemnity,
DECODE(p.payment_type,'M',PAYMENT_AMOUNT,0) Medical,
DECODE(p.payment_type,'R',PAYMENT_AMOUNT,0) recoveries,
DECODE(PAYMENT_FORM, 'N', PAYMENT_AMT, NULL) NONCASH
FROM &INPUT_TABLES,
PAYMENT_CODE P
WHERE P.PAYMENT_CODE = SOMEINPUT_TABLE.PAYMENT_CODE
and other conditions
The idea is to group all the payment codes into a few groups to reduce the clutter. If there is ever a change to the payment code, you could modify the table and it will be reflected in your select query. -
Problem in SQL with CURSOR( ) ,Why the CURSOR did not work?
hi All:
I have a problem in SQL with CURSOR.
The data is as the attachments.
Here is the SQL statement as follow:
SELECT A.WADCTO,A.WADOCO,B.IGCOST,CURSOR (SELECT X.IGLITM
FROM F3102 X
WHERE X.IGDOCO=A.WADOCO
AND X.IGCOST IN ('B1','D1','C3')) AS DETAIL
FROM F4801 A INNER JOIN F3102 B ON A.WADOCO=B.IGDOCO AND A.WADCTO=B.IGDCTO AND B.IGCOST>' '
WHERE A.WADOCO='10004'
The statement above returns records as follow:
WADC WADOCO IGCOST DETAIL
WO 10004 A1 CURSOR STATEMENT : 4
CURSOR STATEMENT : 4
IGLITM
1KV90CPG2
1KV90CPG2
1KV90CPG2
But, after I add one statement in the subquery, there is no record returned from CURSOR.
Here is the SQL statement:
SELECT A.WADCTO,A.WADOCO,B.IGCOST,CURSOR (SELECT X.IGLITM
FROM F3102 X
WHERE X.IGDOCO=A.WADOCO
AND X.IGCOST=B.IGCOST
AND X.IGCOST IN ('B1','D1','C3')) AS DETAIL
FROM F4801 A INNER JOIN F3102 B ON A.WADOCO=B.IGDOCO AND A.WADCTO=B.IGDCTO AND B.IGCOST>' '
WHERE A.WADOCO='10004'
The statement above returns records as follow:
WADC WADOCO IGCOST DETAIL
WO 10004 A1 CURSOR STATEMENT : 4
CURSOR STATEMENT : 4
no rows selected
Why the CURSOR did not work?
The database version is Oracle Database 10g Release 10.2.0.4.0 - 64bit Production.
F3102 DATA:
IGDOCO IGDCTO IGLITM IGCOST
10004 WO 1KV90CPG2 A1
10004 WO 1KV90CPG2 B1
10004 WO 1KV90CPG2 C3
10004 WO 1KV90CPG2 D1
F4801 DATA:
WADCTO WADOCO
WO 10004
Edited by: user2319139 on 2010/3/2 上午 1:17
Edited by: user2319139 on 2010/3/2 上午 1:20Why this structure and not a join?
The cursor() function returns a cursor handle that needs to be processed - in other words, the client needs to fetch data from it. The Oracle® Database SQL Reference+ (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/expressions005.htm#i1035107) describes it as being equivalent to a ref cursor handle.
Thus why are you creating ref cursor handles as a column in a SQL projection - where each row will have a "+nested+" ref cursor handle to process. What problem are you attempting to hack solve this way? -
ColdFusion Builder with case sensitive file system on Mac?
Hi there,
I tried to install CF Builder on my MacBook Pro (Intel), OS-X 10.5.7 with case sensitive file system. Installation went smoothly, but, when I try to launch CF Builder, I get an error saying that the "architecture is not supported". Is it just nor possible to have CF Builder on a case sensitive fs?
Thank you
ChrisI am having the same issue and logged in here to see what the deal is.
After I installed cfbuilder my flex builder crapped out as well.
The cfbuilder logs (which were conveniently scattered throughout my system for no reason) report that I am running:
java.vm.version == 1.5.0_19-137
But if I run "java -version" in terminal I get:
daves-macbook-pro-2:~ Dave$ java -version
java version "1.6.0_13"
Java(TM) SE Runtime Environment (build 1.6.0_13-b03-211)
Java HotSpot(TM) 64-Bit Server VM (build 11.3-b02-83, mixed mode)
"Is JDK 1.5 available in the system"
Definale "available"...
Does it exist? yes
Is it set to default? no -
How to reduce different versions of SQL with bind variables
There is an application, developed on Java.
Application executes SQL following types:
select * from t where id in (:1)
select * from t where id in (:1, :2)
select * from t where id in (:1, :2, :3)
select * from t where id in (:1, :2, :3, :4)
...And as a result very many versions (thousands) of similar SQL.
Do you know a method to reduce number of such SQLs?
I see one method: use one form of SQL with large number of prepared bid variables.
Like as
select * from t where id in (:1, :2, :3, :4, :5, :6, :7, :8, ...);And if query will be executed with one variable, the others will be equal to null.
Is there another method?Cannot you insert those values into a temporary table and work within a subquery against that table ? That will make the code more secure, especially if the number of values is high.
Nicolas. -
Good iphone car mount that works with case?
I need a car mount for my iPhone so that I can use the phone's GPS app. I've looked around and so far I can only find mounts that work for iPhones without any case.
I would rather not have to remove the case everytime I got in my car, so are there any recommended mounts out there that work for phones with cases?
Thanks!Griffin makes an FM/lighter mounted model, which has several bottom mounting brackets, to fit several phone models. I tested it out today, but the ipod buttons on the model don't work correctly, and FM was spotty to awful, as always on these type of setups. It did hold my naked cellphone well, and wish it had worked as advertised - cost about $100 at Best Buy.
Belking has a similar model (about $70 at Best Buy), without the FM transmitter, also on a lighter stalk, which may work, since it grips the top of the phone with a wider clip, made to adapt to case thicknesses, I presume. I have not tried out this model, but may do so, since I have never found a single FM transmitter that works well - too much static, fading in and out, etc.
Is there anyone who can recommend a lighter mounted (on a flexible stalk) charger for the iphone, that has a stalk long enough to accommodate any rental car, I would very much appreciate it. -
Help in to convert sql from CASE to DECODE in 11g
11gr2, Windows.
Can somebody help me out in re-writing below sql from CASE statement to DECODE ?
SELECT INVOICE_ID,sum(TOTAL_EXCL_VAT),LEVEL2 as descr,
sum(case when instr(LEVEL2,'Internet')>0 then SUM_QUANTITY else 0 end) as KB --- >> Here
from rator_cdr.INVOICE_DETAIL_LINE
WHERE INVOICE_ID ='000000000000000000' and CALLER='0000000000' and LEVEL1='Gesprekskosten'
group by LEVEL2,INVOICE_ID;ThanksThere is no difference in performance. CASE is a standard syntax that is relatively easy for any developer to read and follow. DECODE is an Oracle-specific function that is much less flexible (you can only use equality conditions, for example) and generally results in more cryptic code.
Justin -
Hi Experts,
I am working with Case Management, and I have to create Cases with all its specifications automatically. Anybody knows how I can create it? or Anybody have any suggestion or documentation to start with this.
Thanks in advance.
Regards,
Beatriz.Hi,
Easy transaction to Case Management customizing is SCASE_CUSTOMIZING. There you have an overview of the customizing of case management.
Also carryon these steps one by one...
Case Management Basic Settings :
Define Number Range Intervals for Case
Define Case Types
Determine Permitted values for attribute
Create values for "Category" attribute
Create values for "Cause" attributes
Create values for "Priority" attribute
Create values for "Reason" for escalation attribute
Assign escalation reasons to an attribute profile
Create values for "Authorization level" attribute
System Modifications
Create status profile
Create Text profile
Create Text Ids
Create Text Profile
Define Logical system for external objects
Enhanced System modifications
Note About Enhanced System Modifications
Define Processes
Set up registry
Create/Change Case Record Model
Create Profiles
Create attribute profile
Create function profile
Create terminology profile
Create Activities for authorization check
Activate application log
Define processes
Create/Change Case Record Model
When u open the Transaction SCASE_CUSTOMIZING , there will be Registry Steps...
Follow them step by step.
For any queries reply.
Regards,
Eswari. -
Integrating PL/SQL with Perl
Hello All,
I have just started learning PL/SQL and this my first R&D stuff with PL/SQL :)
I have a very basic beginner question.
Suppose I want to insert 1 lakh rows in a table through Perl. One and easiest way to do is to prepare and execute insert queries using Perl module - 'DBI' module in a loop
But I guess this will send lot of traffic over the LAN. What I rather feel is that if I execute these 1 lakh SQL queries using PL/SQL it will be comparatively more network efficient and fast.
So I have following questions:
1. Is it possible to integrate PL/SQL with Perl using 'DBI' module
2. Is there a way in PL/SQL that it will return status of all the 1 Lakh SQL queries after execution that will let me know which SQL queries were successfully executed and which failed.1. Is it possible to integrate PL/SQL with Perl using 'DBI' moduleyes, just use a PL/SQL statement instead of a sql one
2. Is there a way in PL/SQL that it will return status of all the 1 Lakh SQL queries after execution that will let me know which SQL queries were successfully executed and which failed.yes, you have to manage an exception block for each row and store the single row result in a cumulative variable:
The following code is an incomplete and not testet example:
my $STM = "
declare
ret varchar2(10);
begin
begin
insert into mytab values(1);
ret := ret||'0';
exception
when others then
ret:=ret||'1';
end;
begin
insert into mytab values(2);
ret := ret||'0';
exception
when others then
ret:=ret||'1';
end;
... and so on ...
select ret into :OUTRES from dual;
end;";
my $outres;
my $hnd = $db->prepare($STM);
$hnd->bind_param_inout( ":OUTRES", \$outres, 10); -- 10 is the variable length, e.g. the number of inserts
$hnd->execute();
print "inserts output: $outres\n";At the end of the script you should hava a string of bits. A 0 for each successful insert an 1 for each unsuccessful...
Max
[My Italian Oracle blog|http://oracleitalia.wordpress.com/2010/01/10/crittografia-in-plsql-utilizzando-dbms_crypto/]
Maybe you are looking for
-
Importing CD's to iTunes fail with "The required folder cannot be found"
I have my iTunes library on an external drive. Everything works fine, except that I cannot import CD's into iTunes. When I try, I get the error "The required folder cannot be found". My work around currently is to: 1. Upfdate my preference for "iT
-
How to restrict duplicate article codes in PO creation
plz suggest how to restrict entry of same article code more than once in various purchsing document types using ME21N transaction.
-
Incorrectly Deleted Time Machine Backups
I'm helping a relative who apparently was lead astray recently by a friend. She had a Macbook, with a full disk of Time Machine backups. She bought a new Macbook Pro to replace the Macbook. Her friend manually deleted some of the TM backups from her
-
Are the USB cables covered by the 1 year warranty if they stop working for no apparent reason? After spending 2 days trying to figure out what was wrong with my mini, it turns out it's the USB cable. I was just going to buy another one thinking they'
-
Cannot export to wmv in 2160 X 960
Hi, I need to export a video to wmv format in 2160 x 960. However, the maximum width I can get in the setting is 2000 pixels in wmv format. How can I get the size 2160x960 in wmv format? Thanks.