编者按:
停更了2个月,重新起航。
最好的学习是实践加上看官方文档。官方文档中的代码例更是精华和重点所在。
IT行业如此,编程如此,Oracle PL/SQL的学习更是如此。
本系列以摘自《Database PL/SQL Language Reference》的PL/SQL代码例为主进行介绍。
【免责声明】本公众号文章仅代表个人观点,与任何公司无关。

编辑|SQL和数据库技术(ID:SQLplusDB)
Oracle PL/SQL例2:处理查询的结果行(基础循环)
通过双引号可以达到区分大小写,使用Oracle保留字的目的。
示例2-1:自定义标识符的不区分大小写的有效引用
DECLARE"HELLO" varchar2(10) := 'hello';BEGINDBMS_Output.Put_Line(Hello);END;/
结果:
hello
示例2-2 自定义标识符的不区分大小写的无效引用
DECLARE"HELLO" varchar2(10) := 'hello';BEGINDBMS_Output.Put_Line("Hello");END;/
结果:
DBMS_Output.Put_Line("Hello");*ERROR at line 4:ORA-06550: line 4, column 25:PLS-00201: identifier 'Hello' must be declaredORA-06550: line 4, column 3:PL/SQL: Statement ignored
示例2-3 通过双引号使用保留字
DECLARE"BEGIN" varchar2(15) := 'UPPERCASE';"Begin" varchar2(15) := 'Initial Capital';"begin" varchar2(15) := 'lowercase';BEGINDBMS_Output.Put_Line("BEGIN");DBMS_Output.Put_Line("Begin");DBMS_Output.Put_Line("begin");END;/
结果:
UPPERCASEInitial CapitallowercasePL/SQL procedure successfully completed.
示例2-4 双引号的忽略处理
DECLARE"HELLO" varchar2(10) := 'hello'; -- HELLO is not a reserved word"BEGIN" varchar2(10) := 'begin'; -- BEGIN is a reserved wordBEGINDBMS_Output.Put_Line(Hello); -- Double quotation marks are optionalDBMS_Output.Put_Line(BEGIN); -- Double quotation marks are requiredend;/
结果:
DBMS_Output.Put_Line(BEGIN); -- Double quotation marks are required*ERROR at line 6:ORA-06550: line 6, column 24:PLS-00103: Encountered the symbol "BEGIN" when expecting one of the following:( ) - + case mod new not null <an identifier><a double-quoted delimited-identifier> <a bind variable>table continue avg count current exists max min prior sqlstddev sum variance execute multiset the both leadingtrailing forall merge year month day hour minute secondtimezone_hour timezone_minute timezone_region timezone_abbrtime timestamp interval date<a string literal with character set specificat
示例2-5 大小写的区分
DECLARE"HELLO" varchar2(10) := 'hello'; -- HELLO is not a reserved word"BEGIN" varchar2(10) := 'begin'; -- BEGIN is a reserved wordBEGINDBMS_Output.Put_Line(Hello); -- Identifier is case-insensitiveDBMS_Output.Put_Line("Begin"); -- Identifier is case-sensitiveEND;/
结果:
DBMS_Output.Put_Line("Begin"); -- Identifier is case-sensitive*ERROR at line 6:ORA-06550: line 6, column 25:PLS-00201: identifier 'Begin' must be declaredORA-06550: line 6, column 3:PL/SQL: Statement ignored
文章转载自SQL和数据库技术,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




