Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

sum based on Number values in a Char string..

694333Dec 7 2010 — edited Dec 8 2010
i have a requirement

i have a field on my form, designed in form6i (oracle 10g)

my tables are;
with t1 as (
            select 101 t1_code,'it101' t1_itcode, 10 t1_qty, 5.5 t1_prc from dual union all
            select 101,'it102',  5 , 3 from dual union all
            select 102,'it102', 10 , 3 from dual union all
            select 102,'it104', 10 , 5 from dual union all
            select 103,'it101', 10 , 5.5 from dual)
select * from t1;

with t2h as (
            select 11 t2h_no, 101 t2h_code from dual union all
            select 12 , 101  from dual union all
            select 13 , 102  from dual union all
            select 14 , 103  from dual )
select * from t2h;

with t2d as (
            select 11 t2d_no, 'it101' t2d_itcode, 5 t2d_qty from dual union all
            select 11 , 'it102', 5 from dual union all
            select 12 , 'it101', 5 from dual union all
            select 13 , 'it102', 5 from dual union all
            select 13 , 'it104', 5 from dual union all
            select 13 , 'it102', 5 from dual union all
            select 13 , 'it104', 5 from dual union all
            select 14 , 'it101', 10 from dual)
select * from t2d;
t1_CODE , t2h_no and t2d_no are fields Number datatype.

var m_x varchar2(20);
exec :m_x :='11,12';

lets say the value of m_x (t2d_no) is 11,12

i want the query to sum t2d_qty for t2d_no 11 & 12 and put 1 t1_prc in the resultant row
based on the matching t1_itcode with t2d_itcode

the result should be like this for m_x = 11,12
T1_IT        T1_QTY        T1_PRC
----- ------------- -------------
it101        15.000         5.500
it102         5.000         3.000

if m_x hold just 11 then it should return just;

T1_IT        T1_QTY        T1_PRC
----- ------------- -------------
it101         5.000         5.500
it102         5.000         3.000
if m_x hold just 11,13 then it should return an error msg
as the t2h_code is not the same for t2d_no 11 & 13;

kindly suggest..

TY
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 5 2011
Added on Dec 7 2010
2 comments
754 views