Help on Procedure

I have two tables.
ID columns exist in both tables and same record has the same id in both tables. Which mean if the record with ID = 3 in TABLE 1, the record with ID = 3 in TABLE 2 will represent the same record.
TABLE 1 has more data then TABLE 2. Which means TABLE 2 only contains part of the records. No duplicate records.
I want to update some of the columns in TABLE 1 by using TABLE 2 information.
Both tables contain more then 50 million records.
TABLE 1
ID                    name                    title                    level                    office                    location
1                     John                     VP                      9                        18133                        SH
2                     Steve                    MG                      6                        16231                        SA
3                     Jane                                             3                        14267                      
4                                                                      4                        208                           PB
5                                              SL                      6                        192                           BZ
6                     John                     PM                                               133                          SH
7                     Smith                    PM                      2                        183                          SH
8                     Joe                                              2                        18133                        SH
TABLE 2
ID                    name                    title                    level                    office                    location
3                     Jane                                             3                        247                      
6                     John                     PM                      3                        153                          SH
1                     John                     VP                      6                        18133                        SH
4                                                                      4                        208                           PB
2                     Steve                    MG                      4                        16571                        SA
8                     Joe                      TL                      2                        18003                        SH
5                                              SL                      7                        192                           BZ
7                     Smith                    PM                      4                        196                          SH
.I want to use update TABLE 1 by using TABLE2 (Column "level", "office" & "title"). Here is the procedure.
CREATE OR REPLACE PROCEDURE PROC_4 IS
step_id    CONSTANT NUMBER(10) := 100000;
maximum_id          NUMBER(10) := 75000000;
low_id              NUMBER(10) := 1;
high_id             NUMBER(10);
BEGIN
high_id := low_id + step_id;
DBMS_OUTPUT.PUT_LINE('LOW ID = ' || TO_CHAR(low_id) || ', HIGH ID = ' || TO_CHAR(high_id) || ', MAXIMUM ID = ' || TO_CHAR(maximum_id));
WHILE maximum_id > low_id LOOP
UPDATE TABLE_1 A
SET
    A.TITEL = (SELECT B.TITLE FROM TABLE_2 B WHERE A.ID = B.ID),
    A.OFFICE = (SELECT B.OFFICE FROM TABLE_2 B WHERE A.ID = B.ID),
    A.LEVEL = (SELECT B.LEVEL FROM TABLE_2 B WHERE A.ID = B.ID)
WHERE EXISTS (SELECT B.ID FROM TABLE_2 B WHERE A.ID = B.ID);
    COMMIT;
    low_id  := high_id;
    high_id := high_id + step_id;
    DBMS_OUTPUT.PUT_LINE('LOW ID = ' || TO_CHAR(low_id) || ',HIGH ID = ' || TO_CHAR(high_id));
END LOOP;
END PROC_4;
/I tried this, but it is kind of slow, can anyone help me to speed it up?
PS, these two tables are huge.
Thanks at advance.
Edited by: user644467 on Mar 10, 2011 3:02 PM
Edited by: user644467 on Mar 10, 2011 9:28 PM

user644467 wrote:
These are huge tables, my original purpose is to do it piece by piece (every 100000). I thought this will faster.Do what piece by piece? Faster than what? Your posted code will do the same thing 750 times for no clear reason.
My understanding is that your SQL will full table scan for every record, right?My version has two subqueries instead of the four in your version, and it also avoids 750 unnecessary commits. I'm not sure what you think full scans have to do with it.

