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

后端 未结 4 1117
一整个雨季
一整个雨季 2020-12-20 13:07

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 w

相关标签:
4条回答
  • 2020-12-20 13:20

    Try

    declare
      v_str1   varchar2(80);
    begin
      v_str1 := 'test';
      print v_str1;
    end
    
    0 讨论(0)
  • 2020-12-20 13:25

    Got it:

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

    More info here.

    0 讨论(0)
  • 2020-12-20 13:31

    The bind variables syntax of the form :VARNAME are used primarily in SQL* Plus (except for bind variables for dynamic SQL, I think). For SQL* Developer, PL/SQL Developer, or other apps, there is the "&" for variable substitution:

    
    declare
      v_str1   varchar2(80);
    begin
      v_str1 := &v_str;
      print v_str1;
    end
    
    

    EDIT: My bad, the code for Oracle SQL*Developer should have been:

    
    set serveroutput on;
    declare
      v_str1   varchar2(80);
    begin
      v_str1 := '&v_str';
      dbms_output.put_line(v_str1);
    end;
    

    You have to select everything and execute it. The result will appear in the "Script Output" panel.

    0 讨论(0)
  • 2020-12-20 13:37

    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.

    0 讨论(0)
提交回复
热议问题