Have oracle stuff that I can't figure out where is the problem, if you could help me out here
ORA-00911: invalid character
ORA-06512: at line 20
Line 20 is EXECUTE IMMEDIATE SQL_STMT INTO P_COUNT USING L_RB_OD, L_RB_DO;
I have like 10-15 tables, and each of them have similar names and column that is TableName_ID
which contains sequence, so I made a procedure that will select certain amount of data (P_Bucket
) from table (P_Table
).
It will also select total amount of rows selected into P_COUNT
and return P_DATA sys_refcursor
. Procedure compiles successfully but won't execute.
DECLARE
P_PAR_01 VARCHAR2(5) := '2';
P_BUCKET NUMBER := 200;
P_TABLE VARCHAR2(15) := 'KB_FL_1';
P_COUNT NUMBER;
P_DATA SYS_REFCURSOR;
L_RB_OD NUMBER;
L_RB_DO NUMBER;
L_RB NUMBER;
SQL_STMT VARCHAR2(1000);
BEGIN
L_RB := CAST(P_PAR_01 AS NUMBER);
L_RB_DO := L_RB * P_BUCKET;
L_RB_OD := L_RB_DO - (P_BUCKET - 1);
SQL_STMT := 'SELECT COUNT(*)
FROM ' || P_TABLE || '
WHERE 1 = 1
AND ' || P_TABLE || '_ID BETWEEN :1 AND :2'; -- was :2;';
EXECUTE IMMEDIATE SQL_STMT INTO P_COUNT USING L_RB_OD, L_RB_DO;
OPEN P_DATA FOR
'SELECT * FROM ' || P_TABLE || '
WHERE 1 = 1
AND ' || P_TABLE || ' _ID BETWEEN :1 AND :2
ORDER BY ID_LICA' USING L_RB_OD, L_RB_DO; -- was ORDER BY ID_LICA;'
END;
EDIT: As comments says, dynamic SQL don't use semicolons, but even after removal of semicolons I get error invalid character
at OPEN P_DATA FOR