OCA题库中
14.View the exhibit and examine the structure of the PRODUCTS table.
You need to generate a report in the following format:
CATEGORIES
5MPdigital photo Camera’s category is photo 
Y Box’s category is Electronics
Envoy Ambassador’s category is Hardware
Which two queries would give the required output?
 
A. select prod_name||q’’’s category is ‘|| prod_category CATEGORYS FROM products.
B. select prod_name||q’[‘s]’ category is ‘|| prod_category CATEGORYS FROM products.
 
C.select prod_name||q'\'s\'||'category is'|| prod_category category FROM products.
D.select prod_name||q'<'s>'||'category is'|| prod_category category FROM products.
答案选CD
请问一下各位这个题语句q是什么意思啊?为什么我放到数据库中执行会报q关键字找不到。把q换成字符的话,就会提示引号没有正常结束。高手帮忙分析一下,这SQL语句?感谢!

解决方案 »

  1.   

    在oracle10g之前,如果字符串文本包含单引号,那么必须使用两个单引号表示
    例如:要为某个字符串变量赋值I'm a boy,那么必须用str:='I''m a boy';
    在10g之中,如果字符串包含单引号,可以使用其他分隔符([],{},<>等)
    如果使用其他分隔符不仅要在分隔符前后加单引号,而且要带前缀q
    str:=q'[I'm a boy]';
      

  2.   

    呵呵,正解!有了这个,动态拼接SQL就比较容易多了,不用考虑一些引号的问题