SQL> var x number --> declare it at SQL level
SQL> exec :x := 5 --> set its value
PL/SQL procedure successfully completed.
SQL> set serveroutput on
SQL> begin
2 dbms_output.put_line(:x * :x); --> use it in PL/SQL
3 end;
4 /
25 --> result
PL/SQL procedure successfully completed.
SQL>
SQL> begin
2 l_var number;
3 end;
4 /
l_var number;
*
ERROR at line 2:
ORA-06550: line 2, column 9:
PLS-00103: Encountered the symbol "NUMBER" when expecting one of the following:
:= . ( @ % ;
The symbol ":=" was substituted for "NUMBER" to continue.
2条答案
按热度按时间isr3a4wc1#
使用PL/SQL块的
DECLARE
部分声明变量:gblwokeq2#
您尝试的
var
与Oracle的命令行工具SQL*Plus有关。你会用吗当然可以:
[编辑],基于您的评论:如果你想在PL/SQL块的executable部分声明变量,你不能按照你想要的方式来做:
变量将在
DECLARE
节中声明(这是语法的说法):但是,您可以 * 嵌入 * 一个新的PL/SQL块到现有的可执行部分-只需遵循规则(
DECLARE
!):或者,您可以创建一个包含变量、常量等的包。