今天碰到個&變數賦值的問題。
declare
uid number(10);
begin
uid:=&x;
end;
當&x輸入為空白時報如下錯
ORA-06550: 第 5 行, 第 9 列:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
( - + case mod new not null <an identifier>
<a double-quoted delimited-identifier> <a bind variable>
continue avg count current exists max min prior sql stddev
sum variance execute forall merge time timestamp interval
date <a string literal with character set specification>
<a number> <a single-quoted SQL string> pipe
更多精彩內容:http://www.bianceng.cnhttp://www.bianceng.cn/database/Oracle/
<一個帶有字元集說明的可帶引號的字串文字>
<一個可帶引號的 SQL
當&x輸入為字元時報如下錯
ORA-06550: 第 6 行, 第 25 列:
PLS-00306: wrong number or types of arguments in call to 'V'
ORA-06550: 第 6 行, 第 4 列:
PL/SQL: Statement ignored
而當將&x改為'&x'時,
uid:='&x';
無論輸入空還是字元都可以正常賦值。
所以實驗證明&變數要求輸入為數值,而且不可為空。
加上單引號'&變數'則可以輸入任一字元。
另外再記錄下如果碰到&字元如何處理
1.如果在查詢列裡遇到,
select 'B&R/SC' from dual;
可以用chr(38)替換
select 'B'||chr(38)||'R/SC' from dual;
2.如果在where條件裡遇到&字元
select * from test where id = 'b&c';
可以現在關閉&符號的功能
set define off;
然後再執行查詢語句。
本文出自 “richard的筆記-積微成著” 部落格,請務必保留此出處http://zxf261.blog.51cto.com/701797/722326