oracle中的&變數和'&變數'

來源:互聯網
上載者:User

今天碰到個&變數賦值的問題。

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.