Help in writing stored procedrue

I have a table with records like below
ccn item sub_item
1 101a 102a
2 102a 103a
3 103a 104a
4 100x 100y
5 100y 100z
6 101b 101c
and need to load above data into other table like below
p_id p_item p_sub_item p_old_item f_code f_seq_no
1 101a 102a (null) 0001 01
2 102a 103a 101a 0001 02
3 103a 104a 102a 0001 03
4 104a (null) 103a 0001 04
5 100x 100y (null) 0002 01
6 100y 100z 100x 0002 02
7 100z (null) 100y 0002 03
8 101b 101c ( null ) 0003 01
9 101c (null _ 101b 0003 02
here ccn,p_id,f_code,f_seq_no number type
item,sub_item ,p_item,p_sub_item,p_old_item varchar type
Help me in writing the procedure

Here it is. Now you can just do an insert as select to get it in the target table.
SQL> with t as (select 1 as ccn, '101a' as item, '102a' as sub_item from dual union
  2             select 2, '102a', '103a' from dual union
  3             select 3, '103a', '104a' from dual union
  4             select 4, '100x', '100y' from dual union
  5             select 5, '100y', '100z' from dual union
  6             select 6, '101b', '101c' from dual)
  7  -- end of test data
  8  select rownum as p_id, p_item, p_sub_item, p_old_item, sum(f_code) over (order by rownum) as f_code, f_seq_no
  9  from (
10  select item as p_item
11        ,sub_item as p_sub_item
12        ,(select item from t t2 where t2.sub_item = t.item) as p_old_item
13        ,decode(level,1,1) as f_code
14        ,level as f_seq_no
15  from (select ccn, item, sub_item
16        from t
17        union
18        select ccn+0.5, sub_item, null
19        from t
20        where not exists(select 1 from t t2 where t2.item = t.sub_item)
21       ) t
22  connect by item = prior sub_item
23  start with ccn in
24       (select ccn
25        from t
26        where not exists(select 1 from t t2 where t2.sub_item = t.item)
27        )
28        order by ccn
29  )
30  /
      P_ID P_IT P_SU P_OL     F_CODE   F_SEQ_NO
         1 101a 102a               1          1
         2 102a 103a 101a          1          2
         3 103a 104a 102a          1          3
         4 104a      103a          1          4
         5 100x 100y               2          1
         6 100y 100z 100x          2          2
         7 100z      100y          2          3
         8 101b 101c               3          1
         9 101c      101b          3          2
9 rows selected.
SQL>Message was edited by:
blushadow
edited to complete the solution

Similar Messages

  • Help in writing stored procedure!!!

    Hi,
    I m working step by step ....its very unclear to me ...because, my boss gave me SAS code and asking me to convert it into PL/SQL code ...without businees requiremnet.....thats sounds really wired .....And i dont know the SAS......So please help me in this regard ..How do i write a stored procedure for the following requirement...
    Create a table master as select from*
    *( select * from acct_master*
    where join_dt < NVL( close_dt,sysdate)
    oder by acct_nbr, join_dt, nvl (close_dt,sysdate));
    here its creating a master table and inserting the acct_master(prod table) result. Now the next step is i have to query the data which i got in master which is a another step, and that resulted query has to be inserted into another table called 'TEST'.
    so how do i write a proc for this above process......Pleaseee....Help!!!! Thank you so much ...i really appriciate it.

    Raj,
    Here is the SAS code ....for What i described Before... I m absolutely new to SAS ...first time im looking at SAS code....I m Posting what they gave me and told me ....
    There are basicallY two parts ......First part creates table i guess and second part queries the data i guess...
    First part*.........
    proc sq1;
    &con_str;
    create table master (sortedby= acct_nbr join_dt ) as
    select *
    from connection to ora (
    select *
    from acct_master
    where join_dt < nvl ( close_dt, SYSDATE)
    order by acct_nbr, join_dt, NVL
    (alian_close_dt, sysdate) )
    & dis_str;
    quit;
    Second Part*
    %let EOT = '31MAY3000'd;
    data test ;
    set master (keep= acct_nbr id join_dt close_dt cu_type cu_stat csd_resn );
    format init_join_dt join_dt close_dt effective_dt expire_dt lag1_expire_dt date9.
    fy_join 4.
    init_cu_type $3. ;
    retain init_join_dt fy_join n dlk_pend lag1_expire_dt lag1_id 0
    init_cu_type ;
    by acct_nbr join_dt ;
    join_dt = datepart(join_dt);
    close_dt = datepart(close_dt)-1;
    if first.acct_nbr then do
    dlk_pend = 0;
    lag1_id = .;
    lag1_expire_dt = .;
    init_join_dt = join_dt ;
    fy_join = year(intnx('month',join_dt,7));
    init_cu_type = cu_type;
    n = 1;
    end;
    expire_dt = close_dt ;
    lag1_id = lag1(id);
    lag1_expire_dt = lag1(expire_dt) ;
    if dlk_pend then do ;
    cu_class = 'DLK';
    effective_dt = lag1_expire_dt + 1;
    expire_dt = join_dt - 1;
    curr_id = id ;
    id = lag1_id;
    dlk_pend=2;
    output;
    id = curr_id ;
    dlk_pend=0;
    end;
    effective_dt = join_dt ;
    /* If the join date is in the initial fiscal year (01 june is fiscal year) */
    if join_dt < MDY( 6, 1, fy_join ) then do
    cu_class = init_cu_type;
    /* If it's open or closed after the end of the initial fiscal year */
    if close_dt = . or close_dt >= MDY( 6, 1, fy_join ) then do ;
    * Create one record through the end of the fiscal year;
    expire_dt = MDY( 6, 1, fy_join ) -1 ;
    output;
    * Create another record through the close date or leave open;
    effective_dt = expire_dt + 1 ;
    cu_class = 'EXISTING';
    expire_dt = coalesce(close_dt,&EOT) ;
    output;
    end;
    else do;
    * it it closed in the initial fiscal year, then output just one record ;
    expire_dt = close_dt ;
    output ;
    end;
    end;
    * if the record starts after the initial fiscal year ;
    else do;
    * Create a record through the close date or leave open;
    cu_class = 'EXISTING';
    expire_dt = coalesce(close_dt,&EOT) ;
    output;
    end;
    * if record is delink, output a DLK record ;
    if cu_stat = 'CLOSED' and csd_resn = 'DLK' then do
    effective_dt = close_dt + 1;
    expire_dt = &EOT ;
    cu_class = 'DLK';
    if last.acct_nbr then output;
    else dlk_pend = 1 ;
    end;
    n+1;
    run;
    So here is the SAS code ....Thank you so much guys ...i really appriciate it!!!!

  • Need Help With a Stored Procedure

    Help With a Stored Procedure
    Hi everyone.
    I am quite new relative to creating stored procedures, so I anticipate that whatever help I could get here would be very much helpful.
    Anyway, here is my case:
    I have a table where I need to update some fields with values coming from other tables. The other tables, let us just name as tblRef1, tblRef2 and tblRef3. For clarity, let us name tblToUpdate as my table to update. tblToUpdate has the following fields.
    PlanID
    EmployeeIndicator
    UpdatedBy
    CreatedBy
    tblRef1, tblRef2 and tblRef3 has the following fields:
    UserName
    EmpIndicator
    UserID
    In my stored procedure, I need to perform the following:
    1. Check each row in the tblToUpdate table. Get the CreatedBy value and compare the same to the UserName and UserID field of tblRef1. If no value exists in tblRef1, I then proceed to check if the value exists in the same fields in tblRef2 and tblRef3.
    2. If the value is found, then I would update the EmployeeIndicator field in tblToUpdate with the value found on either tblRef1, tblRef2 or tblRef3.
    I am having some trouble writing the stored procedure to accomplish this. So far, I have written is the following:
    CREATE OR REPLACE PROCEDURE Proc_Upd IS v_rec NUMBER;
    v_plan_no tblToUpdate.PLANID%TYPE;
    v_ref_ind tblToUpdate.EMPLOYEEINDICATOR%TYPE;
    v_update_user tblToUpdate.UPDATEDBY%TYPE;
    v_created_by tblToUpdate.CREATEDBY%TYPE;
    v_correct_ref_ind tblToUpdate.EMPLOYEEIDICATOR%TYPE;
    CURSOR cur_plan IS SELECT PlanID, EmployeeIndicator, UPPER(UpdatedBy), UPPER(CreatedBy) FROM tblToUpdate;
    BEGIN
    Open cur_plan;
         LOOP
         FETCH cur_plan INTO v_plan_no, v_ref_ind, v_update_user, v_created_by;
              EXIT WHEN cur_plan%NOTFOUND;
              BEGIN
              -- Check if v_created_by has value.
                   IF v_created_by IS NOT NULL THEN
                   -- Get the EmpIndicator from the tblRef1, tblRef2 or tblRef3 based on CreatedBy
                   SELECT UPPER(EmpIndicator)
                        INTO v_correct_ref_ind
                        FROM tblRef1
                        WHERE UPPER(USERNAME) = v_created_by
                        OR UPPER(USERID) = v_created_by;
                        IF v_correct_ref_ind IS NOT NULL THEN
                        -- Update the Reference Indicator Field in the table TRP_BUSPLAN_HDR_T.
                             UPDATE TRP_BUSPLAN_HDR_T SET ref_ind = v_correct_ref_ind WHERE plan_no = v_plan_no;
                        ELSIF
                        -- Check the Other tables here????
                        END IF;
                   ELSIF v_created_by IS NULL THEN
                   -- Get the EmpIndicator based on the UpdatedBy
                        SELECT UPPER(EmpIndicator)
                        INTO v_correct_ref_ind
                        FROM tblRef1
                        WHERE UPPER(USERNAME) = v_update_user
                        OR UPPER(USERID) = v_created_by;
                        IF v_correct_ref_ind IS NOT NULL THEN
                        -- Update the Reference Indicator Field in the table TRP_BUSPLAN_HDR_T.
                             UPDATE TRP_BUSPLAN_HDR_T SET ref_ind = v_correct_ref_ind WHERE plan_no = v_plan_no;
                        ELSIF
                        -- Check the Other tables here????
                        END IF;
                   END IF;
              END;
         END LOOP;
         CLOSE cur_plan;
         COMMIT;
    END
    Please take note that the values in the column tblToUpdate.UpdatedBy or tblToUpdate.CreatedBy could match either the UserName or the UserID of the table tblRef1, tblRef2, or tblRef3.
    Kindly provide more insight. When I try to execute the procedure above, I get a DATA NOT FOUND ERROR.
    Thanks.

    Ah, ok; I got the updates the wrong way round then.
    BluShadow's single update sounds like what you need then.
    I also suggest you read this AskTom link to help you see why you should choose to write DML statements before choosing to write cursor + loops.
    In general, when you're being asked to update / insert / delete rows into a table or several tables, your first reaction should be: "Can I do this in SQL?" If you can, then putting it into a stored procedure is usually just a case of putting the sql statement inside the procedure header/footers - can't really get much more simple than that! *{;-)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Help with writing and retrieving data from a table field with type "LCHR"

    Hi Experts,
    I need help with writing and reading data from a database table field which has a type of "LCHR". I have given an example of the original code but don't know what to change it to in order to fix it and still read in the original data that's stored in the LCHR field.
    Basically we have two Function modules, one that saves list data to a database table and one that reads in this data. Both Function modules have an identicle table which has an array of fields from type INT4, CHAR, and type P. The INT4 field is the first one.
    Incidentally this worked in the 4.7 non-unicode system but is now dumping in the new ECC6 Unicode system.
    Thanks in advance,
    C
    SAVING THE LIST DATA TO DB
    DATA: L_WA(800).
    LOOP AT T_TAB into L_WA.
    ZDBTAB-DATALEN = STRLEN( L_WA ).
    MOVE: L_WA to ZDBTAB-RAWDATA.
    ZDBTAB-LINENUM = SY-TABIX.
    INSERT ZDBTAB.
    READING THE DATA FROM DB
    DATA: BEGIN OF T_DATA,
                 SEQNR type ZDBTAB-LINENUM,
                 DATA type ZDBTAB-RAWDATA,
               END OF T_TAB.
    Select the data.
    SELECT linenum rawdata from ZDBTAB into table T_DATA
         WHERE repid = w_repname
         AND rundate = w_rundate
         ORDER BY linenum.
    Populate calling Internal Table.
    LOOP AT T-DATA.
    APPEND T_DATA to T_TAB.
    ENDLOOP.

    Hi Anuj,
    The unicode flag is active.
    When I run our report and then to try and save the list data a dump is happening at the following point
    LOOP AT T_TAB into L_WA.
    As I say, T_TAB consists of different fields and field types whereas L_WA is CHAR 800. The dump mentions UC_OBJECTS_NOT_CONVERTIBLE
    When I try to load a saved list the dump is happening at the following point
    APPEND T_DATA-RAWDATA to T_TAB.
    T_DATA-RAWDATA is type LCHR and T_TAB consists of different fields and field types.
    In both examples the dumps mention UC_OBJECTS_NOT_CONVERTIBLE
    Regards
    C

  • Help required in Stored Pocedure

    I have a table as follows:
    -- INSERTING into TABLE1
    Insert into TABLE1 (ACCOUNT_ID,TRANSACTION_REFERENCE_NUMBER,TRANSACTION_TYPE,TRANSACTION_DATE_TIME,TRANSACTION_AMOUNT) values ('112011012045',16890657,'Deposit',to_timestamp('29-DEC-07 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),33000);
    Insert into TABLE1 (ACCOUNT_ID,TRANSACTION_REFERENCE_NUMBER,TRANSACTION_TYPE,TRANSACTION_DATE_TIME,TRANSACTION_AMOUNT) values ('112011012045',14500579,'Deposit',to_timestamp('31-DEC-07 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),49000);
    Insert into TABLE1 (ACCOUNT_ID,TRANSACTION_REFERENCE_NUMBER,TRANSACTION_TYPE,TRANSACTION_DATE_TIME,TRANSACTION_AMOUNT) values ('112011012045',14500577,'Deposit',to_timestamp('31-DEC-07 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),25000);
    Insert into TABLE1 (ACCOUNT_ID,TRANSACTION_REFERENCE_NUMBER,TRANSACTION_TYPE,TRANSACTION_DATE_TIME,TRANSACTION_AMOUNT) values ('112011012045',14500578,'Deposit',to_timestamp('31-DEC-07 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),48500);
    Insert into TABLE1 (ACCOUNT_ID,TRANSACTION_REFERENCE_NUMBER,TRANSACTION_TYPE,TRANSACTION_DATE_TIME,TRANSACTION_AMOUNT) values ('112011012045',6923202,'Deposit',to_timestamp('01-JAN-08 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),2500);
    Insert into TABLE1 (ACCOUNT_ID,TRANSACTION_REFERENCE_NUMBER,TRANSACTION_TYPE,TRANSACTION_DATE_TIME,TRANSACTION_AMOUNT) values ('112011012045',6923203,'Deposit',to_timestamp('01-JAN-08 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),2500);
    Insert into TABLE1 (ACCOUNT_ID,TRANSACTION_REFERENCE_NUMBER,TRANSACTION_TYPE,TRANSACTION_DATE_TIME,TRANSACTION_AMOUNT) values ('112011012045',6923204,'Deposit',to_timestamp('01-JAN-08 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),3000);
    Insert into TABLE1 (ACCOUNT_ID,TRANSACTION_REFERENCE_NUMBER,TRANSACTION_TYPE,TRANSACTION_DATE_TIME,TRANSACTION_AMOUNT) values ('112011012045',6923205,'Deposit',to_timestamp('01-JAN-08 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),3000);
    Insert into TABLE1 (ACCOUNT_ID,TRANSACTION_REFERENCE_NUMBER,TRANSACTION_TYPE,TRANSACTION_DATE_TIME,TRANSACTION_AMOUNT) values ('112011012045',6923206,'Deposit',to_timestamp('01-JAN-08 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),5000);
    Insert into TABLE1 (ACCOUNT_ID,TRANSACTION_REFERENCE_NUMBER,TRANSACTION_TYPE,TRANSACTION_DATE_TIME,TRANSACTION_AMOUNT) values ('112011012045',6923207,'Deposit',to_timestamp('01-JAN-08 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),15500);
    Insert into TABLE1 (ACCOUNT_ID,TRANSACTION_REFERENCE_NUMBER,TRANSACTION_TYPE,TRANSACTION_DATE_TIME,TRANSACTION_AMOUNT) values ('112011012045',6923208,'Deposit',to_timestamp('01-JAN-08 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),18734);
    Insert into TABLE1 (ACCOUNT_ID,TRANSACTION_REFERENCE_NUMBER,TRANSACTION_TYPE,TRANSACTION_DATE_TIME,TRANSACTION_AMOUNT) values ('112011012045',6923209,'Withdrawal',to_timestamp('01-JAN-08 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),80646.75);
    Insert into TABLE1 (ACCOUNT_ID,TRANSACTION_REFERENCE_NUMBER,TRANSACTION_TYPE,TRANSACTION_DATE_TIME,TRANSACTION_AMOUNT) values ('112011012045',6923210,'Withdrawal',to_timestamp('01-JAN-08 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),87314);
    Insert into TABLE1 (ACCOUNT_ID,TRANSACTION_REFERENCE_NUMBER,TRANSACTION_TYPE,TRANSACTION_DATE_TIME,TRANSACTION_AMOUNT) values ('112011012045',7163769,'Withdrawal',to_timestamp('02-JAN-08 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),31875);
    Insert into TABLE1 (ACCOUNT_ID,TRANSACTION_REFERENCE_NUMBER,TRANSACTION_TYPE,TRANSACTION_DATE_TIME,TRANSACTION_AMOUNT) values ('112011012045',7163770,'Withdrawal',to_timestamp('02-JAN-08 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),33878);
    Insert into TABLE1 (ACCOUNT_ID,TRANSACTION_REFERENCE_NUMBER,TRANSACTION_TYPE,TRANSACTION_DATE_TIME,TRANSACTION_AMOUNT) values ('112011012045',7532700,'Deposit',to_timestamp('04-JAN-08 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),20000);
    Insert into TABLE1 (ACCOUNT_ID,TRANSACTION_REFERENCE_NUMBER,TRANSACTION_TYPE,TRANSACTION_DATE_TIME,TRANSACTION_AMOUNT) values ('112011012045',7532701,'Withdrawal',to_timestamp('04-JAN-08 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),9140);
    Insert into TABLE1 (ACCOUNT_ID,TRANSACTION_REFERENCE_NUMBER,TRANSACTION_TYPE,TRANSACTION_DATE_TIME,TRANSACTION_AMOUNT) values ('112011012045',7845450,'Deposit',to_timestamp('05-JAN-08 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),2550);
    Insert into TABLE1 (ACCOUNT_ID,TRANSACTION_REFERENCE_NUMBER,TRANSACTION_TYPE,TRANSACTION_DATE_TIME,TRANSACTION_AMOUNT) values ('112011012045',7845451,'Deposit',to_timestamp('05-JAN-08 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),15000);
    Insert into TABLE1 (ACCOUNT_ID,TRANSACTION_REFERENCE_NUMBER,TRANSACTION_TYPE,TRANSACTION_DATE_TIME,TRANSACTION_AMOUNT) values ('112011012045',7845452,'Withdrawal',to_timestamp('05-JAN-08 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),11966);
    Insert into TABLE1 (ACCOUNT_ID,TRANSACTION_REFERENCE_NUMBER,TRANSACTION_TYPE,TRANSACTION_DATE_TIME,TRANSACTION_AMOUNT) values ('112011012045',7845453,'Withdrawal',to_timestamp('05-JAN-08 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),20564);
    Insert into TABLE1 (ACCOUNT_ID,TRANSACTION_REFERENCE_NUMBER,TRANSACTION_TYPE,TRANSACTION_DATE_TIME,TRANSACTION_AMOUNT) values ('112011012045',8308095,'Deposit',to_timestamp('07-JAN-08 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),9000);I want a stored procedure which will give me the values for the past 7 days transactions, for each transaction.. as comma seperated values... I want this for each transaction in the table.
    i.e., if i take the reference number, 6923202 ,
    Deposit txns for past 7 days including the current txn will be - 26Dec, 27Dec, 28Dec, 29Dec, 30Dec, 31Dec, 1Jan
    So the values will be                -0,0,0,1,0,3,1
    Similarly Amounts will be            -0,0,0,33000,0,122500,2500
    Now if i take the next reference number, 6923203
    Deposit txns for past 7 days including the current txn will be - 26Dec, 27Dec, 28Dec, 29Dec, 30Dec, 31Dec, 1Jan
    So the values will be                -0,0,0,1,0,3,2
    Similarly Amounts will be            -0,0,0,33000,0,122500,5000
    Now if i take the next reference number, 7532700
    Deposit txns for past 7 days including the current txn will be - 29Dec, 30Dec, 31Dec, 1Jan, 2Jan, 3Jan, 4Jan
    So the values will be                -1,0,3,7,0,0,1
    Similarly Amounts will be            -33000,0,122500,50234,0,0,20000
    Note that i am considering only Deposit txns..I want similar to be done for withdrawal txns also..I want to insert into Table2 values like this:
    Insert into Table2 (Account_id, Transaction_reference_number, Deposit_Count, Deposit_Amount) values ('112011012045',6923202,'0,0,0,1,0,3,1','0,0,0,33000,0,122500,2500');
    Insert into Table2 (Account_id, Transaction_reference_number, Deposit_Count, Deposit_Amount) values ('112011012045',6923203,'0,0,0,1,0,3,2','0,0,0,33000,0,122500,5000');
    Insert into Table2 (Account_id, Transaction_reference_number, Deposit_Count, Deposit_Amount) values ('112011012045',7532700,'1,0,3,7,0,0,1','33000,0,122500,50234,0,0,20000');
    At that point of transaction, what are the last 7 days transactions need to be inserted..I want this to be calculated for each Account_id in Table1..right now, this sample data is having only one Account_id..If it has many account_ids, then for each transaction of each account_id, i want data to be inserted into Table2 as the way shown in example..
    Can anybody help me in writing stored procedure for this..Please...

    Well here's a query that will do the necessary hard work, you just need to incorporate that for yourself in a procedure or whatever you want to do with it...
    SQL> select * from table1;
    ACCOUNT_ID           TRANSACTION_REFERENCE_NUMBER TRANSACTION_TYPE
    TRANSACTION_DATE_TIME                                                       TRANSACTION_AMOUNT
    112011012045                             16890657 Deposit
    29-DEC-07 00.00.00.000000                                                                33000
    112011012045                             14500579 Deposit
    31-DEC-07 00.00.00.000000                                                                49000
    112011012045                             14500577 Deposit
    31-DEC-07 00.00.00.000000                                                                25000
    112011012045                             14500578 Deposit
    31-DEC-07 00.00.00.000000                                                                48500
    112011012045                              6923202 Deposit
    01-JAN-08 00.00.00.000000                                                                 2500
    112011012045                              6923203 Deposit
    01-JAN-08 00.00.00.000000                                                                 2500
    112011012045                              6923204 Deposit
    01-JAN-08 00.00.00.000000                                                                 3000
    112011012045                              6923205 Deposit
    01-JAN-08 00.00.00.000000                                                                 3000
    112011012045                              6923206 Deposit
    01-JAN-08 00.00.00.000000                                                                 5000
    112011012045                              6923207 Deposit
    01-JAN-08 00.00.00.000000                                                                15500
    112011012045                              6923208 Deposit
    01-JAN-08 00.00.00.000000                                                                18734
    112011012045                              6923209 Withdrawal
    01-JAN-08 00.00.00.000000                                                             80646.75
    112011012045                              6923210 Withdrawal
    01-JAN-08 00.00.00.000000                                                                87314
    112011012045                              7163769 Withdrawal
    02-JAN-08 00.00.00.000000                                                                31875
    112011012045                              7163770 Withdrawal
    02-JAN-08 00.00.00.000000                                                                33878
    112011012045                              7532700 Deposit
    04-JAN-08 00.00.00.000000                                                                20000
    112011012045                              7532701 Withdrawal
    04-JAN-08 00.00.00.000000                                                                 9140
    112011012045                              7845450 Deposit
    05-JAN-08 00.00.00.000000                                                                 2550
    112011012045                              7845451 Deposit
    05-JAN-08 00.00.00.000000                                                                15000
    112011012045                              7845452 Withdrawal
    05-JAN-08 00.00.00.000000                                                                11966
    112011012045                              7845453 Withdrawal
    05-JAN-08 00.00.00.000000                                                                20564
    112011012045                              8308095 Deposit
    07-JAN-08 00.00.00.000000                                                                 9000
    22 rows selected.
    SQL> with rn as (select 6923202 as rn from dual)
      2      ,p7 as (select cast(transaction_date_time as DATE) - (rownum-1) dt
      3              from (select * from table1, rn where transaction_reference_number = rn.rn)
      4                   ,rn
      5              connect by rownum <= 7)
      6  --
      7  select dt
      8        ,ltrim(sys_connect_by_path(cnt,','),',') as cnt
      9        ,ltrim(sys_connect_by_path(nvl(sm,0),','),',') as sm
    10  from (
    11    select p7.dt, sum(decode(transaction_amount,null,0,1)) cnt, sum(transaction_amount) sm
    12    from p7 left outer join table1 on (trunc(cast(table1.transaction_date_time as date)) = p7.dt AND table1.transaction_type = 'Deposit')
    13    group by p7.dt
    14    )
    15  where connect_by_isleaf = 1
    16  connect by dt = prior dt + 1
    17  start with dt = (select min(dt) from p7)
    18  order by dt
    19  /
    DT        CNT                            SM
    01-JAN-08 0,0,0,1,0,3,7                  0,0,0,33000,0,122500,50234
    SQL>

  • Need help for writing extract program

    hi
    i need help for writing extract program to retriew data from legacy system.
    i already developed bdc programs for me31k and me21.
    my requirement is to write extract program s for those t.codes.
    to retriew data from legacy system and stored in flat file.

    i need help with a java program. it is a program that allows the user to enter a student's GPA, number of extracurricular activities, and number of service activities. The user can not enter a gpa above 4.0 or below 0. The user can not enter a negative number for the number of both activities. If the student meets the following criteria: 1) GPA of 3.8 or above and at least one extracurricular activity and one service activity, 2) GPA below 3.8 but at least 3.4 and a total of at least three extracurricular and service activities, 3) GPA below 3.4 but at least 3.0 and at least two extracurricular activities and three service activities, the message "Scholarship candidate" should display. If the student does not meet the criteria above, then the message"not a candidate" should display. Can you help me, please?
    You haven't posted ANY 'java program' for us to help with.
    The forum is NOT a coding service. It is to help you with YOUR code.
    Post the code you have written and SHOW us (don't just tell us) how you compile it and execute it and the results you get. Then we can help you with any problems you are are having.
    If you need help understanding just what the program should be doing you need to ask your instructor to clarify the assignment.

  • Writing stored procedures.--PLSQL

    Hello,
    Need help in learning and writing stored procedures.
    Scenario is :-
    Tabes:-
    Employee --&gt;
    * Fields are (empl_id,fname,lname,employee_status)*
    * values ( 1,P,M,A)*
    * (2,JK,KK,A)*
    * (3,lk,kj,a)*
    Project-&gt;
    *(Project_id,Projname,duration)*
    * 1 CLEANING*
    * 2 driving*
    Project and Employee---RELATIONSHIP ---&gt; proj_id and employee_id
    Employee_project_reltn
    *(project_id,employee_id,created_dt,duration,status)*
    1 1
    1 3
    2 3
    {color:#0000ff}_An employee can work in multiple projects(1-MANY) at a time. _{color}
    Question:- Please help me with the PROCEDURE for getting all EMPLOYEE details of a PROJECT.
    That means, ----&gt;Input is PROJECT_ID as 1 ----RESULT is employee details of employee no 1 and 3 + Project details fully
    {color:#0000ff}*(1)I don know how to return the entire result set filled with data.Please help me writing the correct full procedure.*{color}
    {color:#0000ff}*(2)Also, a Procedure to add an employee to a project.Inputs are employee_id,project_id*{color}

    Hi,
    If the table Employee_project_reltn has correct foreign keys defined you can attemp to do the insert and if a integrity constrain is violated (ORA-02291) then the exception invalid_employee_or_project is raised.
    As a starting point:
    CREATE OR REPLACE PROCEDURE proc_add_employee_to_project(p_employee_id IN Employee_project_reltn.employee_id%TYPE,
                                                             p_project_id  IN Employee_project_reltn.project_id%TYPE,
                                                             p_message     OUT VARCHAR2) IS
       invalid_employee_or_project EXCEPTION;
       PRAGMA EXCEPTION_INIT(invalid_employee_or_project,
                             -2291);
    BEGIN
       p_message := 'Succesful';
       -- Your insert
       -- commit;
    EXCEPTION
       WHEN invalid_employee_or_project THEN
          p_message := 'invalid_employee_or_project';
          ROLLBACK;
       WHEN OTHERS THEN
          p_message := SQLERRM;
          ROLLBACK;
    END proc_add_employee_to_project;
    /Regards,

  • Need Help in writing a UDF

    Hi,
    Please help in writing a UDF for these fields in mapping, which I need for the object Iu2019m doing currently.
    The fields are like this:
    1)         batch_no = "TRUNC((GetMaxObjid('x_txn_sap_parts')-POWER(2,28))/5000)+1",
    2)         lot_id = "TRUNC((GetMaxObjid('x_txn_sap_parts')-POWER(2,28))/500)+1",
    3)        How to use JDBC connection factory class in the UDF.
    Some logic I can provide which I know i.e. Power (2, 28) means 2 to the power of 28 (2 multiplied 28 times), Trunc means truncate, X_TXN_SAP_Parts is a database table.The Target fields are Batch_no, lot_id & Objid.Actually, objid is mapped initially to a source field i.e. Object ID and in this function it is only being used for the calculation of the batch_no.
    Thanks in Advance,
    Sreedhar.

    Hi,
    Following with my query I've tried to use this code but still I'm unable to execute the mapping.
    import java.util.*;
    import com.sap.aii.mapping.lookup.*;
    import com.sap.aii.mapping.lookup.*;
    DataBaseAccessor accessor = null;
    DataBaseResult JDBCOutPayload = null;
    String BusinessSystem="clarify_dev_bizsys";
    //give your business system having channel name
    String CommunicationChannel="JDBC_TO_CDEV";
    //give your channel name
    String InputPayload= " select X_TXN_PRE_SITE_XFACE.nextval from dual;";
    //give your sql query
    try {
    Channel channel =
    LookupService.getChannel(BusinessSystem,CommunicationChannel);
    accessor = LookupService.getDataBaseAccessor(channel);     
    DataBaseResult resultSet = accessor.execute(InputPayload);
         for(Iterator rows = resultSet.getRows();rows.hasNext();){  
         Map rowMap = (Map)rows.next();
         Object cValue = rowMap.get("batchno");
    //field name of field required , as in database
          catch (Exception e) {}
          finally {
                  if (accessor != null)
                  accessor.close();
           result.addValue((String)cValue);
    --> I don't know what are the parameters to be used and how to be used in the UDF because this is the first time I'm writing a UDF.
    --> The problem in using this query is that both OBJID & BatchNo. are on the target side and the value for the OBJID is retrieved by a SELECT query from the database.
    Kindly help me how to resolve this query of mine.
    Thanks in Advance.
    Sreedhar.

  • Need help in writing data from JSP to excel

    Hi ,
    I need help in writing the data from JSP to excel.I somehow able to retrieve the data into excel but unable to get the required format.
    For eg: The amount should be displayed in 0.00 format .when i am exporting it to excel it is displaying as 0 :( .
    I am using the following code in JSP.
    "out.print(amt + '\t');"
    Would like to know if there is any otherway where in i can get my requirement.
    Thanks
    Tom

    Hi,
    Try using format part of the JSTL tag libs.
    Syntax :
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    <fmt:formatNumber value="40" pattern="$#,##0.00"/>
    I need help in writing the data from JSP to excel.I
    somehow able to retrieve the data into excelHow do u convert the jsp to excel?
    One way to convert the jsp page to excel, is to render it as an excel appl instead of html. Set the content type of the response to application/ms-excel.
    response.setContentType("application/ms-excel")Hope this Helps....

  • Help in writing a query!

    Dear All,
    My database is 11gR2 on Linux.
    I am struck in writing a difficult query, need help from your guys.
    I have a table, an application is controlling the columns of this table. Columns are added by the application.
    This is the structure of the table:
    create table imran_test(
    2 username varchar2(100),
    3 layer1 number(1),
    4 layer2 number(2),
    5 layer3 number(2));
    -- where layer1, layer2, layer3.... are increased up to layer 22 and could be increased more...
    Now each username will have 1 in any one of the layer, and all other layers will have 0
    Like if I consider the above table this could be the sample data:
    imran 1 0 0
    hafeez 0 1 0
    james 0 0 1
    Now the result my query should return is:
    select username, <column name where value is 1> and value of it, as per sample data, this should be return by the query:
    imran layer1 1
    hafeez layer2 1
    james layer 3 1
    Note: Please remember the columns are not fixed, they are added/altered by application.
    Regards,
    Imran

    The table design is incorrect as it is not in 3NF and has a repeating group
    You should correct the 'design' first or turn the layer... columns in a VARRAY.
    Also my feeling is you should change your subject line 'Help in writing a query!' in 'Write my query' as that is what you actually ask, and leave out the exclamation mark.
    Basically you dump everything in this forum, and being a bit less demanding might suit you better.
    Also you still act rude by not marking your questions as answered.
    Change that
    Sybrand Bakker
    Senior Oracle DBA
    Edited by: sybrand_b on 1-apr-2012 12:09

  • Help with writing a formula

    Hi all,
    I am creating a report, and need help with writing a formula...
    I am creating a report that shows how many visits/touches our reps have made to various grade accounts. It is broken down by calendar week, and I currently have a weekly "goal" number set that the reps have to meet. That "goal" number increases each week to keep a running total. (example: week 1: 7, week 2: 14, week 3: 21)
    I have created some different formulas and one is this:
    SUM("Activity Metrics"."# of Activities" BY Date."Calendar Week")
    What this shows me is how many "visits" there are per calendar week to customers, however it show me the total for all reps per week.
    What I need is that total to show, but totaled for each rep individually.
    What I was trying is this:
    SUM("Activity Metrics"."# of Activities" BY Date."Calendar Week") BY Employee."Employee Name"
    But...I keep getting an error.
    Any suggestions?
    I have the reporting book by Lairson, and have been referring to it...but my brain at this point is fried.
    Thanks in advance for any help...(please forgive...I am new to OnDemand, and I am sure this is easy)

    Thanks for helping!
    I created this formula as a column: SUM ("Activity Metrics"."# of Activities" BY Date."Calendar Week"), it is called "total number of visits per week" and it shows the totaled number of visits that all the reps have done per calendar week. For example: Week 1: 10 visits, Week 2: 37 visits, Week 3: 20 visits.
    What I would like to do is take that column and break it down further, to show instead how many visits per week by sales rep there have been
    So what I was trying was to take the "total number of visits per week" (SUM ("Activity Metrics"."# of Activities" BY Date."Calendar Week")) and use "Activity Owner" (Employee."Employee Name") to break it down further.
    What I need to use is the total number of visits each rep has per calendar week.
    I think I am getting the error because you can't use "BY" twice in a formula?

  • Help with writing a batch file

    Hi :
    does anyone know anyplace online that I can get help in writing batch files?? I have never worked much with batch files before....
    any help is greatly appreciated
    thnx

    I suppose, since you're in a Java forum, you need batch files to load java applications.
    If you use windows :
    go to ms console (start/run/"cmd")
    type edit mybatch.bat
    write your command to load a java application, something like
    java myclass.class
    save and exit.
    Be sure the bat file and the class are in the same folder.
    And make certain you've set the classpath, and path variables correctly.
    If this was what you needed and you need more help just ask.
    (In this case it could be better to make executable jars)
    If you wanted to know about linux batches, it works pretty the same way.

  • Help in Writing XSLT

    Hello guys,
    I need help in writing XSLT.I have a XML structure as below.
    <PushEventResult>
         <pushEventDT>
              <id>XX</id>
              <serialNumber>111</serialNumber>
              <Mpxn>1X1</Mpxn>
              <EventData>
                   <alarmDtime>xxx</alarmDtime>
                   <alarmType>UP</alarmType>
                   <additionalData>dummy</additionalData>
              </EventData>
              <EventData>
                   <alarmDtime>xxx</alarmDtime>
                   <alarmType>DOWN</alarmType>
                   <additionalData>dummy</additionalData>
              </EventData>
         </pushEventDT>
    </PushEventResult>
    With XSLT I need to transform it in to this format.
    <PushEventResult>
         <pushEventDT>
              <id>XX</id>
              <serialNumber>111</serialNumber>
              <Mpxn>1X1</Mpxn>
              <EventData>
                   <alarmDtime>xxx</alarmDtime>
                   <alarmType>UP</alarmType>
                   <additionalData>dummy</additionalData>
              </EventData>
              </pushEventDT>
         <pushEventDT>
              <id>XX</id>
              <serialNumber>111</serialNumber>
              <Mpxn>1X1</Mpxn>
              <EventData>
                   <alarmDtime>xxx</alarmDtime>
                   <alarmType>DOWN</alarmType>
                   <additionalData>dummy</additionalData>
              </EventData>
         </pushEventDT>
    </PushEventResult>

    A possible attempt will be this set of templates.
    <xsl:template match="PushEventResult">
        <xsl:copy>
            <xsl:apply-templates select="pushEventDT" />
        </xsl:copy>
    </xsl:template>
    <xsl:template match="pushEventDT">
        <xsl:for-each select="EventData">
            <pushEventDT>
                <xsl:call-template name="const_struct" />
                <xsl:copy-of select="." />
            </pushEventDT>
        </xsl:for-each>
    </xsl:template>
    <xsl:template name="const_struct">
        <xsl:apply-templates select="preceding-sibling::*[not(name()='EventData')]" mode="const" />
    </xsl:template>
    <xsl:template match="*" mode="const">
        <xsl:copy-of select="." />
    </xsl:template>

  • Need helping in writing query for finding percentage of duration

    Can any one please help in writing query for this.
    The table is like this :-
    ID     Region     Month     Duration
    I1 R1     Jan     80
    I2     R2     Jan     70
    I3     R1     Jan     70
    I4     R3     Jan     40
    I5     R1     Feb     80
    I6     R2     Feb     30
    I7     R3     Mar     100
    I want to write a query to find
    % of duration for each and every region against each and every month.
    Please help in solving this query. I am in urgent need of this.
    Thanks in advance.

    I also have to do in MS Access 2003You also have to ask into an other forum since here it's an Oracle forum, to try to find Oracle solution.
    Nicolas.

  • Help with writing .bashrc file

    I would like help with writing a .bashrc file.
    The only thing I want right now is colored output and slashes for directories like what "ls -GF" does -- for each new terminal window.
    Can you guys give me a hand?
    Running Mac OS 10.4.6. Bash is default shell.
    Thanks.

    Hi Paul,
       You can get Apple's "ls" command to always output color with the following in your .bashrc:
    export CLICOLOR=""
    You can have an effect on the colors used with settings like the following:
    export LSCOLORS="gxfxcxdxbxegedabafacad"
       I have a color prompt in my bash startup scripts, bashrc.tgz. If you unpack the tarball in the root of your home directory, the files will be put in a ~/Library/init/bash directory. The file named "prompt" sets the color prompt string.
    Gary
    ~~~~
       I know you think you thought you knew what you
       thought I said, but I'm not sure you understood what
       you thought I meant.

Maybe you are looking for

  • Text input popup

    I am writing a simple RSS reader app in Flex (for AIR). I have a "change feed" button in my app. I want this to launch a popup with text input, to take the URL as a string and return it to my main app. This seems like something that should be incredi

  • Is there an easy way to call a java class from an applet?

    Does anyone know of an easy way to call a server based java class from an applet? Has anyone done it or came across it? If yes how/where? Cheers, Chris.

  • MacBook Pro 13" Late 2011 Internal Speakers Issue

    Every time I use my internal speakers (especially on high voice), my speakers' strength seems to lessen after few seconds of sound. But after about 30 minutes or so, the speakers are back to normal, but the same conflict repeats again after using the

  • Automatic payment run F110

    Dear SAP GURU, When i Run F110 with selection all parameter , that time sys given the error , -Payment proposal could not be carried out In detail description Overlap with payment run 15.01.2009 OTV01 Message no. FZ358 Diagnosis Accounts to be proces

  • Compare dreamweaver 8 and MX 2004

    I am trying to sign up for an online course and they are asking me to have MX 2004, but they won't tell me if DW8 will work for the class instead. Are there extreme differences?