q Function in APEX: Escape Single Quotes:
Reference: http://www.talkapex.com/2009/ 03/q-function-escape-single- quotes.html
Instead of writing out a long description here's an example:
DECLARE
v_sql VARCHAR2 (255);
v_result VARCHAR2 (255);
BEGIN
v_sql := 'select ''hello'' into :a from dual';
EXECUTE IMMEDIATE v_sql
INTO v_result;
DBMS_OUTPUT.put_line (v_result);
END;
Notice how I had to put 2 single quotes around "Hello" to escape the single quote characters?
Now using the q function I don't need to do that:
DECLARE
v_sql VARCHAR2 (255);
v_result varchar2(255);
BEGIN
v_sql := q'!select 'hello' into :a from dual !';
EXECUTE IMMEDIATE v_sql
INTO v_result;
DBMS_OUTPUT.put_line (v_result);
END;
Notice now how "Hello" is wrapped as it would appear if it were not in variable definition function?
This can save you a lot of time by avoiding having to escape single quotes in strings!
Reference: http://www.talkapex.com/2009/
Instead of writing out a long description here's an example:
DECLARE
v_sql VARCHAR2 (255);
v_result VARCHAR2 (255);
BEGIN
v_sql := 'select ''hello'' into :a from dual';
EXECUTE IMMEDIATE v_sql
INTO v_result;
DBMS_OUTPUT.put_line (v_result);
END;
Notice how I had to put 2 single quotes around "Hello" to escape the single quote characters?
Now using the q function I don't need to do that:
DECLARE
v_sql VARCHAR2 (255);
v_result varchar2(255);
BEGIN
v_sql := q'!select 'hello' into :a from dual !';
EXECUTE IMMEDIATE v_sql
INTO v_result;
DBMS_OUTPUT.put_line (v_result);
END;
Notice now how "Hello" is wrapped as it would appear if it were not in variable definition function?
This can save you a lot of time by avoiding having to escape single quotes in strings!