我需要在dbms_output语句中包含单引号。我试过这个:
dbms_output.put_line('\''first_name||'\'');
此处first_name为 variable
;我需要在单引号内显示它。
答案 0 :(得分:7)
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.
答案 1 :(得分:0)
请注意,这仅适用于PL / SQL,必须处于活动状态。
begin
DBMS_OUTPUT.PUT_LINE('DELETE FROM MYTABLE WHERE MYFIELD <> ''A'';');
end;
/
假设您想要匹配CHAR
&#39; A&#39;。