解决oracle绑定变量

时间:2015-11-05 08:57:40

标签: oracle11g

我正在尝试使用Bind Variables。但是被困在这件作品上。无法编译它: -

  VARIABLE b_basic_percent NUMBER
  VARIABLE b_pf_percent NUMBER

 DECLARE 
   v_today DATE:=SYSDATE;        
   v_tomorrow v_today%TYPE;

 BEGIN 
   v_tomorrow:=v_today +1; 
   :b_basic_percent:=45; 
   :b_pf_percent:=12;
   DBMS_OUTPUT.PUT_LINE(' Hello World '); 
   DBMS_OUTPUT.PUT_LINE('TODAY IS : '|| v_today); 
   DBMS_OUTPUT.PUT_LINE('TOMORROW IS : ' || v_tomorrow); 

   PRINT  b_basic_percent 
   PRINT b_pf_percent

END;

有人可以帮助我了解我哪里出错了吗?

1 个答案:

答案 0 :(得分:0)

PRINT是SQL * Plus命令,而不是PL / SQL命令。因此,它应该在之后强调PL / SQL块(与块之前发生的VARIABLE非常相似),如下所示:

variable b_basic_percent number
variable b_pf_percent number

declare 
  v_today date:=sysdate;        
  v_tomorrow v_today%type;

begin 
  v_tomorrow := v_today + 1; 
  :b_basic_percent := 45; 
  :b_pf_percent := 12;
  dbms_output.put_line(' Hello World '); 
  dbms_output.put_line('TODAY IS : '|| to_char(v_today, 'dd Mon yyyy')); 
  dbms_output.put_line('TOMORROW IS : ' || to_char(v_tomorrow, 'dd Mon yyyy')); 

end;
/

print b_basic_percent 
print b_pf_percent


 Hello World 
TODAY IS : 05 Nov 2015
TOMORROW IS : 06 Nov 2015

b_basic_percent
---------------
             45

b_pf_percent
------------
          12