Home » SQL & PL/SQL » SQL & PL/SQL » ORGANIZATION_CODE must be declared
ORGANIZATION_CODE must be declared [message #602228] Mon, 02 December 2013 01:45 Go to next message
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 Go to previous messageGo to next message
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

Re: ORGANIZATION_CODE must be declared [message #602230 is a reply to message #602229] Mon, 02 December 2013 02:11 Go to previous message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Thank you very much!
Previous Topic: ORA-00935: group function is nested too deeply
Next Topic: Comma Delimited String
Goto Forum:
  


Current Time: Fri Apr 26 04:56:36 CDT 2024