Here is:
declare
v_str1 varchar2(80);
begin
v_str1 := 'test';
print :v_str1;
end
When I run it using SQLDeveloper just in a sql worksheet I get this:
Bind Variable "v_str1" is NOT DECLARED
anonymous block completed
You simply have to write a command which starts with keyword VARIABLE followed by the name of your bind variable which is completely user defined along with the data type and data width. That's how we declare a bind variable in Oracle database.
Bind variables are variables you create in SQL*Plus and then reference in PL/SQL. If you create a bind variable in SQL*Plus, you can use the variable as you would a declared variable in your PL/SQL subprogram and then access the variable from SQL*Plus.
In the above example, we first type a colon (:) immediately followed by the variable name. This is a very simple way to reference the bind variable. If we want to change the bind variable in SQL*plus, then we need to write the PL/SQL block.
To use bind variables in an Oracle SQL query, you use the colon character : to indicate a bind variable. You use : then the variable name.
print
is not a PLSQL function. If you want to get an output, you can use dbms_output.put_line(v_str1);
set serveroutput on;
declare v_str1 varchar2(80);
begin
v_str1 := 'test';
dbms_output.put_line(v_str1);
end;
:v_str1 is a bind variable but you must declare not in a plsql. When you declare it you must use VARIABLE keyword.
Got it:
set serveroutput on
declare
v_str1 varchar2(80);
begin
v_str1 := 'test';
dbms_output.put_line(v_str1);
end;
More info here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With