[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

identifier 'V_CUR' must be declared

Posted on 2004-09-07
5
Medium Priority
?
2,874 Views
Last Modified: 2008-01-09
Hello guys

What's wrong ?
v_Cur is a ref cursor

begin
  v_Cur := GetALLRecordByIDG(FTable, FIDG);
  select max(ID) into v_maxid from v_Cur;    //------------------ Error : *
  return(v_maxid);
end;

*"Error: PLS-00201: identifier 'V_CUR' must be declared
Line: 93
Text: select max(ID) into v_maxid from v_Cur;"
0
Comment
Question by:wwwbetyar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 11

Expert Comment

by:cjjclifford
ID: 11995024
Is there a DECLARE section missing, where v_Cur is defined?
0
 
LVL 48

Expert Comment

by:schwertner
ID: 11995071
Ref Cursor should also be declared.
0
 

Author Comment

by:wwwbetyar
ID: 11996062
v_Cur is defined in the package header !

Header :
type
       refcur is ref cursor;  
...



Body :

function GetALLRecordByIDG(FTable in varchar2, --melyik tábla..
                           FIDG in number)     --..melyik IDG-je alapján
  return refcur is      
  v_Cur  refcur;    
  v_sql  long;
-- MODIFICATION HISTORY
-- Person          Date         Comments
-- --------------  -----------  -------------------------------------------
-- Visszatér az összes rekorddal amelynek IDG-je alapjan azonos (csak IDG-t tudjuk)
-- --------------  -----------  -------------------------------------------
-- Zalán Péter     2004.09.06.   Létrehozás
-- --------------  -----------  -------------------------------------------    
begin
  v_sql := 'select * from '||FTable||' where IDG='||to_char(FIDG);
  open v_Cur for v_sql;
  return(v_Cur);
end;  

and now ????
0
 
LVL 11

Expert Comment

by:cjjclifford
ID: 11996118
v_Cur cannot be accessed like that in the calling procedure.

What you have to do is something like:

-- test procedure part of the package defining "refcur"
PROCEDURE test_proc
IS
    v_Cur refcur;
BEGIN
    v_Cur := GetALLRecordByIDG(FTable, FIDG);
    -- etc, etc...
END;
/


0
 
LVL 11

Accepted Solution

by:
cjjclifford earned 100 total points
ID: 11996213
my previous post explains the 'rror: PLS-00201: identifier 'V_CUR' must be declared' error... however, you cannot use a cursor as a table/view in a select statement (as is tried in the following):

  1  declare
  2  type refcur is ref cursor;
  3  v_cur refcur;
  4  i number;
  5  begin
  6  open v_cur for 'SELECT 1 a, 2 b, 3 c, 4 d FROM dual';
  7  select max(a) into i from v_cur;
  8  dbms_output.put_line( 'max(a) : ' || i );
  9* end;
SQL> set serveroutput on
SQL> /
select max(a) into i from v_cur;
                          *
ERROR at line 7:
ORA-06550: line 7, column 27:
PL/SQL: ORA-00942: table or view does not exist
ORA-06550: line 7, column 1:
PL/SQL: SQL Statement ignored


What you should try and do is join the two procedures into one call...

DECLARE
    v_maxid NUMBER;
    v_id NUMBER := 100; -- whatever, probably parameter!
BEGIN
    SELECT max(id) INTO v_maxid
    FROM table_name WHERE id = :id
    USING v_id;
END;
/

However, it looks like you want to use one function to build generic select statements based on table_name and ID parameters.
so to do this in a single step:

CREATE FUNCTION get_maxid( in_tname IN  VARCHAR2, in_id IN VARCHAR2 ) RETURNS NUMBER
IS
    v_max NUMBER;
BEGIN
    -- Use placeholder to help Oracle cache SQL better!
    EXECUTE IMMEDIATE 'SELECT max( id ) FROM ' || in_tname || ' WHERE IDG = :id'
    INTO v_max
    USING in_id;
    RETURN v_max;
END;
/
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question