oracle中动态sql中的链接语句
chaining statements in dynamic sql in oracle
我遇到了以下用于在 oracle 中创建过程的语法。我想知道语法中使用的 a' 、 q'a 、 q'z 和 z' 是什么。
谁能解释一下这些构造的用法。
**
EXECUTE IMMEDIATE 'CREATE OR REPLACE PROCEDURE "demoproc" '|| '( FIXCARD in number DEFAULT 0, INC in number DEFAULT 0 ) '|| 'AUTHID DEFINER IS '|| 'CARD NUMBER; '|| 'FOWNER VARCHAR2(128) := '|| ' SYS_CONTEXT(''USERENV'',''CURRENT_SCHEMA''); '|| 'BEGIN '|| 'EXECUTE IMMEDIATE '|| ''' EXPLAIN PLAN FOR '' || '|| q'z q'a SELECT a' || q'a z' || q'z "demotab"."a" AS "F_NO",
:B7 a' || q'a z' || q'z AS "P_NO"
FROM "demotab" "demotab"
WHERE (
a' || q'a z' || q'z "demotab"."b" = :B17 AND
a' || q'a z' || q'z "demotab"."c" = :B2 AND
a' || q'a z' || q'z "demotab"."d" = :B16
) a' ;
**
注意:语法可能不完整。
此语法用于准确处理引号之间的字符串;您决定用作分隔符的字符,然后在字符串的开头和结尾使用它;一些例子:
select 'quote here: ''' , 'double quote'from dual union all
select q'@quote here: ''@', 'q syntax, double quote means two quotes' from dual union all
select q'@quote here: '@', 'q syntax, no need fou double quotes' from dual union all
select 'two quotes here: ''''', 'same thing to have two quotes' from dual union all
select q'@two quotes here: ''@', 'and two quotes with q syntax ' from dual union all
select q'@this is the delimiter char: @.@', 'the delimiter character can be used wherever in the string' from dual union all
select q'@@delimiter is in the beginning and in the end@@', 'you have to double the delimiter if you want it in the end or beginning' from dual
您可以查看文档 here
q' ' 是一种用嵌入的引号引用字符串文字的方法
例如
select q'x It's a string x' From dual;
It's a string
语法为 q'[...]',其中“[”和“]”是示例中的字符 a' 和 z'。因此 select q'z execute immediate q'a SELECT count(1) from dual a'z' from dual
变成 execute immediate q'a SELECT count(1) from dual a'
示例查询下方
-- quoting string literals (new from 10G)
select q'aIt's string with embedded quotesa' from dual -- string terminated by chacter "a"
union all
select 'It''s string with embedded quotes' from dual--quotes using a 2 quotes
union all
select q'z execute immediate q'a SELECT count(1) from dual a'z' from dual ; -- your example
我遇到了以下用于在 oracle 中创建过程的语法。我想知道语法中使用的 a' 、 q'a 、 q'z 和 z' 是什么。
谁能解释一下这些构造的用法。
**
EXECUTE IMMEDIATE 'CREATE OR REPLACE PROCEDURE "demoproc" '|| '( FIXCARD in number DEFAULT 0, INC in number DEFAULT 0 ) '|| 'AUTHID DEFINER IS '|| 'CARD NUMBER; '|| 'FOWNER VARCHAR2(128) := '|| ' SYS_CONTEXT(''USERENV'',''CURRENT_SCHEMA''); '|| 'BEGIN '|| 'EXECUTE IMMEDIATE '|| ''' EXPLAIN PLAN FOR '' || '|| q'z q'a SELECT a' || q'a z' || q'z "demotab"."a" AS "F_NO",
:B7 a' || q'a z' || q'z AS "P_NO"
FROM "demotab" "demotab"
WHERE (
a' || q'a z' || q'z "demotab"."b" = :B17 AND
a' || q'a z' || q'z "demotab"."c" = :B2 AND
a' || q'a z' || q'z "demotab"."d" = :B16
) a' ;
**
注意:语法可能不完整。
此语法用于准确处理引号之间的字符串;您决定用作分隔符的字符,然后在字符串的开头和结尾使用它;一些例子:
select 'quote here: ''' , 'double quote'from dual union all
select q'@quote here: ''@', 'q syntax, double quote means two quotes' from dual union all
select q'@quote here: '@', 'q syntax, no need fou double quotes' from dual union all
select 'two quotes here: ''''', 'same thing to have two quotes' from dual union all
select q'@two quotes here: ''@', 'and two quotes with q syntax ' from dual union all
select q'@this is the delimiter char: @.@', 'the delimiter character can be used wherever in the string' from dual union all
select q'@@delimiter is in the beginning and in the end@@', 'you have to double the delimiter if you want it in the end or beginning' from dual
您可以查看文档 here
q' ' 是一种用嵌入的引号引用字符串文字的方法
例如
select q'x It's a string x' From dual;
It's a string
语法为 q'[...]',其中“[”和“]”是示例中的字符 a' 和 z'。因此 select q'z execute immediate q'a SELECT count(1) from dual a'z' from dual
变成 execute immediate q'a SELECT count(1) from dual a'
示例查询下方
-- quoting string literals (new from 10G)
select q'aIt's string with embedded quotesa' from dual -- string terminated by chacter "a"
union all
select 'It''s string with embedded quotes' from dual--quotes using a 2 quotes
union all
select q'z execute immediate q'a SELECT count(1) from dual a'z' from dual ; -- your example