Q' 的使用

最近在项目经常看见使用q', 于是决定研究一下。 q'是oracle10g才有的新特性。 主要用于把字符串包含起来进行赋值。 特别在dynamic sql中,如果被包含的sql很复杂, 而且有单引号的情况下, 可以简单的表达,不用去拆分sql,和判断单双引号, 给程序的编写和阅读带来很大方便。q'可以支持多种配对分隔符。如#,{},[],/等等。

 

note that: 不管是q',还是原先得single quote, 都支持换行书写同一个字符串。

 字符串不支持双引号引用字符串, 而且在字符串中,用双引号代替单引号的方法好像也不好用。

 

SQL> select 'i am your boyfriend' MESSAGE from dual;

MESSAGE                                                                        
--------------------------------------                                         
i am your boyfriend                                                            

SQL>
SQL> select 'i am "your" boyfriend' MESSAGE from dual;

MESSAGE                                                                        
------------------------------------------                                     
i am "your" boyfriend                                                          

SQL>
SQL>
SQL> select "i am 'your' boyfriend" MESSAGE from dual;
select "i am 'your' boyfriend" MESSAGE from dual
       *
第 1 行出现错误:
ORA-00904: "i am 'your' boyfriend": invalid identifier


SQL>
SQL> select 'i am your
  2   boyfriend' MESSAGE from dual;

MESSAGE                                                                        
----------------------------------------                                       
i am your                                                                      
 boyfriend                                                                     
                                                                               

SQL>
SQL> select q'{what the fuck ' are you doing?}' MESSAGE from dual;

MESSAGE                                                                        
------------------------------------------------------------                   
what the fuck ' are you doing?                                                 

SQL>
SQL>
SQL> select q'/what the fuck ' are you doing?/' MESSAGE from dual;

MESSAGE                                                                        
------------------------------------------------------------                   
what the fuck ' are you doing?                                                 

SQL>
SQL> select q'{what the fuck
  2   ' are you doing?}' MESSAGE from dual;

MESSAGE                                                                        
--------------------------------------------------------------                 
what the fuck                                                                  
 ' are you doing?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值