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;"
Solution: identifier 'V_CUR' must be declared
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; /