Help required in stored procedure?????

Hi,
I need to write a procedure in which a query is executed.I get a coulmn name as tel_no.it returns 75 telephone numbers.I need to return those numbers from procedure which follows below Criteria:
Select those numbers which have last 4 digits matching i,e last 3 digits are 444 or 333 or 999 etc.
if this criteria isnot met i need to choose whose send last 3 digits are matching i.e, last 4 digits like 3334 or 7775 or 1117 etc....Please do help..its very urgent.
the procedure takes 2 input...area_code and request_no.....
u may refer query as :
select area_name,tel_no, code from xyz where request_id=? and area_code=?
Please do tell me how will i do it...please......i will be thankful to u...
U may mail ur solution on [email protected]
Regards,
Megha Verma....

Megha Verma wrote:
Hi,
I need to write a procedure in which a query is executed.I get a coulmn name as tel_no.it returns 75 telephone numbers.I need to return those numbers from procedure which follows below Criteria:
Select those numbers which have last 4 digits matching i,e last 3 digits are 444 or 333 or 999 etc.
if this criteria isnot met i need to choose whose send last 3 digits are matching i.e, last 4 digits like 3334 or 7775 or 1117 etc....Please do help..its very urgent.
the procedure takes 2 input...area_code and request_no.....
u may refer query as :
select area_name,tel_no, code from xyz where request_id=? and area_code=?What have you tried yourself so far?
If you want help, please provide your database version, some create table scripts and insert statements with example data, show what output is expected and detail any relevant business logic. And remember to include any code or data between {noformat}{noformat} tags (that's the word "code" between two curly brackets both before and after any text that need to retain it's formatting on the forum)
Please do tell me how will i do it...please......i will be thankful to u...
U may mail ur solution on [email protected].
Answers will be provided on the forum, not via email.  That is the purpose of the forum as it's not a personal help desk.
Also, you may want to consider that this is a professional forum, so using IM speak ("u", "ur" etc.) is considered poor practice.  Please use proper words.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • 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 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!!!!

  • Help needed in stored procedures

    Hi,
    I wrote a stored procedure when i execute it. i get the error
    ORA-00942: table or view does not exist
    ORA-06512: at "SANDEEP.PROC_INS_TEMP_NAC_GL", line 18
    ORA-06512: at line 9
    I was unable to resolve this error please help.
    CREATE OR REPLACE PROCEDURE PROC_INS_TEMP_NAC_GL(
    p_bu IN STRING,
    p_period IN STRING
    IS
    sql_stmt varchar2(1000);
    cnt number;
    BEGIN
         SELECT count(view_name) INTO cnt FROM sys.all_views where view_name = UPPER(p_bu||'_v_ldga') and owner = 'SUN';
         sql_stmt := 'INSERT INTO temp_nac_gl'||
         ' SELECT ''' || p_bu ||'''BU, gl.ACCNT_CODE , gl.ANAL_T0 , gl.ANAL_T1 , gl.PERIOD , gl.MEMO_AMT , gl.AMOUNT , gl.REGION, gl.ANAL_T3'||
                   ' FROM sun.'|| p_bu ||'_v_ldga gl, temp_acnt_grp acnt' ||
                   ' WHERE gl.accnt_code = acnt.acnt_code ' ||
                   ' AND acnt.bu = '''|| p_bu ||'''' ||
                   ' AND gl.period <= '''|| p_period || '''' ||
                   ' ORDER BY gl.REGION';
    EXECUTE IMMEDIATE sql_stmt;
    END;
    /

    If you are accessing a object from a Oracle procedure/function then you need direct rights and not through roles.
    You can check this by executing a SELECT from SQL plus , if you are able to see the table then type the following commond
    SQL> set role none;
    SQL> SELECT statement
    If it gives an error then you dont have direct rights.
    Thanks
    Edited by: Himanshu Kandpal on May 14, 2009 5:04 PM

  • 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>

  • Help in JAVA stored procedure

    Hi,
    We need to interface a JAVA application from a pl/sql block. We are using JAVA stored procedure to do the same. This
    stored java class ( that we call from a PL/SQL procedure) has the
    statement ( " textFont = new Font("Arial", 0, 11)" ) where a Font is
    initialized. This is throwing an error message as given below. Please
    let us know if there is any issue with respect to usage of java.awt
    classes in java stored procedures (Oracle JVM of Oracle9i Enterprise
    Edition Release 9.2.0.2.0).
    We tracked down the exception to the following stack trace:
    java.lang.NullPointerException
    at java.lang.Class.forName0(Class.java)
    at java.lang.Class.forName(Class.java)
    at
    java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnviron
    ment.java)
    at java.awt.Font.initializeFont(Font.java)
    at java.awt.Font.<init>(Font.java)
    at com.idautomation.pdf417.PDF417.<init>(com/idautomation/pdf417/PDF417)
    at GenBarCode.createBarCode(GenBarCode.java:24)
    at CallGenBarCode.callGenerateBarCode(CallGenBarCode.java:14)
    g_error_text= ORA-29532: Java call terminated by uncaught Java
    exception: java.lang.NullPointerException in CallGenBarCode_callGBC
    DECLARE
    ERROR at line 1:
    ORA-20001: ORA-29532: Java call terminated by uncaught Java exception:
    java.lang.NullPointerException in CallGenBarCode_callGBC err 15
    ORA-06512: at line 12
    Any pointers in this regard will be of great help.
    thanks,
    Ayyappa

    Hi,
    OracleJVM, as a server-side VM, does not support any UI classes such as awt and swing. The basic GUI components found in the JDK's Abstract Windowing Toolkit (AWT) cannot be used in Stored procedures.
    For more information refer to http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/java.920/a96659/01_intro.htm#16826
    Hope this helps.
    Sujatha.
    http://otn.oracle.com/sample_code/content.html

  • HELP!! Stored Procedures - Adding and Inserting Records

    Can ANYONE tell what I'm doing wrong? I'm learning PL/SQL, and I don't know what I'm missing here.
    For starters, I'm trying to write a stored procedure to:
    -- insert data into a NULL column added using ALTER TABLE
    -- there's about +/- 45 records where this data needes to be added.
    -- the value for each null field in the column is a random value (that is, generated using dbms_random.random
    I've tried several ways to write the procedure, but have run against a wall to determine what I'm missing.
    Here's the SQL statements and the error messages:
    SQL> CREATE OR REPLACE PROCEDURE update_proj_number (p_proj4_id IN VARCHAR2)
    2 AS
    3 BEGIN
    4 DECLARE
    5 v_counter NUMBER(5) := 0;
    6 END;
    7 BEGIN
    8 v_counter := 0;
    9 dbms.random.initialize(32768);
    10 v_counter := v_counter + 1;
    11 p_proj4_id := dbms.random.random
    12 UPDATE sample_trades
    13 SET proj4_id = RANDOM(p_proj4_id);
    14 exit when NOTFOUND%;
    15 END;
    16 /
    Warning: Procedure created with compilation errors.
    SQL>
    SQL> SHOW ERRORS
    Errors for PROCEDURE UPDATE_PROJ_NUMBER:
    LINE/COL ERROR
    6/2 PLS-00103: Encountered the symbol "END" when expecting one of the following:
    begin function package pragma procedure subtype type use <an identifier>
    <a double-quoted delimited-identifier> cursor form current
    12/3 PLS-00103: Encountered the symbol "UPDATE" when expecting one of the following:
    . ( * @ % & = - + ; < / > in mod not rem an exponent (**)
    <> or != or ~= >= <= <> and or like between is null is not &#0124; &#0124; is dangling
    The symbol ";" was substituted for "UPDATE" to continue.
    14/22 PLS-00103: Encountered the symbol ";" when expecting one of the following:
    ( type <an identifier> <a double-quoted delimited-identifier>
    SQL>
    Would it be more efficient to use a cursor to fetch the rows containing the null value or is a stored procedure OK for this?
    Also, I would like to have a second example of a stored procedure that will add random rows to a table (that is, create duplicates of information already in the table). This stored procedure will also use dbms_random.
    For example,
    IF p_value1 = 'FIRST_VALUE' then
    add this record (incl. random_val for key);
    ELSIF p_value = 'SECOND_VALUE' then
    add that record (incl. random_val for key);
    and on and on.
    Much thanks to anyone who can help.
    For example,
    null

    Try this
    CREATE OR REPLACE PROCEDURE update_proj_number (p_proj4_id IN VARCHAR2)
    AS
    v_counter NUMBER(5) := 0;
    BEGIN
    v_counter := 0;
    dbms.random.initialize(32768);
    v_counter := v_counter + 1;
    p_proj4_id := dbms.random.random ;
    UPDATE sample_trades
    SET proj4_id = RANDOM(p_proj4_id);
    END;
    /

  • Help: using a stored procedure to insert a record in DB

    A stored procedure:
    PROCEDURE db_insert
    db_block IN OUT plsql_table)
    is created in DB.
    db_select and db_update are created too. They both work fine as
    db_select is called by go_block execute_query (block populated) and
    db_update is called by commit (DB updated);
    I am trying to have db_insert called as:
    1. DO_KEY('Create_Record');
    2. fill in fields and then
    3. commit.
    These 3 steps do not cause the call of the auto generated block trigger insert_procedure. I think that after filling in the fields and there should be a way to call this insert_procedure trigger. I am not sure how this will work.
    Any suggestions are greatly appreciated.

    I went through quite a deep search and yet not found any good answers. Knowing that select and update all done well with execute_query(stored procedure is called) and commit(stored procedure is called), but not insert.
    Logically there must be some FORM build in that will trigger the call of stored procedure insert.
    I am still looking for answers and just to remind that there are quite number of similar posts and I do not think that any clear answers were delivered.
    Please help.

  • Help creating a stored procedure

    I have a query that is going to run many, many times per day, potentially hundreds of thousands so I want to make sure it's as quick as possible
    The purpose is to take a compiled IP number, look it up and relate it back to the country based on data in the table for current IP/countries
    There are currently 113,536 records in the country table, It's typically taking around 4ms to 5ms, so it's not exactly slow, but as the use of this particular lookup is going to increase significantly I'd like to make sure I have it as fast as possible.
    Here's the current code:
    <CFSET ipnumber = (#listgetat(remote_addr,1,'.')# *256*256*256) +  (#listgetat(remote_addr,2,'.')# *256*256) + (#listgetat(remote_addr,3,'.')#  *256) + #listgetat(remote_addr,4,'.')#>
    <CFQUERY name="GetCountry" DATASOURCE="#datasource#">
        SELECT TOP 1(countryshort) as countryshort
        FROM #ipcountry#
        WHERE ipfrom <= #ipnumber# and ipto >= #ipnumber#
    </CFQUERY>
    The first thought is to try to create a stored proc to see if that generates any performance gain, I've search and read over several documents on setting one up, but I have to admit, I just can't quite grasp it.
    I'm wondering if anybody would be kind enough to stick this query into a stored proc for me and let me know what CF code I need to execute it and read the result.
    Once I see this done I am sure I'll be able to push forward from there on my own in the future
    Thanks
    Mark

    JR \"Bob\" Dobbs wrote:
    Bear in mind that database servers, such as Microsoft SQL Server, will cache the execution plan for parameterized SQL queries which will result in performance gains similar to use of a stored procedure. 
    You might try using CFQUERYPARAM in your queries.  This is also recommended to help prevent SQL injection attacks.
    You might also create indexes on the ipfrom column on your table.
    Agreed. Just wrapping a query in a stored procedures does not mean it is going to run faster. Look at the table's indexes and examine the execution plan to see how it can be improved. And you really should be using cfqueryparam in all of your queries. Not just for performance, but because you are risking sql injection attacks without it.
    HiTopp wrote
    EXEC sp_executesql @sql,
    Since the table name is hard coded, there really is not a need for dynamic sql in this query.
    Message was edited by: -==cfSearching==-

  • Please help convert MSSQL Stored Procedure to Oracle PL/SQL

    Hi there to all,
    this be my first post to these forums. I have already posted this question on a microsoft msdn forum, until someone advised that I ask my question here - dunno why I didnt think of that! ?:|
    Im working with an Oracle 10g Database from an ASP.NET 2.0 application, and want to know if it Oracle supports OPENXML (rhetorical question I fear!). The reason I ask is because I want to create an Oracle Stored Procedure that will accept an XML string as an input parameter, prepare it, select from it, and then insert it into an Oracle table.
    I have done this successfully in SQL server using the following as an example:
    CREATE PROCEDURE [dbo].[Employee_INSERT]
    bq. @INSERTRECORD XML
    AS
    BEGIN
    bq. DECLARE @XDOC INT; \\ EXEC sp_xml_preparedocument @XDOC OUTPUT, @INSERTRECORD; \\ INSERT INTO [dbo].[REC_Employees] (
    bq. bq. [EMPTITLE], \\ [EMPFNAME], \\ [EMPLNAME], \\ [EMPDEPTID], \\ [EMPBEGINDATE], \\ [EMPACTIVE], \\ [EMPDATEADDED]
    bq. )
    bq. SELECT
    bq. bq. [EMPTITLE] = Title, \\ [EMPFNAME] = Firstname, \\ [EMPLNAME] = LastName, \\ [EMPDEPTID] = DepartmentID, \\ [EMPBEGINDATE] = StartDate, \\ [EMPACTIVE] = IsActive, \\ [EMPDATEADDED] = GETUTCDATE()
    bq. FROM
    bq. bq. OPENXML(@XDOC, '/EMPREC/Table', 2) \\ WITH (
    bq. bq. Title VARCHAR(10), \\ FirstName VARCHAR(50), \\ LastName VARCHAR(50), \\ DepartmentID INT, \\ StartDate DATETIME, \\ IsActive BIT
    bq. bq. );
    bq. EXEC sp_xml_removedocument @XDOC;
    END
    I would sincerely appreciate any help in this regard!
    PS - Please excuse the formatting!
    Much Thanks!
    regards
    shalan

    Assuming your table is named DESTINATION
    Name                                      Null?    Type
    TITLE                                              VARCHAR2(10)
    FIRSTNAME                                          VARCHAR2(50)
    LASTNAME                                           VARCHAR2(50)
    DEPARTMENT                                         NUMBER
    STARTDATE                                          DATE
    ISACTIVE                                           NUMBERYou can use a procedure like:
    create or replace
    procedure test (p_xml in xmltype)
    is
    begin
      insert into destination
      select title
           , firstname
           , lastname
           , department
           , to_date (startdate, 'yyyy-dd-mm hh24:mi:ss') startdate
           , isactive
        from (xmltable ('/EMPREC/Table' passing p_xml
                       columns title varchar2(5) path 'Title'
                             , firstname varchar2(10) path 'FirstName'
                             , lastname varchar2(10) path 'LastName'
                             , department number path 'Department'
                             , startdate varchar2(20) path 'StartDate'
                             , isactive number path 'IsActive'
                      ) temp
    end test;to create records in the table
    Removed a unnecessary SELECT FROM DUAL...
    Edited by: Alex Nuijten on Jan 19, 2009 2:24 PM

  • Help with Command - Stored Procedure

    Hi all,
    I'm having a great deal of difficulty getting my head around
    an update command / stored procedure, I've pulled out all of my
    books and spent the last two days on Google which has made my
    confusion worse. In simple terms what I'm trying to do is update a
    field in a table with the value y, but based on certain criteria.
    So my table has the following fields -
    JBAID
    JBASiteID
    JBADatePosted
    JBAPostFor
    JBANotified
    What i want to do is update the value of field JBANotified on
    all records that meeting the following criteria to Y
    The criteria is -
    WHERE DATEADD(d,JBAPostFor,JBADatePosted) BETWEEN DATEADD(d,
    -7, GETDATE()) AND GETDATE() AND JBANotified = 'n' AND JBASiteID =
    MMColParam (where MMColParam is Session("SITEID"))
    So I've just tried building a command / stored procedure -
    which reads (see attached code)(more than likely all wrong)
    The things that I cant get my head around are -
    Firstly getting the code right in the first place, running
    the command on page load and then when the command has run
    redirecting to the next page.
    I really would appreciate some help with this -
    thanks all

    Ed Stewart wrote:
    > Are you using CS3 with ASP/VBScript? There is a bug in
    the command
    > implementation that has this function broken.
    >
    > I asked about it in this forum several months ago, but
    now I can't find my
    > original post, but I did find another post that talks
    about the same thing:
    >
    http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=12&catid=26
    > 3&threadid=1281539&enterthread=y
    >
    > My solution is to drop back to DW8 for command editing,
    but use CS3 for
    > everything else. I don't know what you're supposed to do
    if you don't have an
    > earlier version.
    >
    > It looks like your sql is correct, but the bug prevents
    the second code block
    > is not being updated with the correct values.
    >
    > I hope a solution is forthcoming....
    >
    Create a stored procedure and then use a recordset to
    exectute it,
    making sure the recordset has matching parameters that the
    stored
    procedure expects.
    Commands are broken, I reported it to Adobe and they said it
    might get
    fixed in the next version.
    Steve

  • Help with a stored procedure....

    i'll be honest, i have never written one, and i have been doing research all day to do one and i have not had much luck. Seems like they mostly all take variables or require data that i just do not want it to require.
    I have a query (using TOAD fyi) that is run every morning.... i am trying to make it a stored procedure because i am in the process of automating this for people who want it as opposed to sending it to everyone.
    This is the query i am trying to turn into a stored procedure.... (some details removed for sake of security)
    SELECT CASE
    WHEN stuff
    ELSE 'Unknown'
    END aging,
    a.transaction_type, a.status_code, b.description, a.exception_code,
    c.description,
    decode(a.exception_code,'XXXX','YYYY',
    'XXXX','YYYY',
    'XXXX','YYYY','EXCEPTION') "CATEGORY"
    ,COUNT (*)
    FROM (SELECT TO_DATE
    (DBMS_LOB.SUBSTR (clob_details,10,DBMS_LOB.INSTR (clob_details,
    '<TransactionDate>') + 17 ),'yyyy-mm-dd') receipt_date,
    transaction_type, status_code, exception_code
    FROM thisdb.TRANSACTION
    WHERE status_code = 'MX'
    AND clob_details IS NOT NULL) a,
    thisdb.status b,
    thisdb.EXCEPTIONS c
    WHERE a.exception_code = c.exception_code
    AND a.status_code = b.status_code
    and a.status_code = 'MX'
    GROUP BY a.status_code,
    b.description,
    a.transaction_type,
    a.exception_code,
    c.description,
    CASE
    WHEN Stuff
    ELSE 'Unknown'
    END;
    now, please do not worry about the contents of the query, it works nicely and does its job :)
    but how can i take this and encapsulate it so that i can turn it into a stored procedure?
    Thank you all very much for any and all advice, i do greatly appreciate it!

    Hi,
    user12733751 wrote:
    it is just a query, the results will be going to excel later, all that is created already (the connection and runnign basic queries via excel VBA), so perhaps you are right, i do not need a stored procedure but a view?
    I have not heard of a view (stored query), how does that work?You create a view once for all like this:
    CREATE OR REPLACE VIEW  fubar
    AS
    SELECT    CASE
               WHEN  stuff
              ...     -- the rest of your original query goes here
              END;And you use it just like a table:
    SELECT  *
    FROM    fubar;A user who runs this last, extremely short, query gets the exact same results as someone who runs your original query.
    Here's a completely different approach.
    Depending on your front-end, you could also save your original query in a script, called fubar.sql, and people could run it by simply saying
    @fubar

  • Help! Need oracle help with constructing stored procedure that return resultsets

    Suns tutorial path for returning resultsets from stored procedures indicates that the following should work...
    CallableStatement cs = con.prepareCall("{call SHOW_SUPPLIERS}");
    ResultSet rs = cs.executeQuery();
    Thats if you build your stored procedure something like this ...
    String createProcedure = "create procedure SHOW_SUPPLIERS " + "as " + "select SUPPLIERS.SUP_NAME, COFFEES.COF_NAME " + "from SUPPLIERS, COFFEES " + "where SUPPLIERS.SUP_ID = COFFEES.SUP_ID " + "order by SUP_NAME";
    We are using oracle 8.1.6. However I've been told that with oracle procedures when you return a result set from a called procedure you return a p_cursor variable. Somthing like this
    (p_cursor in out SHOW_SUPPLIERS.SHOCurTyp)
    is
    begin
    open p_cursor for
    select * from suppliers
    In which case the above mentioned sun code doesn't work.
    We want to use jdbc to call a stored procedure that returns a resultset that does not require us to import any proprietary oracle objects...
    Is there another way to write these stored procedures, rather than using this cursor construct? Are we missing something in the way we invoke them?

    Suns tutorial path for returning resultsets from stored procedures indicates that the following should work...
    CallableStatement cs = con.prepareCall("{call SHOW_SUPPLIERS}");
    ResultSet rs = cs.executeQuery();
    Thats if you build your stored procedure something like this ...
    String createProcedure = "create procedure SHOW_SUPPLIERS " + "as " + "select SUPPLIERS.SUP_NAME, COFFEES.COF_NAME " + "from SUPPLIERS, COFFEES " + "where SUPPLIERS.SUP_ID = COFFEES.SUP_ID " + "order by SUP_NAME";
    We are using oracle 8.1.6. However I've been told that with oracle procedures when you return a result set from a called procedure you return a p_cursor variable. Somthing like this
    (p_cursor in out SHOW_SUPPLIERS.SHOCurTyp)
    is
    begin
    open p_cursor for
    select * from suppliers
    In which case the above mentioned sun code doesn't work.
    We want to use jdbc to call a stored procedure that returns a resultset that does not require us to import any proprietary oracle objects...
    Is there another way to write these stored procedures, rather than using this cursor construct? Are we missing something in the way we invoke them?

  • I need Help with the stored procedure

    Hello, I new with VS.Net
    I'm tring to call a stored procedure, but when i try to retrive the data don't return nothing.
    my VB code is the follows
    ocm_comando.Connection = ocn_coneccion
    ocm_comando.CommandText = "WPROC_PRUEBA"
    ocm_comando.CommandType = CommandType.StoredProcedure
    ocm_comando.Parameters.Add("PNI_ID_ESTUDIO", OracleDbType.Decimal).Direction = ParameterDirection.Input
    ocm_comando.Parameters("PNI_ID_ESTUDIO").Value = CType(vc_id_estudio, Integer)
    ocm_comando.Parameters.Add("pco_precalificada", OracleDbType.Varchar2).Direction = ParameterDirection.Output
    ocm_comando.Parameters.Add("pco_resultado", OracleDbType.Varchar2).Direction = ParameterDirection.Output
    Txb_empresa.Text = ocm_comando.Parameters("pco_precalificada").Value
    My stored procedure only take the parameter that I sent and make a simple select and return the value in the variable pco_precalificada
    thank for your help
    **** Sorry for mi English

    You forgot to actually execute the command. Before the last line, where you ask for the value of pco_precalificada, you need to:
    1. Open the connection (if it's not already open)
    2. Call ocm_comando.ExecuteNonQuery()
    HTH,
    Tom

  • Help needed in Stored Procedure validation

    Hi,
    I have defined 5 dimensions in my database. For GLs of Expense and Revenue drawer, I want to validate that if Dimension 1 is selected for a GL in any transaction, then Dimension 2 must also be mandatory.
    Now different transactions have different tables in SAP, like for service type AP Invoice and AR Invoice, I have to read different table; for Incoming & Outgoing Payment against Account, I have to read different table. Then there is Manual Journal Entry also etc.
    But all these transactions also generate a Journal Entry, so in my Stored Procedure, irrespective of AP, AR or whichever screen, how can I access the underlying Journal Entry of that transaction and validate the GL accounts in the Journal Entry that Dimension 2 is mandatory if Dimension 1 is selected?
    Thanks.

    Hi,
    What is your Account Dimension 1 and 2 supposed to be? Can you post here your Chart of Accounts? for us to build the right query for SP_TransactionNotification.
    Thanks
    Alvin

Maybe you are looking for

  • I plug IPod into computer and it says it's charging

    I have no clue what I did. when I used to plug my IPod into the computer ITunes recognized it, then once it said "Do not disconnect" and I unplugged it and now ITunes never recognizes my Ipod and it says it's charging instead. Help, my computer is a

  • BI server is not starting

    Hi, I am having a problem starting my BI server (Red Hat Linux) - when I view the NQServer.log file after starting the server, I see that it's loading each of my subject areas. It has a message saying Finished loading ... for each subject area. Howev

  • Subquery in ODI

    Hello, i need an information ... situation: i need the NVL ( ..., ....) function. in the developer it is no problem to test the subquery, but in ODI i think, it's al little bit more complicated. NVL( <value from my table>, <subquery> ) at the moment

  • Site manager in CS3 deleted all sites

    I am currently working in dreamweaver cs3 for the mac on Leopard. Today the software decided to delete all of my sites in site manager. I don't know ow but it did. I still have several of the sites in Dreamweaver 8. Is there a way to export the infor

  • IBook G3 cannot connect to WPA (Panther 10.3.9)

    Hi there... My iBook G3 366Mhz Clamshell with Airport and Mac OS X 10.3.9 cannot connect to my WPA wireless network. I believe I am all set to connect to wireless WPA, but whenever i try and connect to my wireless it asks for the password and then af