0

I'm trying to put the result of the query into a bind variable like this, but doesn't work:

var teste number;
exec :teste := (select trunc(avg(e.salary),2) from hr.employees e);

How I make it to work? I don't want to use a PL/SQL block.

asked Aug 23, 2019 at 12:16

1 Answer 1

1

exec is a PL/SQL block:

SQL> var teste number
SQL> exec select trunc(avg(user_id)) into :teste from dba_users;
PL/SQL procedure successfully completed.
SQL> print :teste
 TESTE
----------
 447392453

It is the same as:

begin
 select trunc(avg(user_id)) into :teste from dba_users;
end;
/

SQL*Plus substitution variable:

SQL> column my_value new_value teste
SQL> select trunc(avg(user_id)) my_value from dba_users;
 MY_VALUE
----------
 447392453
SQL> define teste
DEFINE TESTE = 447392453 (NUMBER)
SQL>
answered Aug 23, 2019 at 12:36

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.