ORGANIZATION_CODE must be declared [message #602228] |
Mon, 02 December 2013 01:45 |
|
mist598
Messages: 1195 Registered: February 2013 Location: Hyderabad
|
Senior Member |
|
|
Hi all,
can any one suggest below problem
declare
P_ORGANIZATION_CODE varchar2(240);
a SYS_REFCURSOR;
TYPE empd IS TABLE of hope.hope_forecast_data%ROWTYPE;
empdet empd;
begin
open a for select * from hope.hope_forecast_data
WHERE ORGANIZATION_CODE=: P_ORGANIZATION_CODE;
FETCH a BULK COLLECT INTO empdet;
DBMS_OUTPUT.PUT_LINE('Organisation code:'|| ' '|| empdet.ORGANIZATION_CODE);
end;
Thank you
|
|
|
Re: ORGANIZATION_CODE must be declared [message #602229 is a reply to message #602228] |
Mon, 02 December 2013 01:58 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
The problem is the way you are referring to a collection,
mist598 wrote on Mon, 02 December 2013 13:15
DBMS_OUTPUT.PUT_LINE('Organisation code:'|| ' '|| empdet.ORGANIZATION_CODE);
The correct way of referring to the collection EMPDET is :
SQL> set serveroutput on;
SQL>
SQL> DECLARE
2 P_ORGANIZATION_CODE VARCHAR2(240);
3 A SYS_REFCURSOR;
4 TYPE EMPD IS TABLE OF HOPE_FORECAST_DATA%ROWTYPE;
5 EMPDET EMPD;
6 BEGIN
7 OPEN A FOR
8 SELECT * FROM HOPE_FORECAST_DATA WHERE ORGANIZATION_CODE = 'abcd';
9 FETCH A BULK COLLECT
10 INTO EMPDET;
11 FOR I IN 1 .. EMPDET.COUNT LOOP
12 DBMS_OUTPUT.PUT_LINE('Organisation code:' || ' ' || EMPDET(I)
13 .ORGANIZATION_CODE);
14 END LOOP;
15 END;
16 /
Organisation code: abcd
Organisation code: abcd
Organisation code: abcd
Organisation code: abcd
Organisation code: abcd
PL/SQL procedure successfully completed
Another thing, whenever you post your code having issues, please post the entire session from SQL*Plus along with the errors. It will contain the error number and the exact line. That's how you should debug your code.
Also, always post the version of your DB.
Regards,
Lalit
[Updated on: Mon, 02 December 2013 02:10] Report message to a moderator
|
|
|
|