我需要在 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'。