2016-05-18 4 views
-1

oracleでのプロシージャ作成の構文は次のとおりです。私は構文で使用される '、q'a、q'z、およびz'が何であるか不思議でした。oracleの動的SQLでのステートメントの連結

誰かがこれらの構成の使用法を説明できますか?

**

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' ; 

**

注:構文は完全ではないかもしれません。

+0

' sqlstrをお試しくださいとなり実行されるステートメント –

答えて

0

qは」 '埋め込まれた引用符
例えばで文字列リテラルを引用する方法です見ることができます

select q'x It's a string x' From dual; 

It's a string
構文は、Q '[...]'、である "[" と "]" あなたの例では、文字A 'とZ' です。 `見るために; = 'PROCEDUREをCREATE OR REPLACE ...'` `、その後DBMS_OUTPUT.PUT_LINE(sqlstr):したがってselect q'z execute immediate q'a SELECT count(1) from dual a'z' from dualexecute 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 
1

この構文は、引用符間の文字列を正確に書かれた場所で処理するために使用されます。区切り文字として使用する文字を決定し、それを文字列の先頭と末尾に使用します。いくつかの例:

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: @[email protected]', 'the delimiter character can be used wherever in the string' from dual union all 
select q'@@delimiter is in the beginning and in the [email protected]@', 'you have to double the delimiter if you want it in the end or beginning' from dual 

あなたはドキュメントhere