DBAsupport.com Forums - Powered by vBulletin
Results 1 to 4 of 4

Thread: doubt

  1. #1
    Join Date
    Jun 2008
    Posts
    3

    Red face doubt

    create table emp( first_name varchar2(16),last_name varchar2(16), hire_date date);


    set serveroutput on
    set timing on

    DECLARE
    TYPE emp_name_rec is RECORD (
    firstname emp.first_name%TYPE,
    lastname emp.last_name%TYPE,
    hiredate emp.hire_date%TYPE );
    TYPE EmpList_tab IS TABLE OF emp_name_rec;
    SeniorSalespeople EmpList_tab;
    EndCounter NUMBER := 10;
    TYPE EmpCurTyp IS REF CURSOR;
    emp_cv EmpCurTyp;
    BEGIN
    OPEN emp_cv FOR SELECT first_name, last_name, hire_date FROM emp;
    loop
    FETCH emp_cv BULK COLLECT INTO SeniorSalespeople;
    exit when emp_cv%notfound;
    end loop;
    CLOSE emp_cv;
    IF SeniorSalespeople.LAST > 0 THEN
    IF SeniorSalespeople.LAST < 10 THEN
    EndCounter := SeniorSalespeople.LAST;
    END IF;
    FOR i in 1..EndCounter LOOP
    DBMS_OUTPUT.PUT_LINE(SeniorSalespeople(i).lastname || ', '
    || SeniorSalespeople(i).firstname || ', ' || SeniorSalespeople(i).hiredate);
    END LOOP;
    END IF;
    END;
    /


    when i run this block i got error

    FETCH emp_cv BULK COLLECT INTO SeniorSalespeople;
    *
    ERROR at line 14:
    ORA-06550: line 14, column 32:
    PLS-00597: expression 'SENIORSALESPEOPLE' in the INTO list is of wrong type
    ORA-06550: line 14, column 1:
    PL/SQL: SQL Statement ignored
    Elapsed: 00:00:00.00


    plz tell me where i made mistake

  2. #2
    Join Date
    Mar 2000
    Location
    Atlanta, GA,USA
    Posts
    155
    Combination of first_name, last_name, hire_date fields is not the same as record type emp_name_rec defined for your table type. You need to use cast to convert them to expected data type.

    Sergey

  3. #3
    Join Date
    Jun 2008
    Posts
    3

    Wink doubt

    can u explain this scenario briefly????

    plz give correct code.

  4. #4
    Join Date
    Mar 2000
    Location
    Atlanta, GA,USA
    Posts
    155
    Your open cursor code should look like this:

    OPEN emp_cv FOR SELECT emp_name_rec(first_name, last_name, hire_date) FROM emp;

    Sergey

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width