Hello everyone again,
I'm having trouble with a stored procedure. I can't understand why it will NOT make a prepare statement out of a string. Really stuck here. Any ideas will be greatly appreciated.
Code:
DECLARE FORMULA_V VARCHAR(3900);
DECLARE STMT VARCHAR(4500);
DECLARE CURSOR_COTA CURSOR FOR PREP_STMT;
SELECT RTRIM(LTRIM(FORMULA)) INTO FORMULA_V
FROM FORMULA_TABLE
WHERE ID = SP_GET_VALUE.ID;
SET STMT = 'SELECT ('||FORMULA_V||') AS VALOARE FROM '||SP_GET_VALUE.TABLE_NAME||' WHERE ID = '||CHAR(ID_UNIC);
insert into poi values(3,stmt);
PREPARE PREP_STMT FROM STMT;
OPEN CURSOR_COTA;
insert into poi values(3,'opened cursor');
I've run the procedure in debug mode and it just crashes at the PREPARE statement. If I simply run the STMT from the poi table it executes just fine.
The error's description is this:
42704 An undefined object or constraint name was detected. -204
When I call the procedure from the application it crashes at FETCH. I have absolutly no idea what's wrong. Could it be that the varchar is too big? Would that create a problem? Why can I execute the STMT from the poi table and it just crashes at the PREPARE?
Thank you.
Iulia S