I need to include single quotes in dbms_output statement. I've tried this:
dbms_output.put_line('\''first_name||'\'');
Here first_name is variable
; I need to display this inside single quotes.
I need to include single quotes in dbms_output statement. I've tried this:
dbms_output.put_line('\''first_name||'\'');
Here first_name is variable
; I need to display this inside single quotes.
you'd escape by doubling up:
dbms_output.put_line('''' || first_name || '''');
or using the q-quote mechanism:
dbms_output.put_line(q'[']'||first_name||q'[']');
eg:
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.
Note that this is only for PL/SQL and must be active.
begin
DBMS_OUTPUT.PUT_LINE('DELETE FROM MYTABLE WHERE MYFIELD <> ''A'';');
end;
/
Assuming you want to match a CHAR
'A'.