Pl/sql block wrong ?

Can someone tell me why it is failing
create or replace
procedure UPDATE_EMP(p_empno number,p_decrease number)is
V_sal number;
begin
update EMP
set SAL =SAL /p_decrease
where empno =p_empno;
commit;
select sal into v_sal from emp where empno = p_empno;
dbms_output.put_line('new reduced salary is ' v_sal );
end;
gives me an error :
Error(9,53): PLS-00103: Encountered the symbol "V_SAL" when expecting one of the following: ) , * & | = - + < / > at in is mod remainder not rem => .. <an exponent (**)> <> or != or ~= >= <= <> and or like LIKE2_ LIKE4_ LIKEC_ as between from using || multiset member SUBMULTISET_ The symbol "," was substituted for "V_SAL" to continue.
Any help is appreciated ..!
Thanks
Jack

Yepp
got it Thanks for the catch ;-)
J

Similar Messages

  • What is the wrong in this PL/SQL  block

    Hi a...
    Can you please tell what is the wrong in this pl/sql block.
    declare
    TYPE TYP_NT_NUM IS TABLE OF NUMBER ;
    v_tab TYP_NT_NUM := TYP_NT_NUM();
    TYPE uname is VARRAY(30) of varchar2(100) ;
    usr uname := uname ( 'u1','u2','u3','u4' );
    TYPE pwd is VARRAY(30) of varchar2(100) ;
    psw pwd := pwd('p1','p2','p3','p4');
    x number(10):=0;
    Cursor fcid IS Select distinct FC_ID From FCMASTER ;
    Begin
    Open fcid ;
    --for ii in usr.first .. usr.last loop
         Loop
              Fetch fcid Into x ;
              Exit When fcid%NOTFOUND ;
              v_tab(fcid%ROWCOUNT) := x ;
         End loop ;
         For iii IN v_tab.FIRST .. v_tab.LAST Loop
              dbms_output.put_line(v_tab(iii).FC_ID) ;
              End loop ;
    End loop; End of outer loop
    End;
    The error is
    Error
    [row:28,col:36] ORA-06550: line 28, column 36:
    PLS-00487: Invalid reference to variable 'NUMBER'
    ORA-06550: line 28, column 4:
    PL/SQL: Statement ignored
    Thanks in advance,
    Pal

    v_tab(iii).FC_ID
    declare
      type typ_nt_num is table of number;
      v_tab typ_nt_num;
    begin
      select distinct object_id bulk collect into v_tab from all_objects where rownum <= 10;
      for i in 1 .. v_tab.count loop
        dbms_output.put_line(v_tab(i)) ;
      end loop ;
    end;
    /

  • What is wrong with this PL/SQL block

    declare
    v_count integer := 0;
    begin
    -- execute immediate 'select count(1) into v_count from ' || 'abc' || '.table1';
    execute immediate 'select count(1) into v_count from abc.table1';
    dbms_output.put_line('v_count: ' || v_count);
    end;
    When i execute the above pl/sql block, I get the following error:
    ORA-00905: missing keyword
    ORA-06512: at line 6
    What am I doing wrong?
    When I use SELECT COUNT(1) INTO v_count FROM abc.table1; ( instead of the dynamic sql ), it works.
    I realize I don't need to use execute immediate for SELECT, but I need to do the dynamic SQL because the table1 will be under multiple schemas.
    Would appreciate an explanation for the above error, and/or alternate solution(s) for dynamic sql.
    Thanks

    DECLARE
      v_count INTEGER := 0;
    BEGIN
      -- execute immediate 'select count(1) into v_count from ' || 'abc' || '.table1';
      EXECUTE IMMEDIATE 'select count(1)  from abc.table1' into v_count;
      dbms_output.put_line('v_count: ' || v_count);
    END;TEST
    DECLARE
      v_count INTEGER := 0;
    BEGIN
      -- execute immediate 'select count(1) into v_count from ' || 'abc' || '.table1';
      EXECUTE IMMEDIATE 'select count(1) from dual ' into v_count;
      dbms_output.put_line('v_count: ' || v_count);
    END;
    v_count: 1
    PL/SQL procedure successfully completed.HTH
    SS

  • Can some one please tell me what is the problem in the below pl/sql block

    Hi, I have problem with the following pl/sql block, I need this with bulk operation.
    -- Assume the following scenario, we are validating dept (master) and emp(child) which are my temporary tables and updating the status back to
    -- dept ( for all the validation errors, even if we have any validation at child  it has to update the header record with error message),
    -- upon successful validation insert the data into dept3, and emp3 interms of batches
    -- I have give the sample example with dept and emp, but i have around 10 million records which has around 30-40 validations,
    -- I would like to process them in terms of batches using bulk collection as this would do fast processing
    -- Can some one please tell me how to insert them in terms of bulk with every set of 1000 records in each batch in this example,for every set of 1000 records
    -- i need update batch id with unique number in dept table
    -- with current data i can have 50 batches , I need to pass, deptno as parameter to my emp cursor. 
    -- can some one please tell me how to make this validation and insertion more efficient. so that while inserting the data for every batch it should insert batch id
    -- Tried with LIMIT clause as well but not working
    -- I am correcting the code as per your comments Request you to please suggest me so that I can correct , I am new to PL/sql, started learning now.
    step - 1:
    CREATE TABLE DEPT
           (DEPTNO NUMBER(6) primary key,
            DNAME VARCHAR2(25),
            LOC VARCHAR2(23),
            batch_id number );
    INSERT INTO DEPT VALUES (10, 'ACCOUNTING', 'NEW YORK', null);
    INSERT INTO DEPT VALUES (20, 'RESEARCH',   'DALLAS', null);
    INSERT INTO DEPT VALUES (30, 'SALES',      'CHICAGO', null);
    INSERT INTO DEPT VALUES (40, 'OPERATIONS', 'BOSTON', null);
    step - 2:
    declare
    begin
    for i in 1..50000 loop
    insert into dept values(40+i, 'OPERATIONS'||i,'BOSTON'||i, null);
    end loop;
    commit;
    exception
    when others then
    dbms_output.put_line('Exception occured:'||SQLERRM);
    end;
    step - 3:
    create sequence emp_seq start with 1 increment by 1;
    step - 4:
    CREATE TABLE EMP
           (EMPNO NUMBER(15) NOT NULL primary key,
            ENAME VARCHAR2(20),
            JOB VARCHAR2(20),
            MGR NUMBER(4),
            HIREDATE DATE,
            SAL NUMBER(7, 2),
            COMM NUMBER(7, 2),
            DEPTNO NUMBER(6));
    INSERT INTO EMP VALUES
            (7369, 'SMITH',  'CLERK',     7902,
            TO_DATE('17-DEC-1980', 'DD-MON-YYYY'),  800, NULL, 20);
    INSERT INTO EMP VALUES
            (7499, 'ALLEN',  'SALESMAN',  7698,
            TO_DATE('20-FEB-1981', 'DD-MON-YYYY'), 1600,  300, 30);
    INSERT INTO EMP VALUES
            (7521, 'WARD',   'SALESMAN',  7698,
            TO_DATE('22-FEB-1981', 'DD-MON-YYYY'), 1250,  500, 30);
    INSERT INTO EMP VALUES
            (7566, 'JONES',  'MANAGER',   7839,
            TO_DATE('2-APR-1981', 'DD-MON-YYYY'),  2975, NULL, 20);
    INSERT INTO EMP VALUES
            (7654, 'MARTIN', 'SALESMAN',  7698,
            TO_DATE('28-SEP-1981', 'DD-MON-YYYY'), 1250, 1400, 30);
    INSERT INTO EMP VALUES
            (7698, 'BLAKE',  'MANAGER',   7839,
            TO_DATE('1-MAY-1981', 'DD-MON-YYYY'),  2850, NULL, 30);
    INSERT INTO EMP VALUES
            (7782, 'CLARK',  'MANAGER',   7839,
            TO_DATE('9-JUN-1981', 'DD-MON-YYYY'),  2450, NULL, 10);
    INSERT INTO EMP VALUES
            (7788, 'SCOTT',  'ANALYST',   7566,
            TO_DATE('09-DEC-1982', 'DD-MON-YYYY'), 3000, NULL, 20);
    INSERT INTO EMP VALUES
            (7839, 'KING',   'PRESIDENT', NULL,
            TO_DATE('17-NOV-1981', 'DD-MON-YYYY'), 5000, NULL, 10);
    INSERT INTO EMP VALUES
            (7844, 'TURNER', 'SALESMAN',  7698,
            TO_DATE('8-SEP-1981', 'DD-MON-YYYY'),  1500, NULL, 30);
    INSERT INTO EMP VALUES
            (7876, 'ADAMS',  'CLERK',     7788,
            TO_DATE('12-JAN-1983', 'DD-MON-YYYY'), 1100, NULL, 20);
    INSERT INTO EMP VALUES
            (7900, 'JAMES',  'CLERK',     7698,
            TO_DATE('3-DEC-1981', 'DD-MON-YYYY'),   950, NULL, 30);
    INSERT INTO EMP VALUES
            (7902, 'FORD',   'ANALYST',   7566,
            TO_DATE('3-DEC-1981', 'DD-MON-YYYY'),  3000, NULL, 20);
    INSERT INTO EMP VALUES
            (7934, 'MILLER', 'CLERK',     7782,
            TO_DATE('23-JAN-1982', 'DD-MON-YYYY'), 1300, NULL, 10);
    commit;
    step :- 5
    declare
    cursor c1 is select * from dept;
    k number:=0;
    m number:=0;
    begin
    for i in  c1 loop
    k:=k+1;
    --dbms_output.put_line('k:'||k);
    --dbms_output.put_line('i.deptno:'||i.deptno);
    m:=0;
    for j in 1..5 loop
    m:=m+1;
    --dbms_output.put_line('m:'||m);
    --dbms_output.put_line('i.deptno:'||i.deptno);
    insert into emp values
            (9000+emp_seq.nextval, 'SMITH'||'_'||emp_seq.currval,  'CLERK'||'_'||emp_seq.currval,     7902,
            TO_DATE('17-DEC-1980', 'DD-MON-YYYY'),  800, NULL, i.deptno);
    end loop;
    end loop;
    commit;
    exception
    when others then
    dbms_output.put_line('Exception occured:'||sqlerrm);
    end;
    step :-6
    create table dept3 as select * from dept where 1=2;
    create table emp3 as select * from emp where 1=2;
    alter table dept add object_id number;
    alter table dept add status varchar(20);
    alter table dept add err_msg varchar2(200);
    alter table emp add object_id number;
    -- I have not included the alter statements in the inital creation because i dont want them to insert into dept3 and emp3
    CREATE OR REPLACE
    PACKAGE test_b
    AS
      g_batch_id NUMBER;
      PROCEDURE emp_ins(
          p_EMPNO    NUMBER,
          p_ENAME    VARCHAR2,
          p_JOB      VARCHAR2,
          p_MGR      NUMBER,
          p_HIREDATE DATE,
          p_SAL      NUMBER,
          p_COMM     NUMBER,
          p_DEPTNO   NUMBER);
      PROCEDURE dept_ins(
          p_DEPTNO NUMBER,
          p_dname  VARCHAR2 ,
          p_LOC    VARCHAR2,
          p_batch  NUMBER);
      PROCEDURE validate_prc;
      PROCEDURE main;
    TYPE dept_t
    IS
      TABLE OF dept%ROWTYPE;
      hdr_tbl dept_t;
    TYPE emp_t
    IS
      TABLE OF emp%ROWTYPE;
      line_tbl emp_t;
    TYPE dept_i_t
    IS
      TABLE OF dept3%ROWTYPE;
      hdr_ins_tbl dept_i_t;
    TYPE emp_i_t
    IS
      TABLE OF emp3%ROWTYPE;
      line_ins_tbl emp_i_t;
    END;
    -- pacakge body
    CREATE OR REPLACE
    PACKAGE body test_b
    AS
    PROCEDURE emp_ins(
        p_EMPNO    NUMBER,
        p_ENAME    VARCHAR2,
        p_JOB      VARCHAR2,
        p_MGR      NUMBER,
        p_HIREDATE DATE,
        p_SAL      NUMBER,
        p_COMM     NUMBER,
        p_DEPTNO   NUMBER)
    IS
    BEGIN
      INSERT
      INTO EMP3
          EMPNO ,
          ENAME ,
          JOB ,
          MGR ,
          HIREDATE ,
          SAL ,
          COMM ,
          DEPTNO
        VALUES
          P_EMPNO ,
          P_ENAME ,
          P_JOB ,
          P_MGR ,
          P_HIREDATE ,
          P_SAL ,
          P_COMM ,
          P_DEPTNO
    EXCEPTION
    WHEN OTHERS THEN
      DBMS_OUTPUT.PUT_LINE('EXCEPTION AT EMP INSERT'||SQLERRM);
    END;
    PROCEDURE dept_ins
        p_DEPTNO NUMBER,
        p_dname  VARCHAR2 ,
        p_LOC    VARCHAR2,
        p_batch  NUMBER
    IS
    BEGIN
      INSERT
      INTO DEPT3
          DEPTNO ,
          DNAME ,
          LOC ,
          batch_id
        VALUES
          p_DEPTNO ,
          p_DNAME ,
          p_LOC ,
          p_batch
    EXCEPTION
    WHEN OTHERS THEN
      DBMS_OUTPUT.PUT_LINE('EXCEPTION AT DEPT INSERT'||SQLERRM);
    END ;
    PROCEDURE validate_prc
    IS
      CURSOR c1
      IS
        SELECT * FROM dept WHERE status IS NULL ;--AND rownum <25;
      CURSOR c2(p_dept NUMBER )
      IS
        SELECT * FROM emp WHERE deptno=p_dept;
      e_validation EXCEPTION;
    BEGIN
      OPEN c1;
      LOOP
        FETCH c1 BULK COLLECT INTO hdr_tbl limit 5000;
        SELECT emp_seq.nextval INTO g_batch_id FROM dual;
        EXIT
      WHEN hdr_tbl.count = 0;
        dbms_output.put_line('batch'||g_batch_id);
      END LOOP;
      CLOSE c1;
      dbms_output.put_line('C1 closed');
      --------- Loading data into the inv line table type -------------------------------
      FOR i IN 1 .. hdr_tbl.count
      LOOP
        dbms_output.put_line('started validation');
        -- do header level validations
        IF hdr_tbl(i).dname  IS NULL THEN
          hdr_tbl(i).status  := 'ERROR';
          hdr_tbl(i).err_msg :=',DNAME is null';
        END IF;
        OPEN c2(hdr_tbl(i).deptno);
        LOOP
          FETCH c2 BULK COLLECT INTO line_tbl;
          -- EXIT WHEN c2%NOTFOUND;
        END LOOP;
        CLOSE c2;
        FOR j IN 1 .. line_tbl.count
        LOOP
          -- do line validations
          IF line_tbl(j).ename IS NULL THEN
            hdr_tbl(i).status  := 'ERROR';
            hdr_tbl(i).err_msg :=',ENAME is null';
          END IF;
          BEGIN
            FORALL j IN line_tbl.FIRST .. line_tbl.LAST
            SAVE EXCEPTIONS
            UPDATE EMP
            SET object_id =3
              -- I have multiple columns to update based on validations
            WHERE deptno =hdr_tbl(i).deptno------------
            AND empno    =line_tbl (j).empno;
            COMMIT;
            line_tbl.DELETE;
            dbms_output.put_line( 'Successfully updated emp temp table.');
          EXCEPTION
          WHEN OTHERS THEN
            ROLLBACK;
            dbms_output.put_line( 'Error while updating line temp table. ' || sqlerrm );
            FOR j IN 1 .. sql%BULK_EXCEPTIONS.COUNT
            LOOP
              DBMS_OUTPUT.put_line(' occurred during line temp table updation ' || sql%BULK_EXCEPTIONS(i).ERROR_INDEX );
            END LOOP;
            raise e_validation;
          END;
        END LOOP; -- j
        --CLOSE c2;
        IF hdr_tbl(i).err_msg IS NULL THEN
          hdr_tbl (i).status  := 'VALID';
          hdr_tbl (i).err_msg := NULL;
        END IF;
        -- even if I have line validation failed I have to update header status and erorr msg
        BEGIN
          FORALL i IN hdr_tbl.FIRST .. hdr_tbl.LAST
          SAVE EXCEPTIONS
          UPDATE DEPT
          SET object_id =4,
            status      = hdr_tbl (i).status,
            err_msg     = hdr_tbl (i).err_msg
            --  batch_id =
            -- I have multiple columns to update based on validations
          WHERE deptno = hdr_tbl (i).deptno
          AND status  IS NULL; ------------
          COMMIT;
          hdr_tbl.DELETE;
          dbms_output.put_line( 'Successfully updated dept temp table.');
          --close c1;
        EXCEPTION
        WHEN OTHERS THEN
          ROLLBACK;
          dbms_output.put_line( 'Error while updating hdr temp table. ' || sqlerrm );
          FOR i IN 1 .. sql%BULK_EXCEPTIONS.COUNT
          LOOP
            DBMS_OUTPUT.put_line(' occurred during line temp table updation ' || sql%BULK_EXCEPTIONS(i).ERROR_INDEX );
          END LOOP;
          raise e_validation;
        END;
      END LOOP; --i
    EXCEPTION
    WHEN OTHERS THEN
      DBMS_OUTPUT.PUT_LINE('EXCEPTION AT validate'||SQLERRM);
    END ;
    PROCEDURE main
    IS
      CURSOR dept_ins_cur
      IS
        SELECT * FROM dept WHERE status='VALID';
      CURSOR emp_ins_cur(p_deptno NUMBER)
      IS
        SELECT * FROM emp WHERE deptno= p_deptno;
    BEGIN
      validate_prc;
      OPEN dept_ins_cur;
      LOOP
      FETCH dept_ins_cur BULK COLLECT INTO hdr_ins_tbl limit 1000
      EXIT
      WHEN dept_ins_cur%NOTFOUND;
      END LOOP;
      CLOSE dept_ins_cur;
      --------- Loading data into the inv line table type -------------------------------
      FOR i IN 1 .. hdr_tbl.count
      loop
      dept_ins(hdr_ins_tbl(i).deptno ,
      hdr_ins_tbl(i).DNAME ,
      hdr_ins_tbl(i).LOC , emp_seq.nextval);
      commit;
      OPEN emp_ins_cur(hdr_ins_tbl(i).deptno);
      LOOP
      FETCH emp_ins_cur BULK COLLECT INTO line_ins_tbl;
      --EXIT WHEN emp_ins_cur%NOTFOUND;
      END LOOP;
      CLOSE emp_ins_cur;
      for j in 1..line_ins_tbl.count loop
      emp_ins(line_ins_tbl(j).EMPNO ,
      line_ins_tbl(j).ENAME ,
      line_ins_tbl(j).JOB ,
      line_ins_tbl(j).MGR ,
      line_ins_tbl(j).HIREDATE ,
      line_ins_tbl(j).SAL ,
      line_ins_tbl(j).comm ,
      line_ins_tbl(j).DEPTNO );
      end loop;
      end loop;
      commit;
      BEGIN
      forall i IN hdr_ins_tbl.first .. hdr_ins_tbl.last
      SAVE exceptions
      UPDATE dept
      SET status   = 'INSERTED',
      err_msg  = null
      WHERE deptno=hdr_ins_tbl (i).deptno
      AND status   = 'VALID';
      COMMIT;
      hdr_ins_tbl.delete;
      dbms_output.put_line( 'inserting into temp tables.');
      EXCEPTION
      WHEN OTHERS THEN
      rollback;
      end;
    EXCEPTION
    WHEN OTHERS THEN
      dbms_output.put_line('exception in main' ||SQLERRM);
    END ;
    END;
    Thanks in advance...
    Message was edited by: 888025

    Hi, I have problem with the following pl/sql block
    Well, as Hoek already said, that is the understatement of the century.
    I can't be absolutely certain but I think that set of DDL and code that you posted has just about every possible error and design issue that there is! It would make an excellent addition to BluShadow's FAQs an an example of what NOT to do.
    I don't think it is even possible to 'fix the basics first' as Hoek suggested. IMHO the first step needs to be to create a functional requirements document (FRD) that explains in detail WHAT needs to be done. That doc should also contain info about how any errors/recovery/restart is to be handled. It is premature to try to implement ANY solution without first knowing what is needed functionally.
    Once the FRD is done you should do a walk-through based on your current architecture and sample data to make sure that the document really covers ALL of the steps that need to be performed and that it adequately explains how to deal with any processing or data issues that might arise.
    The next document you need is the TRD - Technical Requirements Doc that covers the different technical implementions of the FRD that can be done and the advantages/disadvantages of each.
    Then you can start working on a prototype.
    1. The DDL you posted isn't coherent - there are CREATE table statements and then later ALTER statements that add additional columns. There doesn't appear to be any reason for not including ALL of the columns in the CREATE table statement.
    2. You are using PL/SQL types instead of SQL types. That makes it impossible to use those types in SQL statements and makes it much more difficult to test since it is much easier to test a query in SQL (e.g. using sql*plus) that to embed the query in PL/SQL.
    3. You are defining the same type twice but giving it different names.
    TYPE dept_t
       IS
          TABLE OF dept%ROWTYPE
             INDEX BY binary_integer;
    TYPE dept_i_t
       IS
          TABLE OF dept%ROWTYPE
             INDEX BY binary_integer;
    Those are both based on the same DEPT table! Why the duplication?
    Also you are using associative arrays instead of just using nested tables. Get rid of the INDEX BY clause.
    4. You have some serious architectural and data model issues
    -- Assume the following scenario, we are validating dept (master) and emp(child) which are my temporary tables and updating the status back to
    -- dept ( for all the validation errors, even if we have any validation at child  it has to update the header record with error message),
    Why would you do that? You say 'it has to update the header record ...'. Says who? That is just one indication that you are trying to implement a 'solution' before you have adequately defined the 'problem'.
    Typically you would NOT alter any of the data tables; any validation errors/issues would get inserted into a table specifically designed to hold/log those issues. That table would contain key field values to correlate with the source of the error.
    Those 'master' and 'child' entities are two SEPARATE things. Issues with a 'master' row have NOTHING to do with any possible child rows.
    And issues with a 'child' row have NOTHING to do with any possible master rows. The ONLY connection between 'child' and 'master' is the foreign key that correlates them.
    So you don't necessarily have to validate the 'child' rows in sync with their 'master' row. In many cases you would have a procedure that performs validation of the entire set of 'master' rows and log those issues/problems. You would use a different procedure to validate the entire set of 'child' rows and log their issues.
    Those validation procedures can often work with ALL of the data using SQL statements instead of bulk processing.
    5. You are using loop constructs that are not valid for the type of processing you are using
    LOOP
        FETCH c1 BULK COLLECT INTO hdr_tbl;
        EXIT
      WHEN c1%NOTFOUND;
      END LOOP;
    There can be NO exit since the bulk collect with either get EVERYTHING or NOTHING. Possibly that is just a holdover from your attempt to use the LIMIT clause but you removed that clause from the FETCH; I don't know.
    There is so much wrong with what you posted it is really rather pointless to try to 'fix' it.
    I suggest you start over and clarify and DOCUMENT the actual requirements without prejudice about the solution that someone seems to want to force on you.

  • PL/SQL block returning error

    Hi All,
    I have used PL/SQL block in my custom report to search table heading. Basically I have two select list (LOV), user select the parameter from the list and click on go, it displays the report fine when record exists.
    I am using following PL/SQL block -
    >
    DECLARE
    v_sql VARCHAR2(4000);
    BEGIN
    IF :P126_PARK_NAME IS NOT NULL THEN
    v_sql := 'select P.OLIC_KEY1, PA.NAME, C.TRADING_NAME, L.LIC_TYPE, P.'|| :P126_PARK_NAME ||', C.COP_ID, L.OLIC_ID Olic_id '
    ||' from RTT_OP_PARKS_TEMP P, RTT_COMMERCIAL_OPERATORS C , RTT_PARTIES PA, RTT_OP_LICENCES L'
    ||' where '|| :P126_PARK_NAME || ' IS NOT NULL '
    ||' AND PA.PAR_ID =C.PAR_ID '
    ||' AND P.COP_ID =C.COP_ID '
    ||' AND L.OLIC_KEY1=P.OLIC_KEY1 '
    ||' AND :P126_QUERY = ''Y'''
    ||' ORDER BY PA.NAME ';
    END IF;
    /* debugging */
    IF :DEBUG = 'YES' THEN
    htp.preopen;
    htp.p(v_sql);
    htp.preclose;
    END IF;
    RETURN (v_sql);
    END;
    >
    Now, I want to use like condition to display all the records by checking the parameters in text field. I have created a new text field and modified the query as follows but it does not work -
    >
    DECLARE
    v_sql VARCHAR2(4000);
    BEGIN
    IF :P126_PARK_NAME IS NOT NULL THEN
    v_sql := 'select P.OLIC_KEY1, PA.NAME, C.TRADING_NAME, L.LIC_TYPE, P.'|| :P126_PARK_NAME ||', C.COP_ID, L.OLIC_ID Olic_id '
    ||' from RTT_OP_PARKS_TEMP P, RTT_COMMERCIAL_OPERATORS C , RTT_PARTIES PA, RTT_OP_LICENCES L'
    ||' where '|| :P126_PARK_NAME || ' IS NOT NULL '
    ||' AND PA.PAR_ID =C.PAR_ID '
    ||' AND P.COP_ID =C.COP_ID '
    ||' AND L.OLIC_KEY1=P.OLIC_KEY1 '
    ||' AND :P126_QUERY = ''Y'''
    ||' ORDER BY PA.NAME ';
    END IF;
    IF :P126_MARINE_PARK != -1 THEN
    v_sql := 'select distinct L.OLIC_KEY1, PA.NAME, C.TRADING_NAME, L.LIC_TYPE, M.'|| :P126_MARINE_PARK ||', C.COP_ID '
    ||' from RTT_OP_MARINE_PARKS M, RTT_COMMERCIAL_OPERATORS C , RTT_PARTIES PA, RTT_OP_LICENCES L'
    ||' where '|| :P126_MARINE_PARK || ' IS NOT NULL '
    ||' M.'||:P126_MARINE_PARK||' IS LIKE :P126_MARINE_PARK||'%' '
    ||' AND PA.PAR_ID =C.PAR_ID '
    ||' AND M.COP_ID =C.COP_ID '
    ||' AND L.OLIC_KEY1=M.OLIC_KEY1 '
    ||' AND :P126_QUERY = ''Y'''
    ||' ORDER BY PA.NAME ';
    END IF;
    /* debugging */
    IF :DEBUG = 'YES' THEN
    htp.preopen;
    htp.p(v_sql);
    htp.preclose;
    END IF;
    RETURN (v_sql);
    END;
    >
    Can anybody tell me what I am doing wrong here?
    Thanks in advance
    Regards,
    M Tajuddin

    Hi Andy,
    Thanks for pointing the quotation however it does not work either. Now I am getting -
    >
    failed to parse SQL query:
    ORA-00933: SQL command not properly ended
    >
    Now my query is like below -
    >
    DECLARE
    v_sql VARCHAR2(4000);
    BEGIN
    IF :P126_ZONE_NAME IS NOT NULL THEN
    v_sql := 'select distinct L.OLIC_KEY1, PA.NAME, C.TRADING_NAME, L.LIC_TYPE, M.'|| :P126_ZONE_NAME ||', C.COP_ID '
    ||' from RTT_OP_MARINE_PARKS M, RTT_COMMERCIAL_OPERATORS C , RTT_PARTIES PA, RTT_OP_LICENCES L'
    ||' where '|| :P126_ZONE_NAME || ' IS NOT NULL '
    ||' AND PA.PAR_ID =C.PAR_ID '
    ||' AND M.COP_ID =C.COP_ID '
    ||' AND L.OLIC_KEY1=M.OLIC_KEY1 '
    ||' AND :P126_QUERY = ''Y'''
    ||' ORDER BY PA.NAME ';
    END IF;
    IF :P126_MARINE_PARK IS NOT NULL THEN
    v_sql := 'select distinct L.OLIC_KEY1, PA.NAME, C.TRADING_NAME, L.LIC_TYPE, M.'|| :P126_MARINE_PARK ||', C.COP_ID '
    ||' from RTT_OP_MARINE_PARKS M, RTT_COMMERCIAL_OPERATORS C , RTT_PARTIES PA, RTT_OP_LICENCES L'
    ||' where ' || :P126_MARINE_PARK || ' IS NOT NULL '
    *||' M.' || :P126_MARINE_PARK || ' IS LIKE ''' || :P126_MARINE_PARK || '%'' '*
    ||' AND PA.PAR_ID =C.PAR_ID '
    ||' AND M.COP_ID =C.COP_ID '
    ||' AND L.OLIC_KEY1=M.OLIC_KEY1 '
    ||' AND :P126_QUERY = ''Y'''
    ||' ORDER BY PA.NAME ';
    END IF;
    /* debugging */
    IF :DEBUG = 'YES' THEN
    htp.preopen;
    htp.p(v_sql);
    htp.preclose;
    END IF;
    RETURN (v_sql);
    END;
    >
    Can you tell me how can I display dynamic multiple column in my query? Say in the LIKE condition if user type M in the parameter field and click on go, it must return more than one column starting column name M but in my current query it will only display one column, am I right?
    Thanks again for your suggestion.
    Kind regards,
    M Tajuddin
    http://tajuddin.whitepagesbd.com

  • PL/SQL block error message

    Hi,
    I'm still learning PL/SQL. In my application, I created a PL/SQL block which contains an update and an insert statement. When I click Apply Changes, I receive the following error message:
    1 error has occurred
    ORA-06550: line 24, column 5: PL/SQL: ORA-00933: SQL command not properly ended ORA-06550: line 19, column 2: PL/SQL: SQL Statement ignored
    This is my code. I'm not seeing the problem very clearly. Can someone help me out? Thanks.
    BEGIN
    update
        HISA_AGREEMENTS
         set
           CREATED_BY=V('APP_USER'),
           LAST_UPDATED_BY=V('APP_USER'),
           APPROVER_SALUTATION=:P7_APPROVER_SALUTATION,
           APPROVER_FIRST_NAME=:P7_APPROVER_FIRST_NAME,
           APPROVER_MIDDLE_INITIAL=:P7_APPROVER_MIDDLE_INITIAL,
           APPROVER_LAST_NAME=:P7_APPROVER_LAST_NAME,
           APPROVER_NAME_SUFFIX=:P7_APPROVER_NAME_SUFFIX,
           APPROVER_EMAIL_ADDR=:P7_APPROVER_EMAIL_ADDR,
           SPONSOR_EMAIL_ADDR=:P7_SPONSOR_EMAIL_ADDR,
           APPROVER_TITLE=:P7_APPROVER_TITLE
    where
          ORG_KEY_LE=:P7_ORG_KEY_LE;
    insert into
        HISA_AGREEMENT_DOCS
           (ORG_DOC_CURR_KEY)
       values
           (:P7_DOCUMENT)
        where
          ORG_KEY_LE=:P7_ORG_KEY_LE;
    END;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Hello,
    insert into
    HISA_AGREEMENT_DOCS
    (ORG_DOC_CURR_KEY)
    values
    (:P7_DOCUMENT)
    where
    ORG_KEY_LE=:P7_ORG_KEY_LE;
    is wrong. The WHERE clause needs to be omitted...or you need an update.
    Greetings,
    Roel
    http://roelhartman.blogspot.com/
    You can reward this reply by marking it as either Helpful or Correct ;-)

  • Exception in declarative section to propagating in PL/SQL Block

    Hi All, I have a requirement to send emails to some receipient whenever there is an error in a process. The is working untill the put a wrong database link in the parameter, the cursor is in declarative statement, hence when other exception does not work, create and enclosing block around the initial block so that the exception can propagate to the enclosing block, but this does not work either, please advice. Below is the a brief pseudo code. The bold is the initial block. Please advice.
    DECLARE
    Invalid_table EXCEPTION;
    PRAGMA EXCEPTION_INIT(Invalid_table, -00942);
    BEGIN
    declare
    c_test number;
    cursor c1 is select 1 from tt@sro4link1 --- wrong databaselink sent as a parameter
    where 1 =1;
    */*Because the error is in the cursor select, no email is been sent, that was the reason I put an enclosing block, but the exception is not propagate either */*
    BEGIN
    OPEN C1;
    FETCH C1 into c_test;
    CLOSE C1;
    EXCEPTION
    WHEN OTHERS THEN
    --- Send email
    END; EXCEPTION
    WHEN Invalid_table THEN
    --- send email
    END;
    /

    Ade2 wrote:
    it is not a dynamic sql. Your description is not very clear about what is code and what is pseudo code, but if you are using substitution variables in sqlplus, then that is dynamic SQL.
    sqlplus scans for substitution variables, prompts when needed, replaces the variable (substitutes) with the text input and passes the entire result to the database for validation.
    If the substitution text input results in an invalid PL/SQL block then a compilation error is returned from the database. The PL/SQL cannot be compiled, it never runs, no run time exceptions are possible.
    So you cannot use exceptions to detect errors in values input to substitution variables.
    SQL> declare
      2    l_dummy number;
      3  begin
      4    select 1 into l_dummy from dual;
      5  end;
      6  /
    PL/SQL procedure successfully completed.
    SQL> declare
      2    l_dummy number;
      3  begin
      4    &5
      5  end;
      6  /
    Enter value for 5: select 1 into l_dummy from dual;
    old   4:   &5
    new   4:   select 1 into l_dummy from dual;
    PL/SQL procedure successfully completed.
    SQL> /
    Enter value for 5: this will not compile
    old   4:   &5
    new   4:   this will not compile
      this will not compile
    ERROR at line 4:
    ORA-06550: line 4, column 8:
    PLS-00103: Encountered the symbol "WILL" when expecting one of the following:
    := . ( @ % ;

  • Alter table then Update in PL/SQL block

    I am trying to alter the table then update it :
    declare
    colCount number;*
    begin*
    select count(*) into colCount from all_tab_cols where table_name = 'TEST' and owner = 'TEST_OWNER';*
    dbms_output.put_line('No of Columns in the table : ' || colCount);*
    if colCount = 2  then*
    dbms_output.put_line('Table needs upgrade');*
    execute immediate('ALTER TABLE TEST ADD COL1 VARCHAR2(100) NULL');*
    UPDATE TEST SET COL1 = '123';*
    commit;*
    else*
    dbms_output.put_line('No Changes Required');*
    end if;*
    end;*
    Oracle complains that "COL1" is an invalid identifier.
    I also tried substitute the UPDATE statement with
    **     execute immediate('UPDATE TEST SET VCHCHARSET_OUT='UTF8' WHERE VCHCHARSETNAME='UTF8'');**
    and there is something wrong with the construction of an Update statement in the parenthesis.
    Am I taking the right approach and just need to figuire out the syntax of single quotes or something else is wrong?
    thanks in advance.

    Yes, you are absolutely right, I shouldn't alter the table and then update the values.
    The reason I need to do it relates to the migration process we utilize in our company. Initially I had a set of SQL commands which I executed migrating from one environment to another and eventually to Production. I had an error in the last SQL command which caused migration process to produce "Failure", however the table was already altered and all the rows except the last one were updated. Since I can't successfully migrate to Production with the failed process I have to generate a PL/SQL block which will take in consideration that in one environment the table has already been modified and in the other one is still needs to be changed.

  • HTML not working in PL/SQL block..Help me ASAP

    declare
    l_col VARCHAR2(30) :=to_number(to_char(to_date('01-feb-2011','dd-mon-yyyy'),'dd'));
    CURSOR name_cur IS
      select name
          from   od_shift_schedule
          where   year=2011
          and    (month)=('Feb')
           and    decode(l_col,1,"01",2,"02",3,"03",4,"04",5,"05",6,"06",7,
                         "07",8,"08",9,"09",10,"10",11,"11",12,"12",13,"13",14,"14",15,"15",16,"16",17,"17",18,"18",19,"19",20,"20",
                         21,"21",22,"22",23,"23",24,"24",25,"25",26,"26",
                       27,"27",28,"28",29,"29",30,"30",31,"31")='W';
    BEGIN
      DELETE FROM nam;
      commit;
      FOR i IN name_cur
      LOOP
      dbms_output.put_line(i.name);
      htp.p('<b>Employee '||i.name||'  has been ticked.
       </b><br/>');
      EXECUTE IMMEDIATE 'insert into nam(name) values('''||i.name||''')';
      commit;
    END LOOP;
    end;Kindly help me with this
    If i'm wrong here kindly help me that how can i place a display message

    Re: HTML not working in PL/SQL block..Help me ASAP
    Using the community discussion forums for urgent issues is rude and a violation of the terms and conditions.
    http://www.oracle.com/html/terms.html
    >
    4. Use of Community Services
    Community Services are provided as a convenience to users and Oracle is not obligated to provide any technical support for, or participate in, Community Services. While Community Services may include information regarding Oracle products and services, including information from Oracle employees, they are not an official customer support channel for Oracle.
    You may use Community Services subject to the following: (a) Community Services may be used solely for your personal, informational, noncommercial purposes; (b) Content provided on or through Community Services may not be redistributed; and (c) personal data about other users may not be stored or collected except where expressly authorized by Oracle
    >
    Also please read the FAQ on how to ask questions.
    SQL and PL/SQL FAQ
    >
    2) Thread Subject line
    Give your thread a meaningful subject, not just "help please", "Query help" or "SQL". This is the SQL and PL/SQL forum. We know your question is going to be about those things, make it meaningful to the type of question so that people with the right sort of knowledge can pick it up and those without can ignore it. Never, EVER, mark your subject as "URGENT" or "ASAP"; this forum is manned by volunteers giving their own time to help and your question is never urgent or more important than their own work or than other people's questions. It may be urgent to you, but that's not forum members issue.

  • Pl/sql block updating orderId, itemID

    lol here i am again!
    This time its like this:
    i have a table (orderId, itemId, CustomerId, productId, quantity, start_date, end_date, oldRef)
    here are some of the values:
    2477, 1, 201, 111, 1,19-MAR-93,14-APR-93
    2477,2,201,112,1,19-MAR-93,14-APR-93
    2478,1,201,113,1,19-MAR-93,14-APR-93
    2478,2,201,110,19-Mar-93,14-APR-93
    Now as you can see that order_Id is different however order_date and ship_date both match. Now what i want to do is to give them a new orderId, re-arrange itemId if ship_date and order_date match for each customer so the ex above should come out like this:
    1, 1, 201, 111, 1,19-MAR-93,14-APR-93
    1,2,201,112,1,19-MAR-93,14-APR-93
    1,3,201,113,1,19-MAR-93,14-APR-93
    1,4,201,110,19-Mar-93,14-APR-93
    I have created a pl/sql block. It has a cursor that loops around each row of table. Then it stores orderdate, shipdate and customerId. it also has a itemId variable and orderDate variable. OrderDate variable takes its value from orderId sequence and itemId is just a number that increments itself.
    NOW when orderdate,shipdate&customerId are the same, i just update the itemId, if they differ or customer_id changes i get a new order_id, update the variables (orderdate,shipdate,customerid,itemId) but for some reason i dont think it is working!!
    DECLARE
         cursor c1 is
              SELECT
              FROM
                   ph2_item
              order by
                   customer_id,
                   ship_date,
                   order_date
              for update;
         new_order_id     number(8,0) := 0;
         new_item_id     number(4,0) := 1;
         temp_odate      date := '11-JUN-08';
         temp_sdate     date:= '11-JUN-08';
         temp_cId     number(8,0) := 1;
    BEGIN
         FOR rec in c1 LOOP
              IF  rec.customer_id = temp_cId  THEN
                   IF (rec.order_date <> temp_odate OR
                   rec.ship_date <> temp_sdate) THEN
                        new_item_id:= 1;
                                    SELECT  orderid.nextVal into new_order_id from dual;
                        temp_odate :=rec.order_date;
                        temp_sdate :=rec.ship_date;
                   END IF;
              ELSE
                   new_item_id:= 1;
                   SELECT  orderid.nextVal into new_order_id from dual;
                   temp_cid := rec.customer_id;
                   temp_odate :=rec.order_date;
                   temp_sdate :=rec.ship_date;
              END IF;
              update ph2_item
              set order_id = new_order_id, item_id = new_item_id
              where current of c1;
              new_item_id := new_item_id + 1;
         END LOOP;
    END;
    commit;PS> this is not a real life database and just a college assignment!
    just corrected a mistake in one of the example code i posted
    Message was edited by:
    user646562

    well it does seem to give the right results ie. orderId is changed and itemId is rearranged! however the college has an online marker and when i try to submit the code, it says that the max(order_id) of the resulting table (ph2_item) is wrong, the sum(item_id) is wrong and the no of distinct orders is wrong.. this means i am either consolidating orders whne i shouldnt, and this in turns make my item_id wrong..
    also there is one more criteria i should have mentioned but i forgot and that is even if the order_date and ship_date is the same as another order, we will only consolidate them if the customer in question has multiple sites.
    here is the updated pl/sql block taking into account this criteria (using if/else statement)
    DECLARE
         cursor c1 is
              SELECT
              FROM
                   ph2_item
              order by
                   order_date,
                   customer_id
              for update;
         new_order_id     number(8,0) := 0;
         new_item_id     number(4,0) := 1;
         temp_odate date := '11-JUN-08';
         temp_sdate     date:= '11-JUN-08';
         temp_cId     number(8,0) := 1;
         totalSites     number(2,0);
    BEGIN
         FOR rec in c1 LOOP
              select site_count into totalsites from customer_sites where customer_id = rec.customer_id;
              --dbms_output.put_line(rec.customer_id ||' ' || totalsites);
              if totalsites > 1 THEN
                   IF rec.customer_id = temp_cId THEN
                        IF (rec.ship_date <> temp_sdate AND rec.order_date <> temp_odate) AND rec.ship_date is null THEN
                             new_item_id:= 1;
         SELECT orderid.nextVal into new_order_id from dual;
                             temp_odate :=rec.order_date;
                             --temp_sdate :=rec.ship_date;
                        END IF;
                   ELSE
                        new_item_id:= 1;
                        SELECT orderid.nextVal into new_order_id from dual;
                        temp_cid := rec.customer_id;
                        temp_odate :=rec.order_date;
                        --temp_sdate :=rec.ship_date;
                   END IF;     
              ELSE
                   new_item_id:= 1;
                   SELECT orderid.nextVal into new_order_id from dual;
                   temp_cid := rec.customer_id;
                   temp_odate :=rec.order_date;
                   --temp_sdate :=rec.ship_date;
              END IF;      
              update ph2_item
              set order_id = new_order_id, item_id = new_item_id
              where current of c1;
              new_item_id := new_item_id + 1;
         END LOOP;
    END;

  • Call DLL from PL-SQL block

    Hello all,
    I want to call a function located in an external DLL from a PL-SQL block. I execute the followin steps :
    1. Create a database library pointing to the external DLL :
    create or replace library libstk as 'C:\SUMMIT\libstkdte_s_trade1.dll'
    2. Create the definition and the body package :
    CREATE OR REPLACE PACKAGE dllcall IS
         FUNCTION s_trade (
              s_in VARCHAR2 )
    RETURN VARCHAR2;
    PRAGMA RESTRICT_REFERENCES(s_trade, WNDS);
    end dllcall;
    show errors
    CREATE OR REPLACE PACKAGE BODY dllcall IS
    FUNCTION s_trade (s_in IN VARCHAR2) RETURN VARCHAR2
    IS EXTERNAL
    NAME "s_trade"
    LIBRARY libstk
    PARAMETERS (s_in           STRING,
    RETURN STRING);
    END dllcall;
    show errors
    set serveroutput on
    3. Start the PL-SQL block calling the external function. And I got the foolowing error :
    1 begin
    2 dbms_output.put_line ( dllcall.s_trade ( '<Request> ' ||
    3 '<CurveId>MYCURVE</CurveId> ' ||
    4 '<Mode>02</Mode> ' ||
    5 '<ExpCcy>GBP</ExpCcy> ' ||
    6 '<AsOfDate>20001023</AsOfDate> ' ||
    7 '<Entity>***SUMMIT-XML***</Entity> ' ||
    8 '</Request>') );
    9* end;
    10
    11 /
    begin
    ERROR à la ligne 1 :
    ORA-06520: PL/SQL: Error loading external library
    ORA-06522: Unable to load DLL
    ORA-06512: at "V31.DLLCALL", line 0
    ORA-06512: at line 2
    The "Read - Execute permissions" of the DLL file was given to "Authentified users" .
    What's wrong ?
    TIA
    PS : NT2K environment, DB 8.1.7
    R. Charles Emile

    Yes, a RPC was set up.
    Listner.ora
    LISTENER =
    (DESCRIPTION_LIST =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = Server1)(PORT = 1521))
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = NMP)(SERVER = Server1)(PIPE = ORAPIPE))
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
    SID_LIST_LISTENER =
    (SID_LIST =
    (SID_DESC =
    (SID_NAME = PLSExtProc)
    (ORACLE_HOME = E:\Oracle\Ora81)
    (PROGRAM = extproc)
    tnsnames.ora
    extproc_connection_data =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
    (CONNECT_DATA = (SID = PLSExtProc))
    Thanks
    RCE

  • Error executing pl sql block

    Hii All,
    I'm facing the following error
    ERROR at line 66:
    ORA-06550: line 66, column 20:
    PLS-00306: wrong number or types of arguments in call to '||'
    ORA-06550: line 66, column 11:
    PL/SQL: Statement ignoredVersion Details
    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    PL/SQL Release 11.1.0.7.0 - Production
    CORE    11.1.0.7.0      Production
    TNS for Solaris: Version 11.1.0.7.0 - Production
    NLSRTL Version 11.1.0.7.0 - ProductionMy pl sql block
    Declare
        p_table_name  clob := 'CP_CA_DTLS' ;
        Type t_column_name_tab is table of varchar2(4000)
        index by binary_integer;
        l_table_tab      t_column_name_tab;
        l_file_name constant varchar2(5000) := 'column_counts';
        l_count      number;
        l_tab_count    number;
        l_str    varchar2(32000);
        l_tbl_str  varchar2(32000);
      Cursor c_table_columns(c_table_name user_tables.table_name%type)
      Is
        Select  column_name
        from  user_tab_cols
        where  table_name = upper(c_table_name);
      Type t_table_columns is table of c_table_columns%rowtype;
       l_column_name_tab  t_table_columns;
    Begin
        --Splitting comma seperated data
        Select  regexp_substr(p_table_name,'[^,]+{1}',1,level)
        bulk collect into  l_table_tab
        from  dual
        connect by level <= length(regexp_replace(p_table_name,'[^,]*'))+1;
        for k in 1..l_table_tab.count
        loop
         -- dbg_print(l_file_name,'***'||l_table_tab(k)||'***');   
          Begin
              l_tbl_str := 'Select count(*) from '||l_table_tab(k);
              execute immediate l_tbl_str into l_tab_count;
            --  dbg_print(l_file_name,'Overall Count of table '||l_table_tab(k)||' is '||l_tab_count);   
          End;
       -- dbg_print(l_file_name,'Column Name '||','||'Count'); 
        Open c_table_columns(l_table_tab(k));
        loop
          Fetch c_table_columns bulk collect into l_column_name_tab limit 50;
          exit when l_column_name_tab.count = 0;
          dbms_output.put_line('l_column_name_tab.count count is : '||l_column_name_tab.count);
            for i in 1..l_column_name_tab.count
            loop
            Begin
              l_str := 'Select count(*) ' ;
              l_str := l_str||' from  '||l_table_tab(k) ;
              l_str := l_str||' where '||l_column_name_tab(i);
              l_str := l_str||' is null'  ;
              Execute Immediate l_str into l_count;
            End;
            --dbg_print(l_file_name,l_column_name_tab(i)||','||l_count);
            end loop;
        end loop;
        Close c_table_columns;
      end loop;
          dbms_output.put_line('l_column_name_tab.count count is : '||l_column_name_tab.count);
    End;Even I'm not able to print l_column_name_tab(i) using dbms_output.
    (Later I came to know that this information can be achieved using user_tab_col_statistics table)
    But would like to know whats wrong with my code.???
    Plz help me .
    Edited by: 792353 on Dec 3, 2010 1:26 AM

    Hii RDB,
    when I comment this part of code
      --   l_str := l_str||' where '||l_column_name_tab(i);
           --   l_str := l_str||' is null'  ;
    SQL> Declare
      2 
      3 
      4      p_table_name  clob := 'CP_CA_DTLS' ;
      5 
      6      Type t_column_name_tab is table of varchar2(4000)
      7      index by binary_integer;
      8     
      9      l_table_tab      t_column_name_tab;
    10    
    11 
    12 
    13 
    14      l_file_name constant varchar2(5000) := 'column_counts';
    15      l_count      number;
    16      l_tab_count    number;
    17      l_str    varchar2(32000);
    18      l_tbl_str  varchar2(32000);
    19   
    20    Cursor c_table_columns(c_table_name user_tables.table_name%type)
    21    Is
    22      Select  column_name
    23      from  user_tab_cols
    24      where  table_name = upper(c_table_name);
    25     
    26     
    27    Type t_table_columns is table of c_table_columns%rowtype;
    28   
    29   
    30     l_column_name_tab  t_table_columns;
    31   
    32  Begin
    33      --Splitting comma seperated data
    34     
    35      Select  regexp_substr(p_table_name,'[^,]+{1}',1,level)
    36      bulk collect into  l_table_tab
    37      from  dual
    38      connect by level <= length(regexp_replace(p_table_name,'[^,]*'))+1;
    39     
    40      for k in 1..l_table_tab.count
    41      loop
    42       -- dbg_print(l_file_name,'***'||l_table_tab(k)||'***');   
    43       
    44        Begin
    45            l_tbl_str := 'Select count(*) from '||l_table_tab(k);
    46       
    47            execute immediate l_tbl_str into l_tab_count;
    48       
    49          --  dbg_print(l_file_name,'Overall Count of table '||l_table_tab(k)||' is '||l_tab_coun
    t);   
    50 
    51        End;
    52 
    53     -- dbg_print(l_file_name,'Column Name '||','||'Count'); 
    54 
    55      Open c_table_columns(l_table_tab(k));
    56      loop
    57        Fetch c_table_columns bulk collect into l_column_name_tab limit 50;
    58        exit when l_column_name_tab.count = 0;
    59        dbms_output.put_line('l_column_name_tab.count count is : '||l_column_name_tab.count);
    60          for i in 1..l_column_name_tab.count
    61          loop
    62          
    63          Begin
    64            l_str := 'Select count(*) ' ;
    65            l_str := l_str||' from  '||l_table_tab(k) ;
    66         --   l_str := l_str||' where '||l_column_name_tab(i);
    67         --   l_str := l_str||' is null'  ;
    68         
    69            Execute Immediate l_str into l_count;
    70 
    71          End;
    72         
    73          --dbg_print(l_file_name,l_column_name_tab(i)||','||l_count);
    74       
    75          end loop;
    76      end loop;
    77      Close c_table_columns;
    78    end loop;
    79 
    80        dbms_output.put_line('l_column_name_tab.count count is : '||l_column_name_tab.count);
    81  End;
    82  /
    PL/SQL procedure successfully completed.its running fine so the problem is l_column_name_tab(i) !!!!!!
    and there is nothing wrong with l_table_tab(k) and its declaration.
    Edited by: 792353 on Dec 3, 2010 2:17 AM

  • PL/SQL block to populate a table

    Hello Gurus,
    Need help to write a pl/sql block as per below:
    1. Write a PL/SQL block which will populate the RESULTS table as described below. Consider performance implications (specifically where would you commit the queries) as we are dealing with millions of records.
    The PL/SQL will:
    - insert into the RESULTS table each customer id, and the number of unique products purchased by that customer.
    - update the recently_purchased column of the customer table to 'Y' (yes if they have purchased a product in the last 12 months) or 'N' (if they have not purchased a product in the last 12 months).
    Listed below are the tables & definitions:
    table: CUSTOMER
    columns:
    customer_id NUMBER,
    customer_name VARCHAR2(100),
    recently_purchased VARCHAR2(1) -- 'Y' or 'N'
    table: CUST_PRODUCTS
    columns:
    product_id NUMBER,
    customer_id NUMBER,
    date_purchased DATE
    table: RESULTS
    columns: customer_id NUMBER, product_count NUMBER
    Thanks a lot..

    Hi Guys,
    I've tried this to my best but I feel like something's definately wrong with my update statement.
    Please help..
    --create customer table
    create table customer (
    customer_id number(6),
    customer_name varchar2(100),
    recently_purchased varchar2(1));
    -- describe to see if it is created as required
    desc customer
    --populate customer table with random values
    Begin
    For i in 1..20
    Loop
    Insert into customer(customer_id,customer_name,recently_purchased)
    values(i, dbms_random.string('U',5),'N');
    If mod(i, 100000) = 0 then
    Commit;
    End if;
    End loop;
    End;
    --create cust_products table
    create table cust_products
    (product_id number (6),
    customer_id number(6),
    date_purchased date);
    --describe to see if table is created as required
    desc cust_products
    --populate cust_products with custome_id 1 to 10 and dates
    Begin
    For i in 1..20
    Loop
    Insert into cust_products
    values(dbms_random.value(555,999),i,add_months('04-Nov-08',i));
    If mod(i, 100000) = 0 then
    Commit;
    End if;
    End loop;
    End;
    select * from cust_products
    --update customer table as required
    Begin
    For i in 1..10
    Loop
    update customer set recently_purchased = 'Y';
    commit;
    update customer C set recently_purchased = 'N' where exists (select date_purchased from cust_products P where C.customer_id = P.customer_id );
    commit;
    End loop;
    End;
    --Insert into results table
    select customer_id,count(product_id)
    from cust_products
    group by customer_id
    Edited by: user497841 on Feb 4, 2010 2:12 PM

  • PL/SQL Block with Cursor

    I was trying to create a PL/SQL block where I am trying to call all the SQL Plans and then drop them one by one. Here is how I am doung -
    SET SERVEROUT ON;
    DECLARE
    EXECSTR VARCHAR2(50);
    v_plans_dropped pls_integer;
    CURSOR C1 IS SELECT SQL_HANDLE FROM DBA_SQL_PLAN_BASELINES;
    BEGIN
    FOR I IN C1 LOOP
    EXECSTR := ''''||I.SQL_HANDLE||'''';
    v_plans_dropped:=dbms_spm.drop_sql_plan_baseline(sql_handle=>EXECSTR);
    END LOOP;
    EXCEPTION
    WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('ERROR while dropping SQL PLAN: ' || SQLCODE || ' : ' || SQLERRM);
    END;
    This is giving me error like - ERROR while dropping SQL PLAN: -38131 : ORA-38131: specified SQL handle
    'SYS_SQL_1470897e7b72c982' does not exist
    Whereas this SQL Plan is there in the baseline - SELECT sql_handle FROM dba_sql_plan_baselines;
    SQL_HANDLE
    SYS_SQL_1470897e7b72c982
    SYS_SQL_75ac336a8071cb06
    SYS_SQL_269cdcd4862f8685
    SYS_SQL_269cdcd4862f8685
    SYS_SQL_0ffdb3bddbe422e2
    SYS_SQL_14d81bbae4a7cc93
    SYS_SQL_5c512b58e7795ba2
    SYS_SQL_33515785e80b75d0
    Above PL/SQL block should be same as like deleting it one by one -
    DECLARE
    v_plans_dropped pls_integer;
    BEGIN
    v_plans_dropped:=dbms_spm.drop_sql_plan_baseline(sql_handle=>'SYS_SQL_1470897e7b72c982');
    END;
    If I run this then it will be sucessul but when I run under a PL/SQL block using cursor then it is giving me error ORA-38131.
    Can you please tell me where I am going wrong here.
    Thanks for your time!

    I have this PL/SQL block -
    DECLARE
    v_plans_dropped pls_integer;
    CURSOR C1 IS SELECT SQL_HANDLE FROM DBA_SQL_PLAN_BASELINES;
    BEGIN
    FOR I IN C1 LOOP
    v_plans_dropped:=dbms_spm.drop_sql_plan_baseline(sql_handle=>I.SQL_HANDLE);
    END LOOP;
    END;
    Requirement - This PL/SQL block should read all the records from DBA_SQL_PLAN_BASELINES table and drop all the plans one by one.
    Problem - It gives me error like this -
    SQL> 2 3 4 5 6 7 8 9 DECLARE
    ERROR at line 1:
    ORA-38131: specified SQL handle SYS_SQL_45c1170505dda9a9 does not exist
    ORA-06512: at "SYS.DBMS_SPM", line 2444
    ORA-06512: at line 6
    Analysis: When I ran it 4 times, it showed me that the remaining records after the pl/sql run was like -
    SQL> SELECT COUNT(*) FROM DBA_SQL_PLAN_BASELINES;
    After First Run -
    COUNT(*)
    33429
    After Second Run -
    COUNT(*)
    33255
    After Third Run -
    COUNT(*)
    33228
    After Fourth Run -
    COUNT(*)
    32988
    So, it deletes records but errors out in between. Is it because the PL/SQL block/cursor is not structured properly?
    Thanks for your advice!

  • Performance issue while wrapping the sql in pl/sql block

    Hi All,
    I am facing performance issue in a query while wrapping the sql in pl/sql block.
    I have a complex view. while quering the view using
    Select * from v_csp_tabs(Name of View I am using), it is taking 10 second to fetch 50,000 records.
    But when I am using some conditions on the view, Like
    Select * from v_csp_tabs where clientid = 500006 and programid = 1 and vendorid = 1, it is taking more then 250 secs. to return the result set.
    now the weird part is this is happening only for one programID, that is 1
    I am using Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    Any one please suggest what are the things i need to check..
    I am sorry, I could not provide you the explain plan, because this is in production and I do not have enough prevelage.
    Thank you in advance.
    Thnx,
    Bits

    Bits wrote:
    I have a complex view. while quering the view using
    Select * from v_csp_tabs(Name of View I am using), it is taking 10 second to fetch 50,000 records.
    But when I am using some conditions on the view, Like
    Select * from v_csp_tabs where clientid = 500006 and programid = 1 and vendorid = 1, it is taking more then 250 secs. to return the result set.That's one problem with views - you never know how they will be used in the future, nor what performance implications variant uses can have.
    >
    now the weird part is this is happening only for one programID, that is 1
    Any one please suggest what are the things i need to check..
    I am sorry, I could not provide you the explain plan, because this is in production and I do not have enough prevelage.I understand what you are saying - I have worked at similar sites. HiddenName is correct in suggesting that you need to get execution plans but sometimes getting privileges from the DBA group is simply Not Going To Happen. Its wrong but that's the way it is. Follow through on HiddenName's suggested to get help from somebody who has the privleges needed
    Post the query that view view is executing. Desk checking a query is NOT ideal but is one thing we can do.
    I don't suppose you can see V$ views on production - V$SQL and V$SQL_PLAN (probably not if you can't generate plans, but its worth a thought)

Maybe you are looking for

  • Execute owb mapping as a whole instead of giving step by step or skip

    Hi friends, I need a help from you.. Actually i am working with owb 10.2 and db 10.2. I am able to do all the process successfully like debugging, reinitializing and entering the data into the table. The thing is while debugging,i have to give step o

  • How to prompt for user input in Forms

    How do I prompt for user input in Forms? I am writing a piece of code where the user may choose, by clicking either of three buttons on an alert, to have the system assign a value to a variable, to input a value or to do neither? If the user chooses

  • How to rotate a large table

    I'm building a long technical report with Pages'08. There are many tables in this report. This document is in portrait format. In the middle of this document I have a particularly large table which can't be read if I try to stay on a portrait present

  • Changing icons on the dock

    Hi, i just get some new funny icons i'd install on my dock instead of the defaults one. Anybody knows how i get to it?

  • How in CF8 I can identify type of cfinput/input???

    Hello to all!!! How in CF8 I can identify type of cfinput/input??? For instance, I want to make some code for <input type="text"> or I want to get all form fieldnames with exception "submit" Thanks for your answers!!!!