0

I'm finishing a PL/SQL block but the final update statement is giving me a headache.

The following EXECUTE INMEDIATE thows me an SQLCODE -932 and program breaks.

EXECUTE IMMEDIATE 'UPDATE RS2QTCIN cin SET cin.date_end = '|| dateINSERT ||' WHERE cin.id = '|| REG1.c1id;

The query is just simple, dateINSERT is a variable defined in the declaration block and the value at the end(REG1.c1id), is a result of a cursor also defined.

The update query seems correct and the variables are concatenated with the query string.

1
  • 1
    Save the query to a string. Then look at the string. The error will be obvious. Or, better yet, fix the execute to use parameters. Don't munge query strings with constant values. Commented Mar 24, 2020 at 15:47

1 Answer 1

1

Don't concatenate parameters into the SQL string, use placeholders instead:

EXECUTE IMMEDIATE 'UPDATE RS2QTCIN cin SET cin.date_end = :1 WHERE cin.id = :2'
  USING dateINSERT, REG1.c1id;

But as there are no dynamic identifiers in your SQL, you don't need dynamic SQL to begin with:

UPDATE RS2QTCIN cin 
    SET cin.date_end = dateINSERT 
WHERE cin.id = REG1.c1id;
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, works great and also great examples to use in the future.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.