T-SQL help require to construct a query to sum on varchar column
Guys,
I have a column varchar(400) wherein currency_amount is stored. I need to sum currencyamount however getting the error like Arithmetic overflow error converting varchar to data type numeric.
Any suggestion? it has some values which are having 37 digits after decimal. Might be this is the possible reason.
Few Ex. .240189558129349189976534590012169112856, .312064488126471335301440042584800148951
This is the query i am trying
select sum(convert(decimal(38,20),columnname))
FROM tablename
Did you try converting to float? Also, why do you have such high number of digits if you're talking about currency amounts? Normally, 2 digits is enough for currency.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles
Similar Messages
-
Urgent Help required in Tunning this query
I have table ACCOUNT SPONSOR HOMESTORE ASH with more than 30 million rows.
My batch daily need to update or insert into this table from a temporary table TEMP_HSTRALCT. The data for temporary table is populated by below query which selects from two tables TRANSACTION POINTS and REDEMPTIONS.However both these tables are partitioned on date time and is run daily and this is running for hours.
Can anyone please help me on tuning this query
INSERT INTO temp_hstralct
(tmp_n_collector_account_num, tmp_v_location_id,
tmp_v_sponsor_id, tmp_v_source_file_name,
tmp_n_psc_insert_ind, tmp_n_psc_update_ind,
tmp_n_transaction_amount, tmp_n_transaction_points,
tmp_n_acc_insert_ind, tmp_n_ash_insert_ind,
tmp_n_col_insert_ind, tmp_n_check_digit,
tmp_n_collector_issue_num, tmp_n_csl_insert_ind,
tmp_v_offer_code, tmp_n_psa_insert_ind)
SELECT DISTINCT trp_n_collector_account_num account_num,
trp_v_location_id location_id,
trp_v_sponsor_id sponsor_id,
trp_c_creation_user batch_id, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0
FROM transaction_points, ACCOUNT, locations_master,homestores
WHERE hsr_v_accrual_allowed = 'Y'
AND trp_n_collector_account_num = ACCOUNT.acc_n_account_num(+)
AND ( ( ( ACCOUNT.acc_v_account_type = 'C'
OR ACCOUNT.acc_v_account_type IS NULL
AND hsr_v_b2c_accounts = 'Y'
OR ( ACCOUNT.acc_v_account_type = 'B'
AND hsr_v_nfb_accounts = 'Y'
OR ( ACCOUNT.acc_v_account_type = 'H'
AND hsr_v_hybrid_accounts = 'Y'
AND trp_d_creation_date_time BETWEEN SYSDATE-3
AND SYSDATE
AND trp_v_sponsor_id = 'JSAINSBURY'
AND trp_v_location_id =
locations_master.lnm_v_location_id
AND locations_master.lnm_v_partner_id = 'JSAINSBURY'
AND ( ( ( (INSTR
(hsr_v_store_status,
locations_master.lnm_c_location_status
) > 0
AND (INSTR
(hsr_v_store_type,
locations_master.lnm_c_location_type
) > 0
AND hsr_v_homestore_assignment = 'ST'
OR ( ( locations_master.lnm_c_homestore_ind =
'Y'
AND (INSTR
(hsr_v_store_status,
locations_master.lnm_c_location_status
) > 0
AND hsr_v_homestore_assignment = 'HS'
UNION ALL
SELECT DISTINCT rdm_n_collector_account_num account_num,
rdm_v_location_id location_id,
rom_v_supplier_id sponsor_id,
rdm_c_creation_user batch_id, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0
FROM redemption_details,
reward_offer_master,
ACCOUNT,
locations_master,
HOMESTORES
WHERE hsr_v_redemption_allowed = 'Y'
AND rdm_n_collector_account_num = ACCOUNT.acc_n_account_num(+)
AND ( ( ( ACCOUNT.acc_v_account_type = 'C'
OR ACCOUNT.acc_v_account_type IS NULL
AND hsr_v_b2c_accounts = 'Y'
OR ( ACCOUNT.acc_v_account_type = 'B'
AND hsr_v_nfb_accounts = 'Y'
OR ( ACCOUNT.acc_v_account_type = 'H'
AND hsr_v_hybrid_accounts = 'Y'
AND rdm_d_creation_date_time BETWEEN SYSDATE-3
AND SYSDATE
AND rom_v_reward_offer_id = rdm_v_reward_id
AND rom_v_supplier_id = 'JSAINSBURY'
AND rdm_v_location_id =
locations_master.lnm_v_location_id
AND locations_master.lnm_v_partner_id ='JSAINSBURY'
AND ( ( ( (INSTR
(hsr_v_store_status,
locations_master.lnm_c_location_status
) > 0
AND (INSTR
(hsr_v_store_type,
locations_master.lnm_c_location_type
) > 0
AND hsr_v_homestore_assignment = 'ST'
OR ( ( locations_master.lnm_c_homestore_ind =
'Y'
AND (INSTR
(hsr_v_store_status,
locations_master.lnm_c_location_status
) > 0
AND hsr_v_homestore_assignment = 'HS'
);I have copied the explain as it is and can you please try pasting in the text pad.Can you let me know whether parallel hint on this will speed up the select queries.
Plan
INSERT STATEMENT CHOOSECost: 410,815 Bytes: 2,798,394 Cardinality: 15,395
32 UNION-ALL
15 SORT UNIQUE Cost: 177,626 Bytes: 2,105,592 Cardinality: 11,896
14 FILTER
13 HASH JOIN Cost: 177,312 Bytes: 2,105,592 Cardinality: 11,896
2 TABLE ACCESS BY INDEX ROWID LMHOLTP.LOCATIONS_MASTER Cost: 37 Bytes: 23,184 Cardinality: 966
1 INDEX RANGE SCAN NON-UNIQUE LMHOLTP.IX_LOCATIONS_MASTER_3 Cost: 3 Cardinality: 1
12 FILTER
11 HASH JOIN OUTER
8 MERGE JOIN CARTESIAN Cost: 155,948 Bytes: 702,656,660 Cardinality: 4,845,908
3 TABLE ACCESS FULL LMHOLTP.HOMESTORES Cost: 2 Bytes: 104 Cardinality: 1
7 BUFFER SORT Cost: 155,946 Bytes: 198,682,228 Cardinality: 4,845,908
6 PARTITION RANGE ITERATOR Partition #: 12
5 TABLE ACCESS BY LOCAL INDEX ROWID LMHOLTP.TRANSACTION_POINTS Cost: 155,946 Bytes: 198,682,228 Cardinality: 4,845,908 Partition #: 12
4 INDEX RANGE SCAN NON-UNIQUE LMHOLTP.IX_TRANSACTION_POINTS_1 Cost: 24,880 Cardinality: 6,978,108 Partition #: 12
10 PARTITION RANGE ALL Partition #: 15 Partitions accessed #1 - #5
9 TABLE ACCESS FULL LMHOLTP.ACCOUNT Cost: 6,928 Bytes: 68,495,680 Cardinality: 8,561,960 Partition #: 15 Partitions accessed #1 - #5
31 SORT UNIQUE Cost: 233,189 Bytes: 692,802 Cardinality: 3,499
30 FILTER
29 FILTER
28 NESTED LOOPS OUTER
24 HASH JOIN Cost: 226,088 Bytes: 664,810 Cardinality: 3,499
16 TABLE ACCESS FULL LMHOLTP.REWARD_OFFER_MASTER Cost: 8 Bytes: 2,280 Cardinality: 114
23 HASH JOIN Cost: 226,079 Bytes: 8,327,280 Cardinality: 48,984
20 TABLE ACCESS BY INDEX ROWID LMHOLTP.LOCATIONS_MASTER Cost: 37 Bytes: 432 Cardinality: 18
19 NESTED LOOPS Cost: 39 Bytes: 2,304 Cardinality: 18
17 TABLE ACCESS FULL LMHOLTP.HOMESTORES Cost: 2 Bytes: 104 Cardinality: 1
18 INDEX RANGE SCAN NON-UNIQUE LMHOLTP.IX_LOCATIONS_MASTER_3 Cost: 3 Cardinality: 966
22 PARTITION RANGE ITERATOR Partition #: 28
21 TABLE ACCESS FULL LMHOLTP.REDEMPTION_DETAILS Cost: 226,019 Bytes: 261,636,270 Cardinality: 6,229,435 Partition #: 28
27 PARTITION RANGE ITERATOR Partition #: 30
26 TABLE ACCESS BY LOCAL INDEX ROWID LMHOLTP.ACCOUNT Cost: 2 Bytes: 8 Cardinality: 1 Partition #: 30
25 INDEX UNIQUE SCAN UNIQUE LMHOLTP.CO_PK_ACCOUNT Cost: 1 Cardinality: 1 Partition #: 30 -
SQL Query issue with large varchar column
I have a SQL Query (PL/SQL function body returning SQL query) which contains a large varchar column. Even if I substring the column to 30chars when it displays on the page it wraps. I have tried putting nowrap="wrap" for the HTML table cell attributes and it still wraps. I have tried setting the width attributes on the column even though it's not an updateable column. Does anyone have any ideas on how prevent this from wrapping. In some cases 1 line will take up 3 because of this wrapping issue and it's not nice to look at. It seems that the column is somewhere set to a fixed width, which is less than 30 characters, and anything beyond this fixed width wraps.
Hi Netha,
Can you please provide the DDLs of three tables you are using,
Also post us how many rows you are getting output for this query?
select * from dim.store st where
st.store_code = 'MAUR'
also try to run and update statement on this table as below and execute your query
update dim.store
set store_code
= ltrim(rtrim(store_code))
where
store_code = 'MAUR'
once you run this update, then run your query. Let us know the result. -
Help required in refining a query
I have a sql query :
select C1 AS No_Of_Completed_WOs, C2 as Wos_with_Soft_Fail, (C1-C2) as Completed_Wos,C3 as Failed_Wos,C4 as TimedOut_Wos from (select (CASE WHEN TBL_WRK_ORD.EXTSYS_ID IS NULL THEN '<NULL>'
ELSE TBL_WRK_ORD.EXTSYS_ID END),
count(case when WO_STAT=104 AND XACTION_TYPE like '%Completion%' then WO_STAT end ) as C1,
count(case when WO_STAT=104 AND XACTION_TYPE like '%Soft Error%' then WO_STAT end ) AS C2,
count(case when WO_STAT=253 then WO_STAT end ) AS C3,
count(case when WO_STAT=251 then WO_STAT end ) AS C4
from TBL_WRK_ORD,TBL_WO_EVENT_QUEUE WHERE TBL_WRK_ORD.WO_ID=TBL_WO_EVENT_QUEUE.WO_ID group by TBL_WRK_ORD.EXTSYS_ID)
The query basically maintains a separate counter for each of the qualifying condition.
C1 : if the WO_STAT is 104 and XACTION_TYPE is '%Completion%'
C2 : if the WO_STAT is 104 and XACTION_TYPE is '%Soft Error%'
C3 : if the WO_STAT is 253
C4 : if the WO_STAT is 251.
Now, the requirement is that we need to fetch distinct records, based on which the summation will be carried upon.
I was not able to incorporate the "distinct" logic in the above query.
Required help in this regards, as how to fetch distinct records and use it in the summation logic.
A quick help would be appreciated and thankful.
Regards
RAT.
Edited by: user9546298 on Feb 24, 2010 6:36 AM
Edited by: user9546298 on Feb 24, 2010 7:06 AMHere is the sample data :
{code }
Table : TBL_WRK_ORD
WO_ID SCHED_DTS WO_STAT
EXTSYS_ID
A00000001-QRY_ISUP_SERVICE_L 20091126 03:28:02 103
MRK
A00000002-S3 20091201 02:42:34 255
MRK
A00000003-A4 20091201 02:50:28 253
A00000006-ADD1 20091202 05:37:45 104
A00000004-ADD1 20091201 03:40:39 104
A00000005-DNH1 20091202 05:12:06 253
6 rows selected.
Table : TBL_WO_EVENT_QUEUE
WO_ID XACTION_TYPE
A00000001-QRY_ISUP_SERVICE_L WO Accept
A00000001-QRY_ISUP_SERVICE_L WO Startup
A00000001-QRY_ISUP_SERVICE_L WO Completion
A00000002-S3 WO Accept
A00000003-A4 WO Accept
A00000003-A4 WO Startup
A00000003-A4 WO Rollback
A00000003-A4 WO Failure
A00000005-DNH1 WO Rollback
A00000005-DNH1 WO Failure
A00000006-ADD1 WO Accept
A00000006-ADD1 WO Startup
A00000004-ADD1 WO Accept
A00000004-ADD1 WO Startup
A00000004-ADD1 WO Completion
A00000005-DNH1 WO Accept
A00000005-DNH1 WO Startup
A00000006-ADD1 WO Completion
Current output :
NO_OF_COMPLETED_WOS WOS_WITH_SOFT_FAIL COMPLETED_WOS FAILED_WOS TIMEDOUT_WOS
2 0 2 8 0
0 0 0 0 0
Here, as you can see above that the result has duplicates, which caused the counters to show wrong result.
Now, the query should filter based on given criteria and produce the count of the filtered rows.
But doing so, should consider distinct rows for counting.
Also, just placing distinct at counting logic [ pasted by you ] didnot work. I tried it out, but in vain.
Regards
RAT.
Edited by: user9546298 on Feb 24, 2010 7:09 AM -
Help required in writing a query
hi
Consider a table (ShogenValue) with following data:
Model_Id header_id Serial_no shogen_no si_val
4329 1 40001 A0001 1
4329 1 40001 B0001 2
4329 1 50300 B0001 3
4329 1 40001 C0001 4
4329 1 50300 C0001 5
4329 1 60001 C0001 6
Select
si_val
From
ShogenValue
Where
model_id = 4329
And
header_id = 1
And
serial_no = '60001'
Is it possible to write a modified version of above query which will bring the following result:
Model_Id header_id Serial_no shogen_no si_val
4329 1 40001 A0001 1
4329 1 50300 B0001 3
4329 1 60001 C0001 6
Meaning if a record exists for a particular shogen_no (Shogen_no C0001 has value corrosponding to '60001' in above query), pick it up, if it
does not exist (Shogen_no B0001 does not have value corrosponding to '60001' in above case) then pick a record with one level less serial number ('50300' in above case) and so on.
Thanx
Regards
Omer ImtiazThis should help, although it will probably not perform. Try it and see what the plan for it is.
SELECT
FROM
shogenvalue sv,
(SELECT
max(serial_no) serial_no_max,
shogen_no
FROM
shogenvalue
WHERE
model_id = 4329
AND header_id = 1
AND serial_no <= '60001'
GROUP BY
shogen_no
) svm
WHERE
sv.serial_no = svm.serial_no_max
AND sv.shogen_no = svm.shogen_no
;HTH,
Lennert -
Help required in writing the query
I have the following level accounts
10000
11000
11100
11101
11200
11201
12000
12100
12101
12102
12103
20000
21000
21100
21101
22000
22101
21200
21201
I have to take the amount of the child account and sum it to the parent account as below:
11100 = 11101 + 11102 - 11103+.........
11000 = 11100 + 11200 + 11300+.........
10000 = 11000 + 12000 + 13000+.........
21100 = 21101 + 21102 - 21103+.........
21000 = 21100 + 21200 + 21300+.........
20000 = 21000 + 22000 + 23000+.........
Please help...
Thanks in advance.SQL> with t as (
2 select 10000 ACCOUNT, NULL BEG_BAL, NULL END_BAL from dual union all
3 select 11000,NULL,NULL from dual union all
4 select 11100,NULL,NULL from dual union all
5 select 11101,1750.00,4150.00 from dual union all
6 select 11102,1550.00,3150.00 from dual union all
7 select 11103,1650.00,3200.00 from dual union all
8 select 11200,NULL,NULL from dual union all
9 select 11201,800.00,1250.00 from dual union all
10 select 11202,1550.00,3150.00 from dual union all
11 select 12000,NULL,NULL from dual union all
12 select 12100,NULL,NULL from dual union all
13 select 12101,1200.00,5000.00 from dual union all
14 select 12102,1500.00,3000.00 from dual union all
15 select 12103,1550.00,2750.00 from dual union all
16 select 20000,NULL,NULL from dual union all
17 select 21000,NULL,NULL from dual union all
18 select 21100,NULL,NULL from dual union all
19 select 21101,2000.00,6500.00 from dual union all
20 select 21102,1500.00,3500.00 from dual union all
21 select 21103,1750.00,3550.00 from dual union all
22 select 22000,NULL,NULL from dual union all
23 select 22100,NULL,NULL from dual union all
24 select 22101,1550.00,3550.00 from dual union all
25 select 22102,2550.00,5550.00 from dual union all
26 select 21200,NULL,NULL from dual union all
27 select 21201,2550.00,6500.00 from dual union all
28 select 21202,3550.00,7500.00 from dual
29 )
30 select account,
31 beg_bal,
32 end_bal,
33 sum(beg_bal) over(order by account range between current row and grouping_window follow
ing) group_beg_bal,
34 sum(end_bal) over(order by account range between current row and grouping_window follow
ing) group_end_bal
35 from (
36 select t.*,
37 case
38 when account / 10000 = trunc(account / 10000) then 9999
39 when account / 1000 = trunc(account / 1000) then 999
40 when account / 100 = trunc(account / 100) then 99
41 when account / 10 = trunc(account / 10) then 9
42 else 0
43 end grouping_window
44 from t
45 )
46 order by account
47 /
ACCOUNT BEG_BAL END_BAL GROUP_BEG_BAL GROUP_END_BAL
10000 11550 25650
11000 7300 14900
11100 4950 10500
11101 1750 4150 1750 4150
11102 1550 3150 1550 3150
11103 1650 3200 1650 3200
11200 2350 4400
11201 800 1250 800 1250
11202 1550 3150 1550 3150
12000 4250 10750
12100 4250 10750
ACCOUNT BEG_BAL END_BAL GROUP_BEG_BAL GROUP_END_BAL
12101 1200 5000 1200 5000
12102 1500 3000 1500 3000
12103 1550 2750 1550 2750
20000 15450 36650
21000 11350 27550
21100 5250 13550
21101 2000 6500 2000 6500
21102 1500 3500 1500 3500
21103 1750 3550 1750 3550
21200 6100 14000
21201 2550 6500 2550 6500
ACCOUNT BEG_BAL END_BAL GROUP_BEG_BAL GROUP_END_BAL
21202 3550 7500 3550 7500
22000 4100 9100
22100 4100 9100
22101 1550 3550 1550 3550
22102 2550 5550 2550 5550
27 rows selected.
SQL> SY. -
Help required in optimizing the query response time
Hi,
I am working on a application which uses a jdbc thin client. My requirement is to select all the table rows in one table and use the column values to select data in another table in another database.
The first table can have maximum of 6 million rows but the second table rows will be around 9000.
My first query is returning within 30-40 milliseconds when the table is having 200000 rows. But when I am iterating the result set and query the second table the query is taking around 4 millisecond for each query.
the second query selection criteria is to find the value in the range .
for example my_table ( varchar2 column1, varchar2 start_range, varchar2 end_range);
My first query returns a result which then will be used to select using the following query
select column1 from my_table where start_range < my_value and end_range> my_value;
I have created an index on start_range and end_range. this query is taking around 4 millisseconds which I think is too much.
I am using a preparedStatement for the second query loop.
Can some one suggest me how I can improve the query response time?
Regards,
ShyamTry the code below.
Pre-requistee: you should know how to pass ARRAY objects to oracle and receive resultsets from java. There are 1000s of samples available on net.
I have written a sample db code for the same interraction.
Procedure get_list takes a array input from java and returns the record set back to java. You can change the tablenames and the creteria.
Good luck.
DROP TYPE idlist;
CREATE OR REPLACE TYPE idlist AS TABLE OF NUMBER;
CREATE OR REPLACE PACKAGE mypkg1
AS
PROCEDURE get_list (myval_list idlist, orefcur OUT sys_refcursor);
END mypkg1;
CREATE OR REPLACE PACKAGE BODY mypkg1
AS
PROCEDURE get_list (myval_list idlist, orefcur OUT sys_refcursor)
AS
ctr NUMBER;
BEGIN
DBMS_OUTPUT.put_line (myval_list.COUNT);
FOR x IN (SELECT object_name, object_id, myvalue
FROM user_objects a,
(SELECT myval_list (ROWNUM + 1) myvalue
FROM TABLE (myval_list)) b
WHERE a.object_id < b.myvalue)
LOOP
DBMS_OUTPUT.put_line ( x.object_name
|| ' - '
|| x.object_id
|| ' - '
|| x.myvalue
END LOOP;
END;
END mypkg1;
[pre]
Testing the code above. Make sure dbms output is ON.
[pre]
DECLARE
a idlist;
refc sys_refcursor;
c number;
BEGIN
SELECT x.nu
BULK COLLECT INTO a
FROM (SELECT 5000 nu
FROM DUAL) x;
mypkg1.get_list (a, refc);
END;
[pre]
Vishal V. -
Help required regarding tunning the query mentioned
HI all ,
Query mentioned below takes around 1 hr to complete . It's being used by the autoconfig kindly me in tunning it ..
QUery :
UPDATE WF_ITEM_ATTRIBUTE_VALUES WIAV SET WIAV.TEXT_VALUE = REPLACE(WIAV.TEXT_VALUE,:B1,:B2)
WHERE (WIAV.ITEM_TYPE, WIAV.NAME) = (SELECT WIA.ITEM_TYPE, WIA.NAME
FROM WF_ITEM_ATTRIBUTES WIA WHERE WIA.TYPE = 'URL'
AND WIA.ITEM_TYPE = WIAV.ITEM_TYPE
AND WIA.NAME = WIAV.NAME)
AND WIAV.TEXT_VALUE IS NOT NULL
AND INSTR(WIAV.TEXT_VALUE
, :B1) > 0
Plan :*
<pre>
| Id | Operation | Name | Rows | Bytes | Cost |
| 0 | UPDATE STATEMENT | | 453 | 14496 | 284K|
| 1 | UPDATE | WF_ITEM_ATTRIBUTE_VALUES | | | |
|* 2 | FILTER | | | | |
|* 3 | TABLE ACCESS FULL | WF_ITEM_ATTRIBUTE_VALUES | 453 | 14496 | 282K|
|* 4 | TABLE ACCESS BY INDEX ROWID| WF_ITEM_ATTRIBUTES | 1 | 33 | 2 |
|* 5 | INDEX UNIQUE SCAN | WF_ITEM_ATTRIBUTES_PK | 1 | | 1 |
Predicate Information (identified by operation id):
2 - filter(("SYS_ALIAS_2"."ITEM_TYPE","SYS_ALIAS_2"."NAME")= (SELECT /*+ */
"WIA"."ITEM_TYPE","WIA"."NAME" FROM "APPLSYS"."WF_ITEM_ATTRIBUTES" "WIA" WHERE
"WIA"."NAME"=:B1 AND "WIA"."ITEM_TYPE"=:B2 AND "WIA"."TYPE"='URL'))
3 - filter("SYS_ALIAS_2"."TEXT_VALUE" IS NOT NULL AND
INSTR("SYS_ALIAS_2"."TEXT_VALUE",:Z)>0)
4 - filter("WIA"."TYPE"='URL')
5 - access("WIA"."ITEM_TYPE"=:B1 AND "WIA"."NAME"=:B2)
</pre>
Index :*
<pre>
INDEX_NAME COLUMN_NAME
APPLSYS WF_ITEM_ATTRIBUTE_VALUES_PK 1 ITEM_TYPE
2 ITEM_KEY
3 NAME
</pre>
regds
Rahul
Edited by: RahulG on Jan 2, 2009 10:47 PM
Edited by: RahulG on Jan 2, 2009 10:48 PMRahulG wrote:
HI all ,
Query mentioned below takes around 1 hr to complete . It's being used by the autoconfig kindly me in tunning it ..
A few notes:
1. Your query is using bind variables. If you're already on 9i or later (probably 9iR2 according to plan output), this statement will be subject to bind variable peeking and therefore the output of EXPLAIN PLAN is only of limited use, since the actual execution plan might be different and/or might be based on different cardinality estimates based on the actual bind values peeked at hard parse time. You can use the V$SQL_PLAN view to get the actual execution plan(s) if the statement is still cached in the shared pool, from 10g on DBMS_XPLAN.DISPLAY_CURSOR is available for that purpose.
2. The execution plan posted suggests that only 453 rows will correspond to the filter criteria (but, as mentioned in 1. is based on an unknown bind variable value when using EXPLAIN PLAN), and probably therefore the optimizer didn't unnest the subquery but runs this as recursive FILTER query potentially for each row passing the filter criteria on the driving table WF_ITEM_ATTRIBUTE_VALUES. Depending on the actual number of rows this might be inefficient, and unnesting the subquery and turning it into a join might be more appropriate. This might accomplished e.g. by providing more representative statistics to the optimizer (are the statistics up-to-date?).
Although you can't change the SQL you could try this manually by using the UNNEST hint to see if it makes any difference in the execution plan (and run time):
WHERE (WIAV.ITEM_TYPE, WIAV.NAME) = (SELECT /*+ UNNEST */ WIA.ITEM_TYPE, WIA.NAME
...3. The composite index WF_ITEM_ATTRIBUTE_VALUES_PK can only be used on the first column ITEM_TYPE for effective index access, the NAME column would have to be used as filter on all index leaf blocks that would be found using a range scan on ITEM_TYPE. This might be quite inefficient, and/or might lead to a lot of rows/blocks that need to be visited in the table using this index access path.
4. You could try to trace the execution by enabling extended SQL trace, e.g. using the (undocumented) DBMS_SUPPORT package in 9i. Running the "tkprof" utility on the generated trace file tells you the actual row source cardinalities (which can then be compared to the estimates of the optimizer) and - if the "waits" have been enabled - what your statement has waited for most.
Regards,
Randolf
Oracle related stuff blog:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/ -
Whats wrong in this SQL - Help Required..
Hi,
Can you please tell me what is wrong in this SQL Query.
select
case
when
(SELECT territory_code
FROM
fnd_territories
where territory_code like 'BR') then
(SELECT description
FROM fnd_descr_flex_contexts_tl
WHERE descriptive_flexfield_name='JG_PO_VENDOR_SITES'
AND descriptive_flex_context_code='JL.BR.APXVDMVD.SITES')
else
NULL
end result
FROM dual;
Thanks,Based on the info supplied, here's a few possibilities,
you've typed the table name incorrectly
You've not restricted the results correctly,
you're using a version of oracle that doesn't support the CASE expression
You're using SQL server, which doesn't have the dual table.
you've / someone has manipulated teh dual table so that it now has 4billion and one rows
The subquery in your case statement returns more than one row.
1. It's poorly/not formatted.
2. It's not in code tags
3. You haven't given us anywhere near enough info e.g. Error messages, what you're actually trying to do etc, etc -
Hi,
I have a table "upsd_intmdt_new", which holds data for different snapshot_key or for different dates. Now I can write a query as shown below :
select F_NAME F_NAME,
itm_cd_key itm_cd_key,
max(itm_cd) itm_cd,
max(opr_cd) opr_cd,
max(opr_dsc) opr_dsc,
max(chpst_type) chpst_type,
max(fmly) fmly,
max(qtr_key) qtr_key,
max(fscl_yr_qtr_int_nbr) fscl_yr_qtr_int_nbr,
mo_key mo_key,
max(fscl_yr_mo_nbr) fscl_yr_mo_nbr,
max(frst_day_fscl_mo_dt) frst_day_fscl_mo_dt ,
sls_org_cd sls_org_cd,
max(sls_org_dsc) sls_org_dsc,
max(PASD_CGID) PASD_CGID
from upsd_intmdt_new
where snpsht_key in (2050, 2052)
group by F_NAME,
itm_cd_key,
mo_key,
sls_org_cd
Now I want max(PASD_CGID) will be taken for snpsht_key=2052 only, and all other max will be calculated from the combination dataset of snpsht_key=2050 & 2052.
Is this possible to write in a single query.
Your help will really be appriciated in this case.
Regards,
KoushikI am able to handle it in the following way :
select F_NAME F_NAME,
itm_cd_key itm_cd_key,
max(itm_cd) itm_cd,
max(opr_cd) opr_cd,
max(opr_dsc) opr_dsc,
max(chpst_type) chpst_type,
max(fmly) fmly,
max(qtr_key) qtr_key,
max(fscl_yr_qtr_int_nbr) fscl_yr_qtr_int_nbr,
mo_key mo_key,
max(fscl_yr_mo_nbr) fscl_yr_mo_nbr,
max(frst_day_fscl_mo_dt) frst_day_fscl_mo_dt ,
sls_org_cd sls_org_cd,
max(sls_org_dsc) sls_org_dsc,
max(case when snpsht_key=2052 then PASD_CGID end) PASD_CGID
from upsd_intmdt_new
where snpsht_key in (2050, 2052)
group by F_NAME,
itm_cd_key,
mo_key,
sls_org_cd
Hopefully this is the correct way of handling this thing.
Regards,
Koushik -
Sir, I am working for some data warehouse project in which I want to invoke unix shell command from PL/SQL Block, for example, I want to invoke a sql loder from a PL/SQL block. Is it possible. I have searched in all possible resources available with me but couldn't find any solution.
Any sample code will be of great help.You can try either of these, I don't know about the second one, I think you have to search that site for a Pl/SQL package to execute host commands.
http://www.ckamco.com/Execute_Command.zip
http://www.quest-pipelines.com/Pipelines/PLSQL/archives.htm#code -
Help required in creating a QUERY!!!
hi my name is johnny. I am new to this forums.
My question is
"There are 4 players in a team and that team played 4 matches. The scores for player1: 34,44,23,9. player2: 12,15,62,40. player3: 54,65,34,82. player4: 77,53,69,88. in four inning in four matches respectively. So my question is that i want highest score of each player in a column in the desceding order."
Sample output:
player_name test1 test2 test3 test4 highest_score
player4 77 53 69 88 88
player3 54 65 34 82 82
player2 12 15 62 40 62
player1 34 44 23 09 44Can you tell us how your data is stored in the database. I mean what is the table structure of the table that stores the data for all the inings and scores for all the players?
Faisal. -
Hi There,
I am new to Oracle and I dont have much grip on SQL ..I am stuck on a query ..following is the whole scenario for your understanding (WITH TWO VOUCHERS DATA ONLY)
1. Table Structure (VOUCHER_DETAIL_TABLE)
Voucher_no....number(10)
Voucher_date...date
ACC_CODE......number(8)
DEBIT...............number(13,2)
CREDIT............number(13,2)
VTYPE............varchar2(2)
2. DATA IN TABLE
voucher_no.....voucher_date.....acc_code....... debit.......credit.......vtype.........
....0001.............29-08-07.........24400001........5000.......................CR...........
....0001.............29-08-07.........24400002...... ...500.......................CR...........
....0001.............29-08-07.........24400003....... ..500.......................CR...........
....0001.............29-08-07.........24400004........ .500.......................CR...........
....0001.............29-08-07.........25000000.......................6500........CR...........
....0002.............30-08-07..........25000000.......12000......................CP............
....0002.............30-08-07..........24400001......................5000.........CP...........
....0002.............30-08-07..........24400005......................3000.........CP...........
....0002.............30-08-07..........24400005......................4000.........CP...........
Note that in both of the vouchers there is one compound entry in every voucher which is the sum of all entries on the other side...now what I want is that if the user will enter acc_code as query criteria for example 255000000 the outpu will come
....0001.............29-08-07.........24400001........5000.......................CR...........
....0001.............29-08-07.........24400002...... ...500.......................CR...........
....0001.............29-08-07.........24400003....... ..500.......................CR...........
....0001.............29-08-07.........24400004........ .500.......................CR...........
and if the user will enter 24400001 as query criteria it should show only one CONTRA entry and output will be
....0001.............29-08-07.........25000000.......................6500........CR...........
so its basically showing contra's against each other datawise voucher.
Plz help me to construct the query as I have a short time...thanks
if any advice in structure to make it better and easy will be highly appreciatable.
ThanksNicolas :) lah me clear again.
well in usual double entry accounting vouchers goes this way.
1 entry on debit side and other entry on credit side...same amount offcourse..
example.
Voucher # : 1
Voucher Date : 29-08-07
Acc_code....Name...........................Debit...........Credit..............
25000000....cash in hand..................15000.................................
24000001....Josh & Co.......................................15000................
Voucher # : 2
Voucher Date : 30-08-07
Acc_code....Name...........................Debit...........Credit..............
24000002....Wilson Pharma..................................7500................
25000000....Cash in Hand..................7500...................................
By following the above USUAL way the data would go in the voucher detail table like this.
Voucherno......acc_code.......name...........................debit........credit................
....1............... 25000000....cash in hand..................15000.................................
....1.............. 24000001....Josh & Co.......................................15000................
....2.............. 24000002....Wilson Pharma..............7500...................................
....2.............. 25000000....Cash in Hand..................................7500.................
Clear ?? ..now in my company they've started multiple entries in voucher like this.
Voucher # : 1
Voucher Date : 29-08-07
Acc_code....Name...........................Debit...........Credit..............
25000000....cash in hand..................15000.................................
24000001....Josh & Co.......................................13000..............
26100005....Misc Charges 1................................. 1000...............
26100006....Misc Charges 2................................. 1000...............
Now in the table data would go this way.
Voucherno......acc_code.......name...........................debit........credit................
....1............... 25000000....cash in hand..................15000.................................
....1.............. 24000001....Josh & Co.......................................13000................
....1.............. 26100005....Misc Charges 1................................. 1000.............
....1.............. 26100006....Misc Charges 2................................. 1000.............
....2.............. 24000002....Wilson Pharma..............7500...................................
....2.............. 25000000....Cash in Hand..................................7500.................
Well here is the report part...the accountant now wants to see the reflection in the ledger of the particular account.
For example...he wants to see the reflecting entries of CASH IN HAND account which will tell against cash in hand account what did he CREDIT in voucher # 1.
so he will enter CASH IN HAND account # 25000000 and it show the reflection (the credit side) offcourse...
Hope u got it straight now :) or u need one more coffee ...) -
Hi
I have installed the required .Net software, but never the less I've got this message. Could you please help me out ?
Thanx in advance
Pia
TITLE: Microsoft SQL Server Management Studio
Cannot show Query Designer.
ADDITIONAL INFORMATION:
Exception has been thrown by the target of an invocation. (mscorlib)
Unable to find the requested .Net Framework Data Provider. It may not be installed. (System.Data)
BUTTONS:
OKalso check
http://connect.microsoft.com/VisualStudio/feedback/details/652192/visual-studio-2010-add-connection-fails
mostly machine.config is referring to .net 3.0 assemblies
Balmukund Lakhani
Please mark solved if I've answered your question, vote for it as helpful to help other users find a solution quicker
This posting is provided "AS IS" with no warranties, and confers no rights.
My Blog |
Team Blog | @Twitter
| Facebook
Author: SQL Server 2012 AlwaysOn -
Paperback, Kindle -
Help Required(Rewriting the query to reduce steps)
With and Without Group ID,I am populating a value into a column,Can anyone please help to write the same query in an other way.This is a sample column.Likewise,there are 5 more columns to be populated.So that I have to write 2 left outer joins for a single column with a little difference.
SELECT
CASE
WHEN T6.ACTUAL_FUNCTION IS NOT NULL
THEN T6.ACTUAL_FUNCTION
WHEN T10.ACTUAL_FUNCTION IS NOT NULL
THEN T10.ACTUAL_FUCNTION
ELSE T5.ACTUAL_FUCNTION
END AF_NOM_PRE_GTEES
FROM
ABC_WT17 T1
INNER JOIN
ABC_CUSTOMER_WT01 T3
ON T1.ORIGINAL_SDS_PARTY_IDR=T3.ORIGINAL_SDS_PARTY_IDR
AND T1.IDR_TYPE_CODE=T3.IDR_TYPE_CODE
LEFT OUTER JOIN /* This is the condition with group ID*/
RESIDUAL_CONTROL T6
ON
T1.NOM_PRE_GTEES = T6.VALUE_MAX
OR
T1.NOM_PRE_GTEES > T6.VALUE_GREATER_THAN
AND
T1.NOM_PRE_GTEES < T6.VALUE_MAX
AND
_ T1.GROUP_ID = T6.GROUP_ID_
AND
T6.FALLBACK_IND = ‘N’
LEFT OUTER JOIN /* this is the condition without Group ID*/
RESIDUAL_CONTROL T10
ON
T1.NOM_PRE_GTEES = T10.VALUE_MAX
OR
T1.NOM_PRE_GTEES > T10.VALUE_GREATER_THAN
AND
T1.NOM_PRE_GTEES < T10.VALUE_MAX
AND
T10.FALLBACK_IND = ‘N’
CROSS JOIN
RESIDUAL_CONTROL T5
ON T5.FALLBACK_IND = ‘Y’
Thanks in advance.KVB wrote:
With and Without Group ID,I am populating a value into a column,Can anyone please help to write the same query in an other way.This is a sample column.Likewise,there are 5 more columns to be populated.So that I have to write 2 left outer joins for a single column with a little difference.
SELECT
CASE
WHEN T6.ACTUAL_FUNCTION IS NOT NULL
THEN T6.ACTUAL_FUNCTION
WHEN T10.ACTUAL_FUNCTION IS NOT NULL
THEN T10.ACTUAL_FUCNTION
ELSE T5.ACTUAL_FUCNTION
END AF_NOM_PRE_GTEES
FROM
ABC_WT17 T1
INNER JOIN
ABC_CUSTOMER_WT01 T3
ON T1.ORIGINAL_SDS_PARTY_IDR=T3.ORIGINAL_SDS_PARTY_IDR
AND T1.IDR_TYPE_CODE=T3.IDR_TYPE_CODE
LEFT OUTER JOIN /* This is the condition with group ID*/
RESIDUAL_CONTROL T6
ON
T1.NOM_PRE_GTEES = T6.VALUE_MAX
OR
T1.NOM_PRE_GTEES > T6.VALUE_GREATER_THAN
AND
T1.NOM_PRE_GTEES < T6.VALUE_MAX
AND
_ T1.GROUP_ID = T6.GROUP_ID_
AND
T6.FALLBACK_IND = ‘N’
LEFT OUTER JOIN /* this is the condition without Group ID*/
RESIDUAL_CONTROL T10
ON
T1.NOM_PRE_GTEES = T10.VALUE_MAX
OR
T1.NOM_PRE_GTEES > T10.VALUE_GREATER_THAN
AND
T1.NOM_PRE_GTEES < T10.VALUE_MAX
AND
T10.FALLBACK_IND = ‘N’
CROSS JOIN
RESIDUAL_CONTROL T5
ON T5.FALLBACK_IND = ‘Y’
Thanks in advance.Thread: HOW TO: Post a SQL statement tuning request - template posting
HOW TO: Post a SQL statement tuning request - template posting
Maybe you are looking for
-
I've updated to the most recent version of iTunes and I can no longer see any of my old music on my mac. All the music is still available on my ipad. How can i download the music on my mac?
-
I Can't Back-up/Sync/Update My Phone Anymore Since I Have A New Laptop?
The old computer is gone, I deauthorized it before I wiped the HDD. So, now I have a new laptop with iTunes on it and I can't sync to it without wiping my entire phone? What can I do? This makes no sense. I am using the same Apple ID, the old com
-
Difference in report f.01 and total depreciation report S_ALR87012004
Hi all, Could you please find that the difference in the above report is due to direct jv passed by the user, then how to correct it without disturbing the other balance. Or else what are the possibility of the difference other then jv entry in repor
-
How to find active object ?
Hi, Can anybody please guide me , how to find an active BW objects like Info cube,ODS,info source and info objects? Please answer in details. Thanks and regards DEP
-
Lightroom 4.4.1 odd file change problem
Hi folks, Let's see if I can accurately descibe this and perhaps get an explanation from you. I have a folder, for example, called 2004 keepers. Obviously, I have had this images since at least 2004 MANY of them are jpg's as I did not know enough to