1

it's possible to execute a string as a SQL query in C and get the result? I'm trying to compile this code:

EXEC SQL
    EXECUTE IMMEDIATE : sql_formula INTO :sql_prec_desconto_mp;

But I've this error:

Error at line 10548, column 35 in file

D:\syncs\AIX\fuentes\funcn\niv2\src\rutin as.pc

            EXECUTE IMMEDIATE : sql_formula INTO :sql_prec_desconto_mp;

PCC-S-02201, Encountered the symbol "INTO" when expecting one of the following:

; ( [ . ++ -- ->

How can I get the result of the SQL query? If I remove the INTO clause I can compile without errors.

Thanks in advance.

1 Answer 1

1

That format is described in the documentation:

To prepare and execute a DELETE, INSERT, or UPDATE statement or a PL/SQL block containing no host variables.

You aren't doing one of those DML types, and those don't recognise INTO. When you run a dynamic SQL query without an INTO the query is never actually executed (see the note in the docs).

The quickest way that immediately comes to mind to do what I think you want, is to prepare a cursor and fetch the result:

EXEC SQL PREPARE stmt FROM :sql_formula;
EXEC SQL DECLARE cur CURSOR FOR stmt;
EXEC SQL OPEN cur;
EXEC SQL FETCH cur INTO :sql_prec_desconto_mp;
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer, that code solved my problem! :)

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.