我需要在dbms_output語句中包含單引號。我已經試過這樣:
dbms_output語句中的單引號?
dbms_output.put_line('\''first_name||'\'');
這裏FIRST_NAME正在variable
;我需要在單引號內顯示。
我需要在dbms_output語句中包含單引號。我已經試過這樣:
dbms_output語句中的單引號?
dbms_output.put_line('\''first_name||'\'');
這裏FIRST_NAME正在variable
;我需要在單引號內顯示。
你會加倍了逃避:
dbms_output.put_line('''' || first_name || '''');
或使用q-quote機制:
dbms_output.put_line(q'[']'||first_name||q'[']');
如:
SQL> var b1 varchar2(30)
SQL> exec :b1 := 'this is a test';
PL/SQL procedure successfully completed.
SQL> exec dbms_output.put_line(q'[']'||:b1||q'[']');
'this is a test'
PL/SQL procedure successfully completed.
SQL> exec dbms_output.put_line(''''||:b1||'''');
'this is a test'
PL/SQL procedure successfully completed.
SQL> exec dbms_output.put_line(chr(39)||:b1||chr(39));
'this is a test'
PL/SQL procedure successfully completed.
請注意,這只是針對PL/SQL並且必須是積極的。
begin
DBMS_OUTPUT.PUT_LINE('DELETE FROM MYTABLE WHERE MYFIELD <> ''A'';');
end;
/
假設您想匹配CHAR
'A'。
如果first_name擁有xyx,那麼我的輸出將是'xyz'。這是我試圖獲得的wat。 –
可能重複的[如何在Oracle SQL中處理單引號](http://stackoverflow.com/questions/2875257/how-to-handle-a-single-quote-in-oracle-sql) –
可能的重複[如何在Oracle SQL中處理單引號](https://stackoverflow.com/questions/2875257/how-to-handle-a-single-quote-in-oracle-sql) –