Home > other >  How to initialize a value on a bind variable in the oracle apex?
How to initialize a value on a bind variable in the oracle apex?

Time:12-19

I'm having problems when executing this code in oracle apex:

VARIABLE b_var NUMBER(20);

BEGIN 
   :b_var := 100; 
END;

PRINT b_var;

what I am trying to do is initialize a value to a bind variable then display it to the console. But it always asks me to input a value which is not my expected result.

enter image description here

CodePudding user response:

These are 2 questions mixed into 1.

  1. How to use a bind variable in APEX sql workshop.

Note that the sql workshop is NOT sqlplus. It is a web interface that executes individual statements. To get a bind variable there is no need to define it like in sqlplus. Just put it in your anonymous pl/sql block like this. Note that in your sample code you're not using bind variables correctly. The bind variable references a variable value - not the actual variable.

  1. How to print output in the workshop.

The command "PRINT" is a sqlplus command - that won't work. Use dbms_output.put_line instead.

Putting it all together gives:

DECLARE 
  l_var VARCHAR2(100);
BEGIN 
   l_var := :b_var; 
   dbms_output.put_line(l_var);
END;
/
  • Related