Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Dynamic Queryies and Single Quotes in Variable. how to escape?

bostonmacosxJul 31 2012 — edited Jul 31 2012
What I'm dealing with is in the GROUPS variable. It comes in from a shuttle and one of the options has a single quote in it. I'm not sure how to escape the quote inside of the variable....thanks.
Rob



create or replace FUNCTION mobile_device_support(varstart IN VARCHAR,varstop IN VARCHAR,howgroup IN VARCHAR,hastotal IN VARCHAR,devices IN VARCHAR,groups IN VARCHAR)
RETURN VARCHAR2
is
l_var VARCHAR2(32767);
s_var VARCHAR2(32767);
BEGIN
l_var := q'!SELECT NULL LINK,to_char(open_time,'YYYY-!';
l_var := l_var || howgroup;
l_var := l_var || q'!') DATIME,!';

IF hastotal = 'Y' THEN
l_var := l_var || q'!sum(decode(LOGICAL_NAME,LOGICAL_NAME,'1',0)) "TOTAL",!';
END IF;

for r1 in (
SELECT DISTINCT LOGICAL_NAME as STATE

from

SMINCREQ

where

LOGICAL_NAME LIKE '%mobile%'
ORDER BY STATE

)


LOOP
s_var :=substr(r1.state,0,29);
l_var := l_var || 'sum(decode(LOGICAL_NAME,''' || r1.state || ''',''1'',0))"' || s_var || '",';
END LOOP;
l_var := rtrim(l_var, ',');
l_var := l_var || ' FROM SMINCREQ WHERE open_time between to_date('''|| varstart ||''',''DD-MON-YYYY'') and to_date('''|| varstop ||''',''DD-MON-YYYY'') and ';
l_var := l_var || '(INSTR('':';
l_var := l_var || devices;
l_var := l_var || ':'', '':''||LOGICAL_NAME||'':'') > 0) and';
l_var := l_var || '(INSTR('':';
l_var := l_var || groups;
l_var := l_var || ':'', '':''||ASSIGNMENT||'':'') > 0)';

l_var := l_var || 'GROUP BY to_char(open_time,''YYYY-'||howgroup||''') order by to_char(open_time,''YYYY-'||howgroup||''')';
RETURN l_var;
END;
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 28 2012
Added on Jul 31 2012
7 comments
2,692 views