Similar Messages

  • Need help in procedure

    Hi Experts,
    I have wrote a procedure which is being fired by a trigger and update or insert the Attendance_day table on the basis of punch string, the below issue is coming when employee do two regular shift.
    [code]
    select * from ATTENDANCEMASTER where DATE_PUNCH>='01-aug-2013' and EMP_CD in('E03497');
    SNO
    EMP_CD
    DATE_PUNCH
    TIME_PUNCH
    PREFIX
    INOUT
    8027551423
    E03497   
    1-Aug-13
    8:53
    200
    I
    8027890076
    E03497   
    1-Aug-13
    19:01
    200
    O
    8027980116
    E03497   
    2-Aug-13
    8:56
    200
    I
    8028070441
    E03497   
    2-Aug-13
    17:43
    200
    O
    8028071247
    E03497   
    3-Aug-13
    8:49
    200
    I
    8028160480
    E03497   
    3-Aug-13
    17:43
    200
    O
    8028160680
    E03497   
    3-Aug-13
    22:51
    200
    I
    8028161035
    E03497   
    4-Aug-13
    6:54
    200
    O
    8028661326
    E03497   
    6-Aug-13
    8:51
    200
    I
    8028840273
    E03497   
    6-Aug-13
    18:55
    200
    O
    8028841247
    E03497   
    7-Aug-13
    8:56
    200
    I
    This table is being updated after employees swipe the card. If u look @ the record of 3rd aug the employee has done two shift 1st in 1st shift(9-6pm) and another on 3rd shift (11pm-to next day of 7am). After this table the main attendnace_day table is being updated
    SELECT * FROM ATTENDANCE_DAY WHERE EMP_CODE IN('E03497') AND ATTD_DATE >='01/AUG/2013';
    attd_date
    emp_code
    in_time
    out_time
    status
    shift
    day_no
    chg_date
    chg_user
    chg_term
    result
    punch_str
    1-Aug-13
    E03497   
    8:53
    19:01
    (null)
    G0013
    5
    1-Aug-13
    STAR     
    PAPNABMS      
    -08:53 , -19:01
    2-Aug-13
    E03497   
    8:56
    17:43
    (null)
    G0013
    6
    2-Aug-13
    STAR     
    PAPNABMS      
    -08:56 , -17:43
    3-Aug-13
    E03497   
    8:49
    17:43
    (null)
    G0013
    7
    4-Aug-13
    PRITESH  
    21PAPNADIXIT  
    -08:49 , -17:43 , -22:51,*-17:43
    6-Aug-13
    E03497   
    8:51
    18:55
    (null)
    G0013
    3
    6-Aug-13
    STAR     
    PAPNABMS      
    -08:51 , -18:55
    7-Aug-13
    E03497   
    8:56
    G0013
    4
    7-Aug-13
    STAR     
    PAPNABMS      
    0
    The out time in aug 3rd record is 17:43 but as employee has done two shifts the out time must be:
    8028161035
    E03497   
    4-Aug-13
    6:54
    200
    O
    That's why I need to change the procedure in way that it should update the attendance_day table on the basis of IN OUT flag and must capture these types of records properly.
    The Procedure is mentioned below:
    [code]
    CREATE OR REPLACE
    PROCEDURE UPDATE_ATTENDANCE
        AS_EMP_CODE   CHAR,
        AS_DATE_PUNCH DATE,
        AS_TIME_PUNCH CHAR
    AS
    BEGIN
      DECLARE
        a_time_punch workshft.in_time%type := AS_TIME_PUNCH;
        a_work_shift employee.work_shift%type;
        a_shift_intime workshft.in_time%type;
        a_lunch_time workshft.lunch_time%type;
        a_hol_tblno holiday.hol_tblno%type;
        a_fin_entity site.fin_entity%type;
        a_prv_date DATE := AS_DATE_PUNCH - 1;
        a_count    NUMBER(5);
        a_count1   NUMBER(5);
        CURSOR c1
        IS
          SELECT work_shift
          FROM
            (SELECT tran_date eff_date,
              work_shift_o work_shift,
              conf_date,
              chg_date
            FROM employee_det_change
            WHERE emp_code = AS_EMP_CODE
            AND tran_date  > AS_DATE_PUNCH
            AND status     = 'C'
          UNION ALL
          SELECT eff_Date,
            work_shift__fr work_shift,
            conf_date,
            chg_date
          FROM emp_employ_events
          WHERE emp_code = AS_EMP_CODE
          AND eff_date   > AS_DATE_PUNCH
          AND confirmed  = 'Y'
          ORDER BY eff_date,
            conf_date,
            chg_date;
        BEGIN
          SELECT b.fin_entity
          INTO a_fin_entity
          FROM employee a,
            site b
          WHERE a.emp_code = AS_EMP_CODE
          AND b.site_code  = a.work_site;
          SELECT COUNT(*)
          INTO a_count
          FROM work_shift
          WHERE emp_code = AS_EMP_CODE
          AND AS_DATE_PUNCH BETWEEN from_dt AND to_dt;
          IF (a_count > 0) THEN
            SELECT shift
            INTO a_work_shift
            FROM work_shift
            WHERE emp_code = AS_EMP_CODE
            AND AS_DATE_PUNCH BETWEEN from_dt AND to_dt;
          ELSE
            FOR i IN c1
            LOOP
              a_work_shift := i.work_shift;
              EXIT;
            END LOOP;
            IF (a_work_shift IS NULL) THEN
              SELECT work_shift
              INTO a_work_shift
              FROM employee
              WHERE emp_code = AS_EMP_CODE;
            END IF;
          END IF;
          SELECT in_time,
            lunch_time
          INTO a_shift_intime,
            a_lunch_time
          FROM workshft
          WHERE shift = a_work_shift
          AND day_no  = TO_CHAR(AS_DATE_PUNCH,'D');
          SELECT COUNT(*)
          INTO a_count
          FROM attendance_day
          WHERE attd_date = AS_DATE_PUNCH
          AND emp_code    = AS_EMP_CODE;
          IF (a_count     > 0) THEN
            IF (A_FIN_ENTITY IN ('IC','HU')) THEN
              ------UPDATE HERE-----
              UPDATE attendance_day
              SET out_time = a_time_punch,
                punch_str  = punch_str || ' , -' || AS_TIME_PUNCH,
                work_hour     = (ddf_time_in_mm(a_time_punch)-ddf_time_in_mm(in_time))
              WHERE attd_date = AS_DATE_PUNCH
              AND emp_code    = AS_EMP_CODE;
            ELSE
              IF (ddf_time_in_mm(a_time_punch) < (ddf_time_in_mm(a_shift_intime) + 30)) THEN
                UPDATE attendance_day
                SET PUNCH_STR = PUNCH_STR || ' , -' || AS_TIME_PUNCH
                WHERE attd_date = AS_DATE_PUNCH
                AND emp_code    = AS_EMP_CODE;
              ELSE
                ------UPDATE HERE-----
                UPDATE attendance_day
                SET out_time = a_time_punch,
                  punch_str  = punch_str || ' , -' || AS_TIME_PUNCH,
                  work_hour     = (ddf_time_in_mm(a_time_punch)-ddf_time_in_mm(in_time))
                WHERE attd_date = AS_DATE_PUNCH
                AND emp_code    = AS_EMP_CODE;
              END IF;
            END IF;
          ELSE
            SELECT COUNT(*)
            INTO a_count1
            FROM work_shift
            WHERE emp_code = AS_EMP_CODE
            AND a_prv_date BETWEEN from_dt AND to_dt
            AND shift =
              (SELECT shift
              FROM workshft
              WHERE shift   = work_shift.shift
              AND day_no    = TO_CHAR(a_prv_date,'D')
              AND (out_time > '24:00'
              OR out_time   < in_time)
            SELECT ddf_get_holtblno(AS_EMP_CODE,AS_DATE_PUNCH) INTO a_hol_tblno FROM dual;
            SELECT COUNT(*)
            INTO a_count
            FROM holiday
            WHERE hol_tblno = a_hol_tblno
            AND hol_date = AS_DATE_PUNCH;
            IF ((A_COUNT1 > 0) OR (DDF_TIME_IN_MM(A_TIME_PUNCH) < (DDF_TIME_IN_MM(A_SHIFT_INTIME) - 120)) OR (A_COUNT > 0)) THEN
              IF (a_fin_entity IN ('IC','HU') AND a_count1 > 0) THEN
                SELECT COUNT(*)
                INTO a_count
                FROM attendance_day a,
                  workshft b
                WHERE a.attd_date = a_prv_date
                AND a.emp_code = AS_EMP_CODE
                AND b.shift = a.shift
                AND b.day_no = a.day_no
                AND (ddf_time_in_mm(a_time_punch)+1440) <= (ddf_time_in_mm(b.out_time) + (
                  CASE
                    WHEN b.out_time < b.in_time
                    THEN 1440
                    ELSE 0
                  END) + 300);
              ELSE
                SELECT COUNT(*)
                INTO a_count
                FROM attendance_day
                WHERE attd_date = a_prv_date
                AND emp_code    = AS_EMP_CODE
                AND out_time   IS NULL;
              END IF;
              IF (a_count     > 0) THEN
                A_TIME_PUNCH := TO_CHAR((TO_NUMBER(SUBSTR(A_TIME_PUNCH,1,2))+24)) || ':' || SUBSTR(A_TIME_PUNCH,4,2);
                ------UPDATE HERE-----
                UPDATE attendance_day
                SET out_time = a_time_punch,
                  punch_str  = punch_str
                  || ' , -'
                  || a_time_punch,
                  work_hour     = (ddf_time_in_mm(a_time_punch)-ddf_time_in_mm(in_time))
                WHERE attd_date = a_prv_date
                AND emp_code    = AS_EMP_CODE;
              ELSE
                ------UPDATE HERE-----
                INSERT
                INTO attendance_day
                    attd_date,
                    emp_code,
                    in_time,
                    shift,
                    day_no,
                    chg_date,
                    chg_user,
                    chg_term,
                    punch_str,
                    lunch_time
                  VALUES
                    AS_DATE_PUNCH,
                    AS_EMP_CODE,
                    a_time_punch,
                    a_work_shift,
                    TO_CHAR(AS_DATE_PUNCH,'D'),
                    sysdate,
                    USER,
                    userenv('terminal'),
                    || AS_TIME_PUNCH,
                    a_lunch_time
              END IF;
            ELSE
              INSERT
              INTO attendance_day
                  attd_date,
                  emp_code,
                  in_time,
                  shift,
                  day_no,
                  chg_date,
                  chg_user,
                  chg_term,
                  punch_str,
                  lunch_time
                VALUES
                  AS_DATE_PUNCH,
                  AS_EMP_CODE,
                  a_time_punch,
                  a_work_shift,
                  TO_CHAR(AS_DATE_PUNCH,'D'),
                  sysdate,
                  USER,
                  userenv('terminal'),
                  '-' || AS_TIME_PUNCH,
                  a_lunch_time
            END IF;
          END IF;
        END;
      END;
    [code]
    Thnx in advance, help will be appreciated..

    Sorry, totally lost in procedural logic (maybe others could see some ways of improvement)
    PROCEDURE UPDATE_ATTENDANCE
        AS_EMP_CODE   CHAR,
        AS_DATE_PUNCH DATE,
        AS_TIME_PUNCH CHAR
    AS
    BEGIN
    DECLARE
        a_time_punch workshft.in_time%TYPE := AS_TIME_PUNCH;
        a_work_shift employee.work_shift%TYPE;
        a_shift_intime workshft.in_time%TYPE;
        a_lunch_time workshft.lunch_time%TYPE;
        a_hol_tblno holiday.hol_tblno%TYPE;
        a_fin_entity site.fin_entity%TYPE;
        a_prv_date DATE := AS_DATE_PUNCH - 1;
        a_count    NUMBER(5);
        a_count1   NUMBER(5);
    -------------------------------changes 13082013 starts-------------------
        a_count11 workshft.in_time%TYPE;
        a_count22 workshft.in_time%TYPE;
    -------------------------------changes 13082013 ends-------------------
    CURSOR c1 IS
          SELECT work_shift
            FROM(SELECT tran_date eff_date,work_shift_o work_shift,conf_date,chg_date
                   FROM employee_det_change
                  WHERE emp_code = AS_EMP_CODE
                    AND tran_date > AS_DATE_PUNCH
                    AND status = 'C'
                 UNION ALL
                 SELECT eff_date,work_shift__fr work_shift,conf_date,chg_date
                   FROM emp_employ_events
                  WHERE emp_code = AS_EMP_CODE
                    AND eff_date > AS_DATE_PUNCH
                    AND confirmed = 'Y'
           ORDER BY eff_date,conf_date,chg_date;
    BEGIN
          SELECT b.fin_entity
            INTO a_fin_entity
            FROM employee a,
                 site b
           WHERE a.emp_code = AS_EMP_CODE
             AND b.site_code = a.work_site;
          SELECT COUNT(*)
            INTO a_count
            FROM work_shift
           WHERE emp_code = AS_EMP_CODE
             AND AS_DATE_PUNCH BETWEEN from_dt AND to_dt;
          IF (a_count > 0) THEN
              SELECT shift
                INTO a_work_shift
                FROM work_shift
               WHERE emp_code = AS_EMP_CODE
                 AND AS_DATE_PUNCH BETWEEN from_dt AND to_dt;
          ELSE
              FOR i IN c1
              LOOP
                a_work_shift := i.work_shift;
                EXIT;
              END LOOP;
              IF (a_work_shift IS NULL) THEN
                SELECT work_shift
                  INTO a_work_shift
                  FROM employee
                 WHERE emp_code = as_emp_code;
              END IF;
          END IF;
          SELECT in_time,lunch_time
            INTO a_shift_intime,a_lunch_time
            FROM workshft
           WHERE shift = a_work_shift
             AND day_no = TO_CHAR(AS_DATE_PUNCH,'D');
          SELECT COUNT(*)
            INTO a_count
            FROM attendance_day
           WHERE attd_date = AS_DATE_PUNCH
             AND emp_code = AS_EMP_CODE;
          IF (a_count > 0) THEN
            IF (a_fin_entity IN ('IC','HU')) THEN
              UPDATE attendance_day
                 SET out_time = a_time_punch,
                     punch_str = punch_str || ' , -' || as_time_punch,
                     work_hour = (ddf_time_in_mm(a_time_punch) - ddf_time_in_mm(in_time))
               WHERE attd_date = AS_DATE_PUNCH
                 AND emp_code = AS_EMP_CODE;
            ELSE
              IF (ddf_time_in_mm(a_time_punch) < (ddf_time_in_mm(a_shift_intime) + 30)) THEN
                UPDATE attendance_day
                   SET punch_str = punch_str || ' , -' || as_time_punch
                 WHERE attd_date = AS_DATE_PUNCH
                   AND emp_code = AS_EMP_CODE;
              ELSE
                UPDATE attendance_day
                   SET out_time = a_time_punch,
                       punch_str = punch_str || ' , -' || as_time_punch,
                       work_hour = (ddf_time_in_mm(a_time_punch) - ddf_time_in_mm(in_time))
                 WHERE attd_date = AS_DATE_PUNCH
                   AND emp_code = AS_EMP_CODE;
              END IF;
            END IF;
          ELSE
            SELECT COUNT(*)
              INTO a_count1
              FROM work_shift
             WHERE emp_code = AS_EMP_CODE
               AND a_prv_date BETWEEN from_dt AND to_dt
               AND shift = (SELECT shift
                              FROM workshft
                             WHERE shift = work_shift.shift
                               AND day_no = TO_CHAR(a_prv_date,'D')
                               AND (out_time > '24:00' OR out_time < in_time)
            SELECT ddf_get_holtblno(as_emp_code,as_date_punch)
              INTO a_hol_tblno
              FROM dual;
            SELECT COUNT(*)
              INTO a_count
              FROM holiday
             WHERE hol_tblno = a_hol_tblno
               AND hol_date = AS_DATE_PUNCH;
            IF ((a_count1> 0) OR (ddf_time_in_mm(a_time_punch) < (ddf_time_in_mm(a_shift_intime) - 120)) OR (a_count > 0)) THEN
              IF (a_fin_entity IN ('IC','HU') AND a_count1 > 0) THEN
                SELECT COUNT(*)
                  INTO a_count
                  FROM attendance_day a,
                       workshft b
                 WHERE a.attd_date = a_prv_date
                   AND a.emp_code= AS_EMP_CODE
                   AND b.shift = a.shift
                   AND b.day_no= a.day_no
                   AND ddf_time_in_mm(a_time_punch)+1440 <= ddf_time_in_mm(b.out_time) + CASE WHEN b.out_time < b.in_time THEN 1440 ELSE 0 END + 300;
              ELSE
                SELECT COUNT(*)
                  INTO a_count
                  FROM attendance_day
                 WHERE attd_date = a_prv_date
                   AND emp_code = AS_EMP_CODE
                   AND out_time IS NULL;
              END IF;
    -------------------------------changes 13082013 starts-------------------
              SELECT MAX(TIME_PUNCH)
                INTO A_COUNT11
                FROM ATTENDANCEMASTER
               WHERE DATE_PUNCH = A_PRV_DATE
                 AND EMP_CD = AS_EMP_CODE
                 AND INOUT='I';
              SELECT OUT_TIME
                INTO A_COUNT22
                FROM ATTENDANCE_DAY
               WHERE EMP_CODE = AS_EMP_CODE
                 AND ATTD_DATE = a_prv_date;
              DBMS_OUTPUT.PUT_LINE('value of In TIme : ' ||TO_CHAR(A_COUNT22)|| ' , Out Time : '|| TO_CHAR(A_COUNT11));
              IF (A_COUNT11 > A_COUNT22) THEN
                a_count:=1;
              ELSE
                a_count:=0;
              END IF;
    -------------------------------changes 13082013 ends-------------------
              IF (a_count > 0) THEN
                A_TIME_PUNCH := TO_CHAR((TO_NUMBER(SUBSTR(A_TIME_PUNCH,1,2))+24)) || ':' || SUBSTR(A_TIME_PUNCH,4,2);
                UPDATE attendance_day
                   SET out_time = a_time_punch,
                       punch_str = punch_str || ' , -' || a_time_punch,
                       work_hour = (ddf_time_in_mm(a_time_punch) - ddf_time_in_mm(in_time))
                 WHERE attd_date = a_prv_date
                   AND emp_code = AS_EMP_CODE;
              ELSE
                INSERT INTO attendance_day(attd_date,emp_code,in_time,shift,day_no,chg_date,chg_user,chg_term,punch_str,lunch_time)
                VALUES (AS_DATE_PUNCH,AS_EMP_CODE,a_time_punch,a_work_shift,TO_CHAR(AS_DATE_PUNCH,'D'),SYSDATE,USER,USERENV('terminal'),'-'|| AS_TIME_PUNCH,a_lunch_time);
                END IF;
            ELSE
              INSERT INTO attendance_day(attd_date,emp_code,in_time,shift,day_no,chg_date,chg_user,chg_term,punch_str,lunch_time)
              VALUES (AS_DATE_PUNCH,AS_EMP_CODE,a_time_punch,a_work_shift,TO_CHAR(AS_DATE_PUNCH,'D'),SYSDATE,USER,USERENV('terminal'),'-'|| AS_TIME_PUNCH,a_lunch_time);
            END IF;
          END IF;
    END;
    You might be better off just storing the punch data into attendancemaster table (allowing browsing, changes, confirmations, ...) and using sql to update attendance_day table in one shot just before the table is needed for further processing
    Regards
    Etbin

  • Help on Procedure and trigger for updating(urgent please)

    SQL> / Table A
    CTUT_ID CTUT_COMPANY_NAME CURRT_USER_ID FMIS_ID CREATE_DA UPDATE_BY UPDATE_DATE
    1234 A 15-APR-03
    2222 B 15-APR-03
    3333 C 15-APR-03
    4444 D 15-APR-03
    5555 E 15-APR-03
    6666 F 15-APR-03
    150282 G oRACLE 23-APR-03
    1 H 15-APR-03
    2 I 15-APR-03
    3 J 15-APR-03
    150343 K TIGER 24-APR-03
    150305 L EXAMPLE 23-APR-03
    150342 M SCOTT 24-APR-03
    sQL >/ Table B
    Empno     Empname UPDATE_BY UPDATE_DATE
    1 AA
    2 BB
    3 CC
    4 DD
    What i need to do is i need to create an update trigger on both tables
    like create a procedure
    1)In procedure i need to check like
    IF TABLEA.CURRT_USER_ID = (SELECT USER FROM DUAL)
    THEN
    UPDATE_BY = (CURRENT_USER_ID of CTUT_ID)
    FOR EXAMPLE CURRENT USER_ID IS SCOTT THEN
    UPDATE_BY = 150342
    UPDATE_DATE = SYSDATE
    ELSIF
    UPDATE_BY <=> (CURRENT_USER_ID of CTUT_ID)
    THEN
    MESSAGE('USER IS NOT IN TABLE);
    END IF;
    and call that procedure in the update triggers
    FOR BOTH TABLES TABLEA,TABLEB
    i CREATED A PROCEDURE BUT IT IS NOT WORKING
    ANY HELP PLEASE
    CREATE OR REPLACE PROCEDURE UPDATE(
    UPDATE_DATE out DATE,
    UPDATE_BY out VARCHAR2)
    IS
    Uuser varchar2(20);
    Udate date;
    Ufound number(1);
    BEGIN
    SELECT USER,SYSDATE
    INTO Uuser,Udate from dual;
    SELECT count(*),CTUT_ID into Ufound,Uctut_id
    FROM TABLEA
    WHERE CURRT_USER_ID = Uuser
    Group by Ctut_id;
    IF (UFOUND = 1) THEN
    UPDATE_DATE := UDATE;
    UPDATE_BY := UCTUT_ID;
    END IF;
    EXCEPTION WHEN NO_DATA_FOUND THEN
    RAISE_APPLICATION_ERROR(-20001,'User Does not Exist');
    END UPD_CONSTITUENT;
    CREATE A TRIGGER :
    CREATE OR REPLACE TRIGGER TU
    BEFORE INSERT ON TABLEA
    FOR EACH ROW
    BEGIN      
    UPDATE(:NEW.update_date,
         :NEW.update_BY);
    END IF;      
    END;
    SQL> update TABLEA
    2 set CTUT_COMPANY_NAME = 'SCOTT TEST'
    3 WHERE FMIS_USER_ID = 'N';
    update TABLEA
    ERROR at line 1:
    ORA-04091: table TABLEA is mutating, trigger/function may not see it
    ORA-06512: at "UPDATE", line 12
    ORA-06512: at "TU", line 1
    ORA-04088: error during execution of trigger 'TU'

    Hi Mara,
    You are right thats what i want
    I have a table A
    EmpNo Empname Currtuser_id Update_date Updateby
    1 Denis Oracle
    2 Scott Scott
    3 Mara MMara
    1)what i need to do is when any user tries to update the table Table A
    Then the Trigger or procedure should check whether user is exits in table A in column currtuser_id
    If his user id exits in table A
    Then allow him to update the TABLE A
    and insert his EMPNO in UPDATE_BY
    and SYSDATE in UPDATE_BY
    He will do all this process using forms
    But i need to have trigger or procedure in database level for table
    2) I have another table like 10 tables
    Suppose TABLE B
    When user tries to update TABLE B
    Then the Trigger or procedure should check whether user is exits in table A in column currtuser_id
    If his user id exits in table A
    Then allow him to update the TABLE B
    and insert his EMPNO in UPDATE_BY
    and SYSDATE in UPDATE_BY
    3) I need to have a common Procedure and call that procedure in all tables in UPDATE TRIGGER
    Thanks for your help
    Thanks

  • New to pl/sql and need help with procedure

    Hello there, I got two tables STAFF and BONUS which are not related by any constraints
    STAFF
    ID_NUMBER HIREDATE SALARY BONUS
    100020 12-MAY-03 13600
    100021 04-NOV-01 30000
    100022 08-APR-02 28000
    100023 08-APR-02 24000
    BONUS
    PERCENTAGE MORE_THAN_YEARS
    0.1 3
    0.15 5
    0.3 7
    0.45 9
    0.5 12
    I am trying to create a procedure that would calculate bonus based on years of employment according to bonus table.
    If employees sysdate -hiredate is greater than 5, he would get salary*0.15%....
    I created this procedure, but I got stuck here.
    I calculated the length of employment for every soldier using cursor in a loop, but I don't know how to get values from bonus table and connect them together.
    Please help me!
    create or replace
    procedure bonus_staff
    as
    cursor c1 is select *from staff;
    bon real;
    begin
    FOR ITEM IN C1
    LOOP
    bon := FLOOR(months_BETWEEN(SYSDATE,ITEM.hiredate)/12)*
    update staff
    set bonus = bon
    where id_number = ITEM.id_number;
    exit when c1%notfound;
    end loop;
    end;
    Thanks in advance..

    update staff
    set bonus = (select percentage
    from bonus
    where more_than_years = (select max(more_than_years)
    from bonus
    where more_than_years <= FLOOR(months_BETWEEN(SYSDATE,staff.hiredate)/12)
    You can do this in pure SQL, which operates on a set, so no PL/SQL is required.
    Sybrand Bakker
    Senior Oracle DBA

  • Help on procedure from a code at asktom...

    hello all,
    i found this procedure on asktom.oracle.com...
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1352202934074
    and for some reason i cant get it working..here is the script...
    drop table alert_log;
    create global temporary table alert_log
    ( line   int primary key,
      text   varchar2(4000)
    on commit preserve rows
    create or replace procedure load_alert
    as
        l_background_dump_dest   v$parameter.value%type;
        l_filename               varchar2(255);
        l_bfile                  bfile;
        l_last                   number;
        l_current                number;
        l_start                  number := dbms_utility.get_time;
    begin
        select a.value, 'alert_' || b.instance || '.log'
          into l_background_dump_dest, l_filename
          from v$parameter a, v$thread b
         where a.name = 'background_dump_dest';
        execute immediate
        'create or replace directory x$alert_log$x as
        ''' || l_background_dump_dest || '''';
        dbms_output.put_line( l_background_dump_dest );
        dbms_output.put_line( l_filename );
        delete from alert_log;
        l_bfile := bfilename( 'X$ALERT_LOG$X', l_filename );
        dbms_lob.fileopen( l_bfile );
        l_last := 1;
        for l_line in 1 .. 50000
        loop
            dbms_application_info.set_client_info( l_line || ', ' ||
            to_char(round((dbms_utility.get_time-l_start)/100, 2 ) )
            || ', '||
            to_char((dbms_utility.get_time-l_start)/l_line)
            l_current := dbms_lob.instr( l_bfile, '0A', l_last, 1 );
            exit when (nvl(l_current,0) = 0);
            insert into alert_log
            ( line, text )
            values
            ( l_line,
              utl_raw.cast_to_varchar2(
                  dbms_lob.substr( l_bfile, l_current-l_last+1,
                                                        l_last ) )
            l_last := l_current+1;
        end loop;
        dbms_lob.fileclose(l_bfile);
    end;
    /select name, value from v$parameter where name = 'background_dump_dest';
    NAME                                                                           
    VALUE                                                                          
    background_dump_dest                                                           
    /oracle/admin/orcl/bdump   but when i run the procedure...
    BEGIN
    scott.LOAD_ALERT;
    COMMIT;
    END;
    i get below errors
    Error at line 1
    ORA-22288: file or LOB operation FILEOPEN failed
    No such file or directory
    ORA-06512: at "SYS.DBMS_LOB", line 523
    ORA-06512: at "scott.LOAD_ALERT", line 27
    ORA-06512: at line 2
    ALSO...user scott has dba grant and all other grants necessary. Also its not like the procedure is invalid or anything...its valid...but throws me this error....
    any help is appericiated...

    S2K,
    The procedure contains platform specific code. Of course you couldn't be bothered to specify your version or platform. But, as the error message is self-explanatory. why didn't you verify whether the alert_<instance>.log actually exists?
    You really need to learn to troubleshoot yourself, instead of just dumping everything in this forum rightaway.
    This forum is not about doing your work (or should I say 'ur work') for free!!!!!!!!!!!!!!!!!!
    And BTW: you could easily set up this procedur without needing access to v$thread and v$parameter.
    The quality of the code in this procedure is sadly way below average.
    Sybrand Bakker
    Senior Oracle DBA

  • Help Stored Procedure Problems

    I'm trying to call this stored procedure from VB to update an existing table where its fields match fields in another table.
    I always get a created with erros noteification when I create the procedure.
    CREATE OR REPLACE PROCEDURE smsattribute AS
    CURSOR mycursor IS
    SELECT SMSCOMMODITY.NOMENCLATURE, SMSSIGN_ATTRIBUTE.SIGN_TYPE FROM SMSCOMMODITY, SMSSIGN_ATTRIBUTE WHERE SMSCOMMODITY.WIDTH = SMSSIGN_ATTRIBUTE.WIDTH and SMSCOMMODITY.HEIGHT = SMSSIGN_ATTRIBUTE.HEIGHT and SMSCOMMODITY.NOMENCLATURE = SMSSIGN_ATTRIBUTE.SIGN_
    BEGIN
    FOR SMSSIGN_ATTRIBUTE.SIGN_TYPE IN mycursor LOOP
    UPDATE mycursor SET SMSSIGN_ATTRIBUTE.SIGN_TYPE = SMSCOMMODITY.NOMENCLATURE;
    END LOOP;
    END smsattribute;
    I've also tried the following stored procedure...with the same results.
    UPDATE SMSSIGN_ATTRIBUTE.SIGN_TYPE = (SELECT SMSCOMMODITY.NOMENCLATURE FROM SMSCOMMODITY, SMSSIGN_ATTRIBUTE WHERE SMSCOMMODITY.WIDTH = SMSSIGN_ATTRIBUTE.WIDTH and SMSCOMMODITY.HEIGHT = SMSSIGN_ATTRIBUTE.HEIGHT and SMSCOMMODITY.NOMENCLATURE = SMSSIGN_ATTRIBUTE.SIGN_TYPE)
    Thanks
    null

    Brendan,
    It is not clear what you are trying to do. Ignoring all the syntax errors, it appears that you are trying to update the smsattribute table by setting the sign_type column equal to the value in the nomenclature column of the commodity table where the two are already equal. In other words, you are attempting to create a procedure that will never update anything.
    We would be able to help you more if you would state in words exactly what column of what table you are trying to update with the value from what column of what other table, under what conditions.
    The script below is an example of the general syntax for an update statement like the one you are trying to create. If you will replace table_to_update with the name of the table that you are trying to update and replace column_to_update_to with the name of the column that you want to update and replace table_to_compare with the name of the table that you want to compare to and replace column_to_update_from with the name of the column that you expect to get the value to put in the column_to_update_to and replace each comparison_column with the columns that must already have the same values before updating, then you can use this script.
    UPDATE table_to_update
    SET column_to_update_to =
    (SELECT table_to_compare.column_to_update_from
    FROM table_to_compare
    WHERE table_to_compare.comparison_column1 = table_to_update.comparison_column1
    AND table_to_compare.comparison_column2 = table_to_update.comparison_column2
    AND table_to_compare.comparison_column3 = table_to_update.comparison_column3)
    WHERE (table_to_update.comparison_column1, table_to_update.comparison_column2, table_to_update.comparison_column3) IN
    (SELECT table_to_compare.comparison_column1, table_to_compare.comparison_column2, table_to_compare.comparison_column3
    FROM table_to_compare);
    If you want to create a procedure that performs the update, then just insert the same update statement between begin and end, like this:
    CREATE OR REPLACE PROCEDURE update_table
    AS
    BEGIN
    UPDATE table_to_update
    SET column_to_update_to =
    (SELECT table_to_compare.column_to_update_from
    FROM table_to_compare
    WHERE table_to_compare.comparison_column1 = table_to_update.comparison_column1
    AND table_to_compare.comparison_column2 = table_to_update.comparison_column2
    AND table_to_compare.comparison_column3 = table_to_update.comparison_column3)
    WHERE (table_to_update.comparison_column1, table_to_update.comparison_column2, table_to_update.comparison_column3) IN
    (SELECT table_to_compare.comparison_column1, table_to_compare.comparison_column2, table_to_compare.comparison_column3
    FROM table_to_compare);
    END update_table;
    Barbara
    null

  • Can i get help on procedures for amending passwords

    can any one help me write the procedures for creating user as well as amending the paaswords of userS??

    can any one help me write the procedures for creating user as well as amending the paaswords of userS??

  • Help regarding procedure

    hello,
    i juast want to know is oracle provide temporary procedure concept like ms-sql server provides .
    if yes please explain with example or post related links.
    if no then how can i achive it.
    i want to convert ms-sql server sp into oracle.
    any help appriciated
    thanks
    pankaj
    Message was edited by:
    Pankaj M

    Question is - what they are doing with this temporary procedure?
    Calling it just from the main proc?
    Then you can use just subprocedure in your main proc and call it whatever times you need:
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace procedure main_prc is
      2    procedure nested_prc is
      3    begin
      4      null;
      5    end;
      6  begin
      7    nested_prc;
      8    nested_prc;
      9    nested_prc;
    10    nested_prc;
    11    nested_prc;
    12* end;
    SQL> /
    Procedure created.If these are used in another sessions i.e. according to article above - global temporary procedures, then you just simply need to think about the design, because craeting objects on the fly is bad style, for example, what you should do if another session has already created that global temporary proc?
    It seems that temporary procedures just like temporary tables are probably used here without actually thinking whether they are useful or not.
    Gints Plivna
    http://www.gplivna.eu

  • Request some help, over procedure's performance uses regular expressions for its functinality

    Hi All,
            Below is the procedure, having functionalities of populating two tables. For first table, its a simple insertion process but for second table, we need to break the soruce record as per business requirement and then insert into the table. [Have used regular expressions for that]
            Procedure works fine but it takes around 23 mins for processing 1mm of rows.
            Since this procedure would be used, parallely by different ETL processes, so append hint is not recommended.
            Is there any ways to improve its performance, or any suggestion if my approach is not optimized?  Thanks for all help in advance.
    CREATE OR REPLACE PROCEDURE SONARDBO.PRC_PROCESS_EXCEPTIONS_LOGS_TT
         P_PROCESS_ID       IN        NUMBER, 
         P_FEED_ID          IN        NUMBER,
         P_TABLE_NAME       IN        VARCHAR2,
         P_FEED_RECORD      IN        VARCHAR2,
         P_EXCEPTION_RECORD IN        VARCHAR2
        IS
        PRAGMA AUTONOMOUS_TRANSACTION;
        V_EXCEPTION_LOG_ID     EXCEPTION_LOG.EXCEPTION_LOG_ID%TYPE;
        BEGIN
        V_EXCEPTION_LOG_ID :=EXCEPTION_LOG_SEQ.NEXTVAL;
             INSERT INTO SONARDBO.EXCEPTION_LOG
                 EXCEPTION_LOG_ID, PROCESS_DATE, PROCESS_ID,EXCEPTION_CODE,FEED_ID,SP_NAME
                ,ATTRIBUTE_NAME,TABLE_NAME,EXCEPTION_RECORD
                ,DATA_STRUCTURE
                ,CREATED_BY,CREATED_TS
             VALUES           
             (   V_EXCEPTION_LOG_ID
                ,TRUNC(SYSDATE)
                ,P_PROCESS_ID
                ,'N/A'
                ,P_FEED_ID
                ,NULL 
                ,NULL
                ,P_TABLE_NAME
                ,P_FEED_RECORD
                ,NULL
                ,USER
                ,SYSDATE  
            INSERT INTO EXCEPTION_ATTR_LOG
                EXCEPTION_ATTR_ID,EXCEPTION_LOG_ID,EXCEPTION_CODE,ATTRIBUTE_NAME,SP_NAME,TABLE_NAME,CREATED_BY,CREATED_TS,ATTRIBUTE_VALUE
            SELECT
                EXCEPTION_ATTR_LOG_SEQ.NEXTVAL          EXCEPTION_ATTR_ID
                ,V_EXCEPTION_LOG_ID                     EXCEPTION_LOG_ID
                ,REGEXP_SUBSTR(str,'[^|]*',1,1)         EXCEPTION_CODE
                ,REGEXP_SUBSTR(str,'[^|]+',1,2)         ATTRIBUTE_NAME
                ,'N/A'                                  SP_NAME    
                ,p_table_name
                ,USER
                ,SYSDATE
                ,REGEXP_SUBSTR(str,'[^|]+',1,3)         ATTRIBUTE_VALUE
            FROM
            SELECT
                 REGEXP_SUBSTR(P_EXCEPTION_RECORD, '([^^])+', 1,t2.COLUMN_VALUE) str
            FROM
                DUAL t1 CROSS JOIN
                        TABLE
                            CAST
                                MULTISET
                                    SELECT LEVEL
                                    FROM DUAL
                                    CONNECT BY LEVEL <= REGEXP_COUNT(P_EXCEPTION_RECORD, '([^^])+')
                                AS SYS.odciNumberList
                        ) t2
            WHERE REGEXP_SUBSTR(str,'[^|]*',1,1) IS NOT NULL
            COMMIT;
           EXCEPTION
             WHEN OTHERS THEN
             ROLLBACK;
             RAISE;
        END;
    Many Thanks,
    Arpit

    Regex's are known to be CPU intensive specially when dealing with large number of rows.
    If you have to reduce the processing time, you need to tune the Select statements.
    One suggested change could be to change the following query
    SELECT
                 REGEXP_SUBSTR(P_EXCEPTION_RECORD, '([^^])+', 1,t2.COLUMN_VALUE) str
            FROM
                DUAL t1 CROSS JOIN
                        TABLE
                            CAST
                                MULTISET
                                    SELECT LEVEL
                                    FROM DUAL
                                    CONNECT BY LEVEL <= REGEXP_COUNT(P_EXCEPTION_RECORD, '([^^])+')
                                AS SYS.odciNumberList
                        ) t2
    to
    SELECT REGEXP_SUBSTR(P_EXCEPTION_RECORD, '([^^])+', 1,level) str
    FROM DUAL
    CONNECT BY LEVEL <= REGEXP_COUNT(P_EXCEPTION_RECORD, '([^^])+')
    Before looking for any performance benefit, you need to ensure that this does not change your output.
    How many substrings are you expecting in the P_EXCEPTION_RECORD? If less than 5, it will be better to opt for SUBSTR and INSTR combination as it might work well with the number of records you are working with. Only trouble is, you will have to write different SUBSTR and INSTR statements for each column to be fetched.
    How are you calling this procedure? Is it not possible to work with Collections? Delimited strings are not a very good option as it requires splitting of the data every time you need to refer to.

  • Help passing procedure parameter

    I created a pl/sql collection. Now i want to pass the whole collection into a procedure and then loop through the collection inside the procedure to find out if a particular attribute is existing in it.
    I am not able to figure out how can I do that.Do i have to use a refcursor or something? please help. Its kind of urgent

    > I created a pl/sql collection. Now i want to pass the
    whole collection into a procedure and then loop
    through the collection inside the procedure to find
    out if a particular attribute is existing in it.
    Why?
    Two good reason not to do it like this come to mind.
    Data is better and faster and easier and more performant to handle as Oracle data (aka data/rows in a table) - not as data inside a PL/SQL array. SQL allows you to sort, group by, filter, transform, analyse and so on. Oracle allows you to index and partition that data.
    PL/SQL in comparison cannot do any of this.
    The second reason is memory. It requires PGA (Process Global Area) to store data in PL/SQL. PGA is expensive as it is a dedicated resource. It can only service a single process. The SGA in turn (and its db buffer cache) services all Oracle sessions. So 1MB spend of system memory spend on the SGA has a lot more bite in the byte than 1MB spend on the PGA.
    No, I'm not saying that these two reasons are absolutes and that PL/SQL collections/arrays are a bad thing. Simply that you need better reasons than these to justify throwing data into a collection and using a FOR LOOP to iterate through the data looking for something - especially when this is exactly what Oracle tables and Oracle SQL do brilliantly.
    > Its kind of urgent
    Arrgghh.. this is where I usually get on my soapbox and tell you that it is rude to assume that your problem is more urgent than other posters' problems here. And that it is arrogant to insist on that those (with paying jobs) provides answers and support here for free, give immediate attention to your problem.
    So please, unless you like to see me foam at the mouth and wave my lead pipe in your general direction, do not claim that your problem is urgent when posting here (or any other similar forum for that matter).

  • Help Approval Procedures

    Hi All
    I'm not sure if this is possible in SBO, I want to know how can a user (Finance department admin clerk ) capture an invoice (Purchase Invoice) and then selects the person who is the Head for that department to receive it.
    N.B. Approval Procedure are active for Invoices added on the system. Currently the setup is if a Finance user captures an Invoice irrespective of the value, the invoice must be sent for approval to all the GM's ( General Managers).
    Now a problem is when it is sent to all the GM's a mistake can happen when a GM is in a hurry or (s)he approves another departments invoice.
    I was thinking of activating data ownership and specifying the rules for each user.
    Is there another way where only Purchase Invoices for each department be sent to that particular department when the Approval Procedures are active?
    Thanks
    Bongani Dlamini

    Hi Suda
    Invoices are captured by the Finance department , so when the user presses add an approval procedure is launched to all the departments.
    This is causing inconviences as some users only get one or two invoices in two weeks and other more than 10 invoices a day.
    So if a user in finance captures an invoice for any department between the 6 departments the invoice approval must be launched for that department head only.
    Hope this helps.
    Bongani

  • Help Me procedure

    create or replace
    PROCEDURE test
    (p_acqurier_inst_id IN VARCHAR2,
    p_card_no in varchar2,
    p_TXN_PASSCODE in varchar2,
    p_merchant_id in varchar2,
    p_trancode in varchar2,
    v_MCC_CODE in varchar2,
    V_CONNECTION_AADHAAR out varchar2,
    V_BIOMETRIC_VALIDATION out varchar2,
    V_AUA_KEY out nocopy varchar2,
    v_FISP_TYPE out nocopy varchar2,
    v_RSP_CODE out nocopy varchar2,
    status out nocopy VARCHAR2
    ) IS
    count_ind NUMBER (5);
    count_ind1 NUMBER (5);
    BEGIN
    SELECT COUNT(*) INTO count_ind1
    from f_merchant fm inner join b_config bc
    on fm.merchant_id = p_merchant_id and fm.transaction_passcode = p_TXN_PASSCODE and fm.mcc_code = v_MCC_CODE and bc.aadhaar_acq_bankid = p_acqurier_inst_id and bc.bank_id = fm.bank_id group by bc.AUA_KEY, fm.FISP_TYPE ;
    IF count_ind1 > 0 THEN
    SELECT count(*), bc.AUA_KEY, fm.FISP_TYPE
    INTO count_ind,V_AUA_KEY,v_FISP_TYPE
    from f_merchant fm inner join b_config bc
    on fm.merchant_id = p_merchant_id and fm.transaction_passcode = p_TXN_PASSCODE and fm.mcc_code = v_MCC_CODE and bc.aadhaar_acq_bankid = p_acqurier_inst_id and bc.bank_id = fm.bank_id group by bc.AUA_KEY, fm.FISP_TYPE ;
    IF (count_ind > 0) then
    SELECT COUNT (*)
    INTO count_ind
    FROM b_config bc inner join TRANCODE_LINK_INFO tli
    on bc.aadhaar_acq_bankid = p_acqurier_inst_id and
    tli.bank_id = bc.bank_id and bc.BANK_ID=substr(p_card_no,1,6)
    and rownum =1;
    IF (count_ind > 0) THEN
    status := 'ONUSUID';
    dbms_output.put_line('status');
    ELSE
    SELECT COUNT (*)
    INTO count_ind
    FROM b_config bc inner join a_bank_bin bnn
    on bc.aadhaar_acq_bankid = p_acqurier_inst_id AND
    bnn.BANK_BIN_ID= substr(p_card_no,1,6) and
    bnn.bank_id=bc.bank_id and rownum=1;
    IF (count_ind > 0) THEN
    status := 'OFFUSUID';
    dbms_output.put_line('status');
    ELSE
    SELECT COUNT (*) into count_ind
    FROM b_config bc, CARD_PREFIX_INFO cpi,TRANCODE_LINK_INFO tli
    Where bc.aadhaar_acq_bankid = p_acqurier_inst_id and cpi.card_prefix= SUBSTR (p_card_no,1,6) and cpi.bank_id=bc.bank_id and
    tli.BANK_ID=cpi.BANK_ID AND ROWNUM=1 and bc.bank_id=tli.bank_id;
    IF (count_ind > 0) THEN
    status := 'ONUSNONUID';
    dbms_output.put_line('status');
    END IF;
    END IF;
    END IF;
    if (status='ONUSUID') then v_RSP_CODE :='00';
    elsif (status='OFFUSUID') then v_RSP_CODE:='00';
    elsif (status='ONUSNONUID')then v_RSP_CODE:='00';
    elsif (status is NULL) then v_RSP_CODE:='14' ;
    end if;
    IF((status='ONUSUID') OR (status='OFFUSUID') OR (status='ONUSNONUID')) THEN
    IF(status='ONUSUID') THEN
    SELECT ic.CONNECTION_AADHAAR,ic.BIOMETRIC_VALIDATION,m.AUA_KEY into V_CONNECTION_AADHAAR,V_BIOMETRIC_VALIDATION,V_AUA_KEY
    FROM b_config bc ,i_config ic,f_merchant m , trancode_link_info tli
    WHERE bc.bank_id =SUBSTR(p_card_no,1,6) and bc.BANK_ID=ic.BANK_ID and m.MERCHANT_ID=p_merchant_id AND tli.tran_code = p_trancode and tli.bank_id = m.bank_id and bc.aadhaar_acq_bankid = p_acqurier_inst_id;
    ELSIF(status='OFFUSUID') THEN
    SELECT ic.CONNECTION_AADHAAR,ic.BIOMETRIC_VALIDATION,m.AUA_KEY into V_CONNECTION_AADHAAR,V_BIOMETRIC_VALIDATION,V_AUA_KEY
    FROM a_bank_bin bnn ,i_config ic,f_merchant m,b_config bc
    WHERE m.MERCHANT_ID=p_merchant_id and ic.bank_id = m.bank_id and bnn.bank_bin_id=SUBSTR(p_card_no,1,6) and bnn.tran_code like '%'|| p_trancode ||'%'
    and bc.aadhaar_acq_bankid =p_acqurier_inst_id and bc.bank_id= bnn.bank_id;
    ELSIF(status='ONUSNONUID') THEN
    SELECT ic.CONNECTION_AADHAAR,ic.BIOMETRIC_VALIDATION,m.AUA_KEY into V_CONNECTION_AADHAAR,V_BIOMETRIC_VALIDATION,V_AUA_KEY
    FROM CARD_PREFIX_INFO cpi,i_config ic,f_merchant m,trancode_link_info tli,b_config bc
    WHERE cpi.BANK_ID=ic.BANK_ID and
    m.MERCHANT_ID=p_merchant_id and cpi.CARD_PREFIX=SUBSTR(p_card_no,1,6) and tli.tran_code=p_trancode and bc.aadhaar_acq_bankid=p_acqurier_inst_id;
    END IF;
    ELSE
    v_RSP_CODE :='77';
    END IF;
    ELSE
    v_RSP_CODE :='77';
    END IF;
    END test;
    I am poor in pl/sql can you help me please
    --bolded code is for finding weather onusuid or offusuid or onusnonuid
    --after that one i want to check weather the given IN  parameters
    i want to check the following
    1)if all the in parameters are null then i have to return v_rsp_code=14
    2)if p_card_no not matches i have to return v_rsp_code=15
    3)in beginning if p_TXN_PASSCODE does not matches it has to return v_rsp_code=77;
    4)if mcc_code fails i have to return v_rsp_code=66;
    how i have to change the above code please tell me

    Are you after something like (your code omitted to get the idea clearly)
    create or replace
    PROCEDURE test(p_acqurier_inst_id IN VARCHAR2,
                   p_card_no in varchar2,
                   p_TXN_PASSCODE in varchar2,
                   p_merchant_id in varchar2,
                   p_trancode in varchar2,
                   v_MCC_CODE in varchar2,
                   V_CONNECTION_AADHAAR out varchar2,
                   V_BIOMETRIC_VALIDATION out varchar2,
                   V_AUA_KEY out nocopy varchar2,
                   v_FISP_TYPE out nocopy varchar2,
                   v_RSP_CODE out nocopy varchar2,
                   status out nocopy VARCHAR2
                  ) IS
      the_diagnose varchar2(1000);
    begin
      select d.diagnose ||
             case when fm.transaction_passcode != p_TXN_PASSCODE
                  then '77,' /* no matching passcode */
             end ||
             case when fm.mcc_code != v_MCC_CODE
                  then '66,' /* no matching mcc */
             end ||
             case when bc.bank_id != substr(p_card_no
                  then '15,' /* no matching card */
             end ||
             case when bc.aadhaar_acq_bankid != p_acqurier_inst_id
                  then '33,' /* no matching acquirer */
             end || '00'
        into the_diagnose
        from (select case when coalesce(p_acqurier_inst_id,p_card_no,p_TXN_PASSCODE,p_merchant_id,p_trancode,v_MCC_CODE) is null
                          then '14,' /* all in params are null */
                     end ||
                     case when not exists(select null
                                            from f_merchant
                                           where merchant_id = p_merchant_id
                          then '55,' /* no merchant */
                     end ||
                     case when not exists(select null
                                            from b_config
                                           where bank_id = (select bank_id
                                                              from f_merchant
                                                             where merchant_id = p_merchant_id
                          then '44,' /* no merchant's bank */
                     end diagnose
                from dual
             ) d,
             (select bank_id_id,transaction_passcode,mcc_code
                     from f_merchant
                    where merchant_id = p_merchant_id
             ) fm,
             (select bank_id,aadhaar_acq_bankid
                from b_config
               where aadhaar_acq_bankid = p_acqurier_inst_id
             ) bc
       where bc.bank_id = fm.bank_id;
      v_RSP_CODE := substr(the_diagnose,1,2);
    /* v_RSP_CODE := rtrim(the_diagnose,','); would return all errors */
    end test;Regards
    Etbin
    Edited by: Etbin on 19.1.2012 0:10
    the formatted code for those who might be interested
    create or replace
    PROCEDURE test(p_acqurier_inst_id IN VARCHAR2,
                   p_card_no in varchar2,
                   p_TXN_PASSCODE in varchar2,
                   p_merchant_id in varchar2,
                   p_trancode in varchar2,
                   v_MCC_CODE in varchar2,
                   V_CONNECTION_AADHAAR out varchar2,
                   V_BIOMETRIC_VALIDATION out varchar2,
                   V_AUA_KEY out nocopy varchar2,
                   v_FISP_TYPE out nocopy varchar2,
                   v_RSP_CODE out nocopy varchar2,
                   status out nocopy VARCHAR2
                  ) IS
      count_ind  NUMBER (5);
      count_ind1 NUMBER (5);
    BEGIN
      SELECT COUNT(*)
        INTO count_ind1
        from f_merchant fm
             inner join
             b_config bc
          on (fm.merchant_id = p_merchant_id
         and  fm.transaction_passcode = p_TXN_PASSCODE
         and  fm.mcc_code = v_MCC_CODE
         and  bc.aadhaar_acq_bankid = p_acqurier_inst_id
         and  bc.bank_id = fm.bank_id
       group by bc.AUA_KEY,fm.FISP_TYPE ;
      IF count_ind1 > 0 THEN
        SELECT count(*),bc.AUA_KEY,fm.FISP_TYPE
          INTO count_ind,V_AUA_KEY,v_FISP_TYPE
          from f_merchant fm
               inner join
               b_config bc
            on (fm.merchant_id = p_merchant_id
           and  fm.transaction_passcode = p_TXN_PASSCODE
           and  fm.mcc_code = v_MCC_CODE
           and  bc.aadhaar_acq_bankid = p_acqurier_inst_id
           and  bc.bank_id = fm.bank_id
         group by bc.AUA_KEY,fm.FISP_TYPE ;
        IF (count_ind > 0) then
          SELECT COUNT (*)
            INTO count_ind
            FROM b_config bc
                 inner join
                 TRANCODE_LINK_INFO tli
              on (bc.aadhaar_acq_bankid = p_acqurier_inst_id
             and  tli.bank_id = bc.bank_id
             and  bc.BANK_ID = substr(p_card_no,1,6)
             and  rownum = 1
          IF (count_ind > 0) THEN
            status := 'ONUSUID';
            dbms_output.put_line('status');
          ELSE
            SELECT COUNT (*)
              INTO count_ind
              FROM b_config bc
                   inner join
                   a_bank_bin bnn
                on (bc.aadhaar_acq_bankid = p_acqurier_inst_id
               AND  bnn.BANK_BIN_ID = substr(p_card_no,1,6)
               and  bnn.bank_id = bc.bank_id
               and  rownum = 1
            IF (count_ind > 0) THEN
              status := 'OFFUSUID';
              dbms_output.put_line('status');
            ELSE
              SELECT COUNT (*)
                into count_ind
                 FROM b_config bc,
                      CARD_PREFIX_INFO cpi,
                      TRANCODE_LINK_INFO tli
                Where bc.aadhaar_acq_bankid = p_acqurier_inst_id
                  and cpi.card_prefix = SUBSTR(p_card_no,1,6)
                  and cpi.bank_id = bc.bank_id
                  and tli.BANK_ID = cpi.BANK_ID
                  AND ROWNUM = 1
                  and bc.bank_id=tli.bank_id;
              IF (count_ind > 0) THEN
                status := 'ONUSNONUID';
                dbms_output.put_line('status');
              END IF;
            END IF;
          END IF;
        if (status = 'ONUSUID') then
          v_RSP_CODE := '00';
        elsif (status = 'OFFUSUID') then
          v_RSP_CODE := '00';
        elsif (status = 'ONUSNONUID')then
          v_RSP_CODE := '00';
        elsif (status is NULL)
          then v_RSP_CODE := '14';
        end if;
        IF((status = 'ONUSUID') OR (status = 'OFFUSUID') OR (status = 'ONUSNONUID')) THEN
          IF(status = 'ONUSUID') THEN
            SELECT ic.CONNECTION_AADHAAR,ic.BIOMETRIC_VALIDATION,m.AUA_KEY
              into V_CONNECTION_AADHAAR,V_BIOMETRIC_VALIDATION,V_AUA_KEY
              FROM b_config bc,
                   i_config ic,
                   f_merchant m ,
                   trancode_link_info tli
             WHERE bc.bank_id = SUBSTR(p_card_no,1,6)
               and bc.BANK_ID = ic.BANK_ID
               and m.MERCHANT_ID = p_merchant_id
               AND tli.tran_code = p_trancode
               and tli.bank_id = m.bank_id
               and bc.aadhaar_acq_bankid = p_acqurier_inst_id;
          ELSIF(status = 'OFFUSUID') THEN
            SELECT ic.CONNECTION_AADHAAR,ic.BIOMETRIC_VALIDATION,m.AUA_KEY
              into V_CONNECTION_AADHAAR,V_BIOMETRIC_VALIDATION,V_AUA_KEY
              FROM a_bank_bin bnn,
                   i_config ic,
                   f_merchant m,
                   b_config bc
             WHERE m.MERCHANT_ID = p_merchant_id
               and ic.bank_id = m.bank_id
               and bnn.bank_bin_id = SUBSTR(p_card_no,1,6)
               and bnn.tran_code like '%'|| p_trancode ||'%'
               and bc.aadhaar_acq_bankid = p_acqurier_inst_id
               and bc.bank_id= bnn.bank_id;
          ELSIF(status = 'ONUSNONUID') THEN
            SELECT ic.CONNECTION_AADHAAR,ic.BIOMETRIC_VALIDATION,m.AUA_KEY
              into V_CONNECTION_AADHAAR,V_BIOMETRIC_VALIDATION,V_AUA_KEY
              FROM CARD_PREFIX_INFO cpi,
                   i_config ic,f_merchant m,
                   trancode_link_info tli,
                   b_config bc
             WHERE cpi.BANK_ID = ic.BANK_ID
               and m.MERCHANT_ID=p_merchant_id
               and cpi.CARD_PREFIX = SUBSTR(p_card_no,1,6)
               and tli.tran_code = p_trancode
               and bc.aadhaar_acq_bankid = p_acqurier_inst_id;
          END IF;
        ELSE
          v_RSP_CODE := '77';
        END IF;
      ELSE
        v_RSP_CODE := '77';
      END IF;
    END test;

  • Help in procedure

    Thnx all of u for the support...
    The procedure is giving the below error at line 33 after execution...
    CREATE OR REPLACE PROCEDURE Dwh_PrdC_Sum_Qtdytd_2401(V_TBL_NAME IN VARCHAR2,V_COL_NAM IN VARCHAR2,V_RPRT_DATE DATE, V_FLTRCOL IN VARCHAR2, GRoup_COL in varchar2, GRoup_COL2 in varchar2 )
    is
    V_REPORT_DATE DATE:=V_RPRT_DATE;
    V_FILTERCOL VARCHAR2(30):=UPPER(V_FLTRCOL);
    V_COL_NAME VARCHAR2(30):=UPPER(V_COL_NAM);
    V_TAB_NAME VARCHAR2(30):=UPPER(V_TBL_NAME);
    V_GRP_COL VARCHAR2(30):=UPPER(GRoup_COL);
    V_GRP_COL2 VARCHAR2(30):=UPPER(GRoup_COL2);
    V_CURRMNTH_STRT VARCHAR2(11);
    V_CURRMNTH_END VARCHAR2(11);
    V_PRVMNTH_STRT VARCHAR2(11);
    V_PRVMNTH_END VARCHAR2(11);
    V_CURRMNTH VARCHAR2(1000);
    V_PRVMNTH VARCHAR2(1000);
    V_CURRMNTH_SUM NUMBER(14,3):=0;
    V_PRBMNTH_SUM NUMBER(14,3):=0;
    A_RET_VALUE NUMBER(14,3):=0;
    BEGIN
    EXECUTE IMMEDIATE('TRUNCATE TABLE TEST_X');
    -------------------GETTING START_END DATE OF THE MONTH-----------------------------------------
    select TRUNC(to_date(V_REPORT_DATE),'MON') INTO V_CURRMNTH_STRT FROM DUAL;
    SELECT LAST_DAY (V_CURRMNTH_STRT) INTO V_CURRMNTH_END FROM DUAL;
    DBMS_OUTPUT.PUT_LINE (V_CURRMNTH_STRT||'          '||V_CURRMNTH_END);
    -------------------START_END DATE OF PRV_MONTH-------------------------------------------------
    SELECT TRUNC(trunc(to_date(V_REPORT_DATE),'MON')-1,'MON') INTO V_PRVMNTH_STRT FROM DUAL;
    SELECT LAST_DAY (V_PRVMNTH_STRT) INTO V_CURRMNTH_END FROM DUAL;
    DBMS_OUTPUT.PUT_LINE (V_PRVMNTH_STRT||'          '||V_PRVMNTH_END);
    --------------------CURRENT QUARTER VALUE------------------------------------------------------
    -------------------CURRENT MONTH VALUE---------------------------------------------------------
    V_CURRMNTH:='INSERT INTO TEST_X SELECT '||V_GRP_COL||', '||V_GRP_COL2||', SUM('||V_COL_NAME||'),0 FROM  '||V_TAB_NAME||' WHERE '||V_FILTERCOL||' BETWEEN   TO_DATE('''||V_CURRMNTH_STRT||''') ' || '  AND  TO_DATE('''||V_CURRMNTH_END||''') GROUP BY  '||V_GRP_COL||','||V_GRP_COL2||'
    UNION
    SELECT '||V_GRP_COL||', '||V_GRP_COL2||',0, SUM('||V_COL_NAME||')  FROM  '||V_TAB_NAME|| ' WHERE '||V_FILTERCOL||' BETWEEN   TO_DATE('''||V_PRVMNTH_STRT||''') ' || '  AND  TO_DATE('''||V_PRVMNTH_END||''')  GROUP BY  '||V_GRP_COL||','||V_GRP_COL2||'';
    EXECUTE IMMEDIATE V_CURRMNTH using V_CURRMNTH_STRT, V_CURRMNTH_END, V_PRVMNTH_STRT, V_PRVMNTH_END;----here
    commit;
    END;
    / ERROR
    ERROR at line 1:
    ORA-01006: bind variable does not exist
    ORA-06512: at "UTL.DWH_PRDC_SUM_QTDYTD_2401", line 33
    ORA-06512: at line 1Edited by: 977490 on Jan 24, 2013 9:33 PM

    Thnx....
    It's been done without the help of you, Purvesh and other experts I wasn't able to do....
    No my code looks like
    CREATE OR REPLACE PROCEDURE Dwh_Prdc_SumQtdytd_tst(p_tbl_name  in varchar2
                                                              ,p_col_nam   in varchar2
                                                              ,p_rprt_date in date    
                                                              ,p_fltcol    in varchar2
                                                              ,p_group_col   in varchar2
                                                              ,p_group_col2  in varchar2
                                                              ) is
      v_currmnth_strt  date             := trunc(p_rprt_date,'MM');
      v_currmnth_end   date             := last_day(v_currmnth_strt);
      v_prvmnth_strt   date             := add_months(v_currmnth_strt,-1);
      v_prvmnth_end    date             := last_day(v_prvmnth_strt);
      v_currqtr_strt   date             := trunc(to_date(p_rprt_date), 'Q');
      v_currqtr_end    date             := add_months(trunc(to_date(v_currqtr_strt), 'q'), 3)-1;
      v_prvqtr_strt    date             := trunc(add_months(p_rprt_date, -3), 'q');
      v_prvqtr_end     date             := add_months(trunc(add_months(p_rprt_date, -3), 'q'), 3) - 1;
      v_currytd_strt   date             := add_months(trunc(add_months(p_rprt_date, -3), 'YYYY'), 3);
      v_currytd_end    date             := add_months(v_currytd_strt, 12)- 1;
      v_prvyr_smdt     date             := add_months(to_date(p_rprt_date),-12);
      v_prvytd_strt    date             := add_months(trunc(add_months(v_prvyr_smdt, -3), 'YYYY'), 3);
      v_prvytd_end     date             := add_months(v_prvytd_strt, 12)- 1;
      v_prvyrmnth_strt date             := trunc(to_date(v_prvyr_smdt),'MM');
      v_prvyrmnth_end  date             := last_day(v_prvyrmnth_strt);
      v_sql            varchar2(32767);
      dtformat         varchar2(30) := 'DD-MON-YYYY';
    begin
      execute immediate('truncate table test_x');
      dbms_output.put_line('Current Month : '||to_char(v_currmnth_strt,dtformat)||'          '||to_char(v_currmnth_end,dtformat));
      dbms_output.put_line('Previous Month: '||to_char(v_prvmnth_strt,dtformat)||'          '||to_char(v_prvmnth_end,dtformat));
      dbms_output.put_line('Current Quarter : '||to_char(v_currqtr_strt,dtformat)||'          '||to_char(v_currqtr_end,dtformat));
      dbms_output.put_line('Previous Quarter : '||to_char(v_prvqtr_strt,dtformat)||'          '||to_char(v_prvqtr_end,dtformat));
      dbms_output.put_line('Current YTD : '||to_char(v_currytd_strt,dtformat)||'          '||to_char(v_currytd_end,dtformat));
      dbms_output.put_line('Previous YR Month : '||to_char(v_prvyr_smdt,dtformat));
      dbms_output.put_line('Previous YTD : '||to_char(v_prvytd_strt,dtformat)||'          '||to_char(v_prvytd_end,dtformat));
      dbms_output.put_line('Previous YR Same Month : '||to_char(v_prvyrmnth_strt,dtformat)||'          '||to_char(v_prvyrmnth_end,dtformat));
    v_sql:='insert into test_x select '||p_group_col||', '||p_group_col2||', sum('||p_col_nam||'),0, 0, 0, 0, 0, 0 from  '||p_tbl_name||' where '||p_fltcol||' between   to_date(:v_currmnth_strt) and  to_date(:v_currmnth_end) group by  '||p_group_col||','||p_group_col2||'
      union
      select '||p_group_col||', '||p_group_col2||',0, sum('||p_col_nam||'),0, 0, 0, 0, 0 from  '||p_tbl_name|| ' where '||p_fltcol||' between   to_date(:v_prvmnth_strt)  and  to_date(:v_prvmnth_end)  group by  '||p_group_col||','||p_group_col2||'
      union
      select '||p_group_col||', '||p_group_col2||',0, 0, sum('||p_col_nam||'),0, 0, 0, 0 from  '||p_tbl_name|| ' where '||p_fltcol||' between   to_date(:v_currqtr_strt)  and  to_date(:v_currqtr_end)  group by  '||p_group_col||','||p_group_col2||'
      union
      select '||p_group_col||', '||p_group_col2||',0, 0, 0, sum('||p_col_nam||'),0, 0, 0 from  '||p_tbl_name|| ' where '||p_fltcol||' between   to_date(:v_prvqtr_strt)  and  to_date(:v_prvqtr_end)  group by  '||p_group_col||','||p_group_col2||'
      union
      select '||p_group_col||', '||p_group_col2||',0, 0, 0, 0, sum('||p_col_nam||'),0, 0 from  '||p_tbl_name|| ' where '||p_fltcol||' between   to_date(:v_currytd_strt)  and  to_date(:v_currytd_end)  group by  '||p_group_col||','||p_group_col2||'
      union
      select '||p_group_col||', '||p_group_col2||',0, 0, 0, 0, 0, sum('||p_col_nam||'),0  from  '||p_tbl_name|| ' where '||p_fltcol||' between   to_date(:v_prvytd_strt)  and  to_date(:v_prvytd_end)  group by  '||p_group_col||','||p_group_col2||'
      union
      select '||p_group_col||', '||p_group_col2||',0, 0, 0, 0, 0, 0, sum('||p_col_nam||')  from  '||p_tbl_name|| ' where '||p_fltcol||' between   to_date(:v_prvyrmnth_strt)  and  to_date(:v_prvyrmnth_end)  group by  '||p_group_col||','||p_group_col2||'';
    execute immediate v_sql using v_currmnth_strt, v_currmnth_end, v_prvmnth_strt, v_prvmnth_end, v_currqtr_strt, v_currqtr_end, v_prvqtr_strt, v_prvqtr_end, v_currytd_strt, v_currytd_end, v_prvytd_strt, v_prvytd_end, v_prvyrmnth_strt, v_prvyrmnth_end;
    commit;
    end;
    /Thnx all of you once again....and still suggestions will be appreciated....

  • Help: stored procedure for oracle forms

    Hi,
    I am working on a form with data block based on stored procedures. Here is the question:
    On a data block based on simple query, where insert a new record is taking care of by oracle form. That is create_record will do the job.
    When the data block is based on stored procedures, select, update, insert and delete will have to based on the data block created by the ref curcor. How to call the stored procedure from form to create a new record?
    I attempted to write something like:
    PROCEDURE sample_insert
    data_block IN OUT some_refcurcor) IS
    BEGIN
    insert into some_table values
    (data_block.field1, data_block.field2.....);
    commit;
    END;
    I am not quit sure how this works, as would create_record buildin will work to clean up the FORM data block and allow user to enter data and when and how the sample_insert will be called to make this work? Or how the same effect will work out as none stored procedure would do. New data eventually get into the designated table.
    Any suggestions are greatly appreciated.
    Jimmy
    Correction: (data_block IN OUT some_refcurcor) should be (data_block IN OUT some_table) and some_table is a record type etc..
    Message was edited by:
    WJH

    Hello,
    there are two kinds of output from a stored procedure which can be used in a forms block:
    - ref cursor
    - table of records
    The easiest way is to use a ref cursor. Use a strongly typed one,
    so that you can see the columns in the block wizard.
    A table of records is used when you also want to insert, update and so on.
    There is a not on metalink note for this ( 66887.1 ).
    Bernd

  • Need some help on procedure calling procedure using object type reg

    dear all,
    i need to test one procedure by passing only one value but how do i pass single value. i am showing the details of few section on which i am working on. here is few details about the package.
    Description: package pkj_emp contains two procedure pkj_emp and procedure proc_rem.
    purpose:based on passing dname values to procedure pkj_emp, cursor cur_emp will fetch empid from emp table and then we are passing 4 empid records to procedure proc_rem using empid object type.Inside the procedure proc_rem it will delete all 4 records of table A,B,C and D at one short.
    Requirement:i need to test for only one value that means is it possible i can pass only one value using the cursor cur_emp.
    create or replace package pkj_emp
    TYPE obj_emp IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
    procedure proc_emp(empid obj_emp);
    create or replace package body pkj_emp
    as
    procedure(
    dname varchar2;
    as
    cursor cur_emp is select emp_id from emp a,dept d
    where a.deptid=d.deptid
    and d.deptname=dname;
    begin
    count:=0;
                   for cur_emp_rec in cur_emp LOOP
                   empid(count) := cur_emp_rec.emp_id;
              IF (count = 4) THEN
                   proc_rem(empid); // calling another procedure
                   commit;
                   END IF;
                   count := count + 1;
                   END LOOP;
    end;
    proc_rem(
    empid obj_emp;
    is
    begin
    delete from A where emp_id in (empid(0),empid(1),empid(2),empid(3));
    delete from B where emp_id in (empid(0),empid(1),empid(2),empid(3));
    delete from c where emp_id in (empid(0),empid(1),empid(2),empid(3));
    delete from d where emp_id in (empid(0),empid(1),empid(2),empid(3));
    end;
    regards
    Laxman

    You have hardcoded your IN LIST in the REM procedure. I recommend changing the code to take a variable number of inputs. You could do something like the following:
    SQL> CREATE TABLE A (ID NUMBER);
    Table created.
    SQL> CREATE TABLE B (ID NUMBER);
    Table created.
    SQL> CREATE TABLE C (ID NUMBER);
    Table created.
    SQL> CREATE TABLE D (ID NUMBER);
    Table created.
    SQL> INSERT INTO A VALUES(7566);
    1 row created.
    SQL> INSERT INTO B VALUES(7902);
    1 row created.
    SQL> INSERT INTO C VALUES(7876);
    1 row created.
    SQL> INSERT INTO D VALUES(7369);
    1 row created.
    SQL> CREATE OR REPLACE TYPE EMP_TYPE AS TABLE OF NUMBER(4);
      2  /
    Type created.
    SQL> CREATE OR REPLACE PACKAGE PKJ_EMP
      2  AS
      3          PROCEDURE PKJ_EMP
      4          (
      5                  DNAME   IN      SCOTT.EMP.DEPTNO%TYPE
      6          );
      7 
      8          PROCEDURE REM
      9          (
    10                  pEMPList  IN      EMP_TYPE
    11          );
    12  END PKJ_EMP;
    13  /
    Package created.
    SQL> CREATE OR REPLACE PACKAGE BODY PKJ_EMP
      2  AS
      3          PROCEDURE PKJ_EMP
      4          (
      5                  DNAME   IN      SCOTT.EMP.DEPTNO%TYPE
      6          )
      7          AS
      8                  pEMPList        EMP_TYPE := EMP_TYPE();
      9                  i               NUMBER := 1;
    10          BEGIN
    11                  FOR r IN
    12                  (
    13                          SELECT  EMPNO
    14                          FROM    SCOTT.EMP
    15                          WHERE   DEPTNO = DNAME
    16                  )
    17                  LOOP
    18                          pEMPList.EXTEND;
    19                          pEMPList(i) := r.EMPNO;
    20 
    21                          i := i + 1;
    22                  END LOOP;
    23 
    24                  REM(pEMPList);
    25          END PKJ_EMP;
    26 
    27          PROCEDURE REM
    28          (
    29                  pEMPList  IN      EMP_TYPE
    30          )
    31          AS
    32          BEGIN
    33                  DELETE FROM A WHERE ID IN (SELECT   COLUMN_VALUE FROM TABLE(pEMPList));
    34                  DELETE FROM B WHERE ID IN (SELECT   COLUMN_VALUE FROM TABLE(pEMPList));
    35                  DELETE FROM C WHERE ID IN (SELECT   COLUMN_VALUE FROM TABLE(pEMPList));
    36                  DELETE FROM D WHERE ID IN (SELECT   COLUMN_VALUE FROM TABLE(pEMPList));
    37          END REM;
    38  END PKJ_EMP;
    39  /
    Package body created.
    SQL> EXEC PKJ_EMP.PKJ_EMP(20);
    PL/SQL procedure successfully completed.
    SQL> SELECT * FROM A;
    no rows selected
    SQL> SELECT * FROM B;
    no rows selected
    SQL> SELECT * FROM C;
    no rows selected
    SQL> SELECT * FROM D;
    no rows selected
    SQL> spool off;HTH!

Maybe you are looking for

  • Error in starting OWB repository browser listener

    Hi, I got the following error when starting owb repository browser listener on Solaris with startOwbbInst.sh Exception in thread "main" java.lang.NoClassDefFoundError: javax.servlet.Servlet at com.evermind.server.ApplicationServer.class$(ApplicationS

  • Import from Excel to SQL (in code)

    I need to import data from an Excel file (2010) into my SQL database. These are my current driver setting Microsoft Excel Driver 6.01 Microsoft Excel Driver 14.00 Microsoft Excel-Treiber 6.01 I'm trying to execute the code below, but having no luck i

  • Connection to Fastmail.fm

    Up until this morning I've been able to send/receive email via my Motorola Droid Bionic.  Suddenly I'm getting error notifications telling me that I have a "connection" error. I've verified my configuration and even tried some others to no avail.  I

  • Blank lines on black print output

    We are seeing blank lines for the black print head.  We replaced the cartridge and ran 1,2,3 level print head cleaning with no improvement.  Ran diagnostics, but I can't see any differences in that report between the different color cartridges.  

  • Remediation Workflow - 2 Total Attempts per Question Scenario

    I'm trying to accomplish the following with all of my quiz slides - I want the user to have only 2 attempts to answer the question correctly before 'failing' the question and having to move to the next one. This is the expected outcome: User answers