Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is wrong with this PL/SQL? Bind Variable * is NOT DECLARED

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
like image 940
NitroxDM Avatar asked Oct 20 '09 23:10

NitroxDM


People also ask

How do you declare bind variables in PL SQL?

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.

What is bind variable in Oracle PL SQL?

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.

How do you refer to bind variables?

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.

How do you bind variables in SQL query?

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.


2 Answers

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.

like image 77
EREN Avatar answered Oct 15 '22 23:10

EREN


Got it:

set serveroutput on

declare
  v_str1   varchar2(80);    
begin
 v_str1 := 'test';
 dbms_output.put_line(v_str1);
end;

More info here.

like image 40
NitroxDM Avatar answered Oct 15 '22 23:10

NitroxDM