Put single quote around input data

Hi all,
DB:10G
Have an input field (P10_item) with text value . Sometimes it can be multiple text values separated by , like T-123,T-870 . sometimes it only has 1 text value.
How do I construct a query that can take the item and convert the input value to the following example ? By using length function I can find out how many check no in the field but am lost in how to put the ' around each check no. Help
ex:
select * from payment where checkno in ('T-123','T-870')
thanks

with  t as
(select 'T-123,T-870'  txt from dual )
select replace(regexp_replace(txt,'(.+)','''\1'''),',',''',''')from t;
'T-123','T-870'sorry I did not understand what you wanted at first.
this shoud break p_10_item into multiple entries if it has commas in it and
then you can join it to the payment table.
WITH t AS (SELECT 'T-123,T-870' p_10_item FROM DUAL),
     t2
        AS (    SELECT REGEXP_SUBSTR (p_10_item,
                                      '[^\,]+',
                                      1,
                                      LEVEL)
                          checkno
                  FROM t
            CONNECT BY LEVEL <=
                            LENGTH (p_10_item)
                          - LENGTH (REPLACE (p_10_item, ','))
                          + 1)
SELECT payment.*
  FROM payment, t2
WHERE t2.checkno = payment.checknoEdited by: pollywog on May 18, 2011 1:14 PM

Similar Messages

  • How to put single quotes around selected data

    Is there a way to return selected column value with single quotes around it?
    Example I have a table:
    select name from test_table;
    returns: George Clooney
    I want it to return 'George Clooney'
    I tried: select '''||name||''' from test_table;
    returns: '||name||'

    ...or
    SCOTT@demo102> select chr(39)||ename||chr(39) from emp;
    CHR(39)||ENA
    'SMITH'
    'ALLEN'
    'WARD'
    'JONES'
    'MARTIN'
    'BLAKE'
    'CLARK'
    'SCOTT'
    'KING'
    'TURNER'
    'ADAMS'Nicolas.

  • SQL: Need help putting single quote around string

    I want to put single quotes around string in my output.
    I am running the following command as a test:
    select ' ' hello ' ' from dual;
    My expectation is to get 'hello' (Single quote around hello)
    However I am getting the following error:
    ERROR at line 1:
    ORA-00923: FROM keyword not found where expected
    When I do SHOW ALL at my SQL command prompt, the escape is set as follows:
    escape "\" (hex 5c)
    I even tried: select '\'hello\'' from dual;
    I get back: select ''hello'' from dual
    ERROR at line 1:
    ORA-00923: FROM keyword not found where expected

    Hi,
    user521525 wrote:
    I want to put single quotes around string in my output.
    I am running the following command as a test:
    select ' ' hello ' ' from dual;
    My expectation is to get 'hello' (Single quote around hello)You probably read that you can get a single-quote within a string literal by using two of them in a row.
    That's true, but they really have to be in a row (no spaces in between), and you still need the single-quotes at the beiginning and end of the literal.
    So what you want is
    SELECT  '''hello'''
    FROM    dual;Starting in Oracle 10, you can also use Q-notation, For example:
    SELECT  Q'['hello']'
    FROM    dual;

  • Place single quote around string

    Hi,
    I am wondering how I can Place single quote around string in the following. I have tried double and triple quote but it doesn't take variable name from rec.tablename.
    any idea
    rec.table_name ==> 'rec.table_name'
    rec.column_name ==> 'rec.column_name'
    v_sql:= 'DELETE USER_SDO_GEOM_METADATA WHERE TABLE_NAME= ' || rec.table_name ;
    execute immediate v_sql;
    -- Insert Table Record in Sdo_User_Geom_Metadata
    v_sql:= 'INSERT INTO USER_SDO_GEOM_METADATA(TABLE_NAME, COLUMN_NAME, DIMINFO, SRID) ' ||
    'VALUES (' || rec.table_name || ',' || rec.column_name || ', MDSYS.SDO_DIM_ARRAY( ' ||
    'MDSYS.SDO_DIM_ELEMENT(''X'',-2147483648, 2147483647, .000005), ' ||
    'MDSYS.SDO_DIM_ELEMENT(''Y'',-2147483648, 2147483647, .000005)), 2958)' ;
    execute immediate v_sql;
    Nancy

    I have 2 suggestions, 2nd one being the better choice.
    SQL> set serveroutput on
    SQL>
    SQL> declare
      2    v_sql varchar2(4000);
      3    table_name varchar2(4000);
      4  begin
      5    table_name := 'MY_TABLE';
      6    v_sql:= 'DELETE USER_SDO_GEOM_METADATA WHERE TABLE_NAME= ''' || table_name || '''';
      7    dbms_output.put_line(v_sql);
      8  end;
      9  /
    DELETE USER_SDO_GEOM_METADATA WHERE TABLE_NAME= 'MY_TABLE'
    PL/SQL procedure successfully completed
    SQL> or using DBMS_ASSERT for a more elegant solution against SQL injection:
    Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.4.0
    Connected as fsitja
    SQL> set serveroutput on
    SQL>
    SQL> declare
      2    v_sql varchar2(4000);
      3    table_name varchar2(4000);
      4  begin
      5    table_name := dbms_assert.QUALIFIED_SQL_NAME('ALL_TABLES');
      6    v_sql:= 'DELETE USER_SDO_GEOM_METADATA WHERE TABLE_NAME= ' || dbms_assert.ENQUOTE_NAME(table_name);
      7    dbms_output.put_line(v_sql);
      8  end;
      9  /
    DELETE USER_SDO_GEOM_METADATA WHERE TABLE_NAME= "ALL_TABLES"
    PL/SQL procedure successfully completed
    SQL> [Docs referencing validation checks against SQL injection|http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10472/dynamic.htm#LNPLS648]
    Regards,
    Francisco

  • Single quotes around a variable

    Hi,
    I have values that are being passed into a variable with single quotes around.
    for eg: 'test'. So the value in variable v_empname will hold the value 'test'
    But then below sql statement returns null:
    select empid
    into v_empid
    from emp where empname = v_empname
    When I checked the value of the variable it's 'test' and compared as '''test'''.
    How can I get around this?
    Thanks for the help.
    SK.

    Doh!
    SQL> create or replace procedure get_empno (i_name in varchar2)
      2  as
      3    v_empno number;
      4  begin
      5    select empno into v_empno
      6    from emp
      7    where ename = i_name;
      8    dbms_output.put_line('empno is '||v_empno);
      9  exception
    10    when no_data_found then
    11      dbms_output.put_line('No such person, or did you mean '||upper(i_name)||'?');
    12  end;
    13  /
    Procedure created.
    SQL>
    SQL> set serveroutput on
    SQL> exec get_empno('king');
    No such person, or did you mean KING?
    PL/SQL procedure successfully completed.
    SQL> exec get_empno('KING');
    empno is 7839
    PL/SQL procedure successfully completed.

  • Putting Single Quote in any field

    Hi All,
    What is the purpose of putting ' ' (Single Quote) in any of the field?
    Example:
    Object:F_BKPF_BUK
    Field:
    ACTVT:01
    BUKRS:' '  -
    > What does this imply?

    Hi,
    what do you mean by 'single quote'? If you mean 'blank', this has the same meaning as an empty value in the field. So if the application checks for any value, but not for an empty field, the check will fail.
    Regarding the docu: you can access it through some different ways, for instance in SE38->display source code of any report->press the blue 'I' infobutton->enter ABAP key-word authority-check, select authority-check->abap statement, enjoy the documentation.
    b.rgds, Bernhard
    Edited by: Bernhard Hochreiter on Sep 15, 2008 3:31 PM

  • Preserve single quote in text data.

    I have text data that is read into a BurrefedReader, some text contain single quoutes such as Ray's. When I retieve the data instead of seeing the single quote I see a square box replacing the single quote. What can I do in java to preserve the single quote?
    Thanks.

    Many thanks....here is my original code:
    public static String ClobToString(Clob cl) throws IOException, SQLException
    if (cl == null)
    return "";
    StringBuffer strOut = new StringBuffer();
    String aux;
    String aux2;
    BufferedReader br = new BufferedReader(cl.getCharacterStream());
    String ls =System.getProperty("line.separator");
    while ((aux=br.readLine())!=null)
    strOut.append(aux+ls);
    return strOut.toString();
    Here is the code with the encoding convertion:
    public static String ClobToString(Clob cl) throws IOException, SQLException
    if (cl == null)
    return "";
    StringBuffer strOut = new StringBuffer();
    String aux;
    String aux2;
    BufferedReader br = new BufferedReader(cl.getCharacterStream());
    String ls =System.getProperty("line.separator");
    while ((aux=br.readLine())!=null)
    strOut.append(aux+ls);
    StringInputStream st = new StringInputStream(strOut.toString());
    InputStreamReader inStreamReader=new InputStreamReader(st,"UTF-8");
    BufferedReader bufReader=new BufferedReader(inStreamReader);
    StringBuffer strOut2 = new StringBuffer();
    while ((aux2=bufReader.readLine())!=null)
    strOut2.append(aux2+ls);
    return strOut2.toString();
    I do thank you again for any help.

  • Adding SIngle quotes around a Colmn Name stored in a DB Field

    I know the SQL I need to execute ( It yeilds 500 rows )
    select p.DS_ID
    from dbo.v_ds p
    inner join dbo.Rpt r
    on p.DS_ID = r.PKVal
    and r.ColumnNm = 'DS_ID'
    BUT the value of r.Column in stored in a table and building it using dynamic SQL , the closest i get is
    select p.DS_ID
    from dbo.v_ds p
    inner join dbo.Rpt r
    on p.DS_ID = r.PKVal
    and r.ColumnNm = DS_ID
    Note that ther single quotes needed are missing and so I get NO rows. I've tried using the ''' + @field + ''' and cannor get it to work.
    Any ideas?

    Not sure of your try. May be you would have missed the single quote before and after as you said your closest ry result looks like below:
    and r.ColumnNm = DS_ID --Without single quotes.

  • Quotes around meta data

    Whenever I create a PDF document from within Microsoft Word with the Acrobat toolbar adobe adds in quote marks around my keywords.  My tags/keywords in Microsoft do not have any quote marks and all are separated by commas.  How do I fix this?  I do not want adobe adding in quote marks automatically.
    I have Adobe Acrobat Standard XI and am using Microsoft Word 2013.  The problem also exists with Acrobat Standard X and Microsoft Word 2010.?
    Can adobe please advise on how to fix this problem?
    Thank you.

    In Microsoft Word there are document properties.  One of them is called "tags".  When in Microsoft Word when I go to the adobe ribbon and click on the command "Create PDF" it converts the Microsoft Word Document into an Adobe PDF file.  It also imports/brings over the document properties.  "Tags" is brought over into the adobe PDF file in the meta data as "Keywords".
    For example, if I have the following information in the "Tags" property in Microsoft Word: car, truck, vehicle, SUV
    Now when it gets converted adobe brings it over into the metadata field of keywords but displays it as: "car, truck, vehicle, SUV"
    Adobe adds into the quotes.  Does not matter if I use semi colons instead.  It has something to do with how adobe interprets the information from the Microsoft Word document.  The metadata I am talking about for Adobe exists in the PDF file under "Document Properties", then in the description tab it mentions the fields of: Title: Author: Subject: Keywords: and there is a button also yet for Additional Metadata.

  • How to put single quotes inside single quotes

    Hi all,
    My requriement is to put a statement
    LIKP~VSTEL <> INF
    in a variable LV.
    For that I have written
    CONCATENATE LV 'LIKP~VSTEL <> "INF" ' INTO LV.
    where LIKP is a table as VSTEL is a table field.
    When this LV is used inside a select query, the value for LIKP~VSTEL is "INF", but I want without the double quotes. Can any one please help me with this.
    Thanks and Regards,
    Avinash

    Hi,
    Iif you mean LV should hold something like LIKP~VSTEL = ' INF ', then try this
    data: c_quote(4) type c value ''''.
    data: l_inv type string.
    CONCATENATE c_quote 'INF' c_quote into l_inv.
    CONCATENATE ' LIKP~VSTEL' '='  l_inv  INTO LV separated by space.
    Regards,
    Vikranth.
    Edited by: Vikranth.Reddy on Sep 1, 2009 1:55 PM

  • Problem with single quote around ANYINTERACT

    CREATE TABLE JUNK
    as SELECT s.survey_id,s.shape,s.original_depth
    FROM bathyuser.sounding s,m_covr r
    WHERE SDO_GEOM.RELATE (s.shape, 'ANYINTERACT', R.geom, 0.5) = 'TRUE'
    AND R.DSNM=CNT.DSNM
    and
    s.SURVEY_ID in
    (SELECT unique s.survey_id FROM header s, m_covr r
    WHERE SDO_GEOM.RELATE (s.shape, 'ANYINTERACT', r.geom, 0.5) = 'TRUE'
    AND DSNM=CNT.DSNM)';
    This above SQL works fine in SQL prompt. But when I put it together in PL/SQL it gives me this error :
    WHERE SDO_GEOM.RELATE (s.shape, 'ANYINTERACT', R.geom, 0.5) = 'TRUE'
    ERROR at line 17:
    ORA-06550: line 17, column 39:
    PLS-00103: Encountered the symbol "ANYINTERACT" when expecting one of the
    following:
    * & = - + ; < / > at in is mod remainder not rem
    <an exponent (**)> <> or != or ~= >= <= <> and or like LIKE2_
    LIKE4_ LIKEC_ between || multiset member SUBMULTISET_
    Could someone help me fix this error. I know I have to try it with "EXECUTE IMMEDIATE" command, but I'm having problem with "||" (concatinate).
    Thanks so much
    Cuong

    This is how you go about debugging execute immediate statements. I am assuming that you fixed the first problem as marias suggested and cam up with something like this. Note, I changed the table in your surso to dual since I do not have your tables, but the effect is the same. I changed the EXECUTE IMMEDIATE to DBMS_OUTPUT.Put_Line so you can actually see what you are trying to execute. I also added some carriage returns to make the formatting a littel easier to see. This is what I got:
    SQL> DECLARE
      2     statement varchar2(1000);
      3  CURSOR C_DSNM5 IS
      4     SELECT dummy dsnm FROM dual;
      5  BEGIN
      6     FOR CNT IN C_DSNM5 LOOP
      7        STATEMENT := 'CREATE TABLE JUNK'||
      8                     ' AS SELECT s.survey_id,s.shape,s.original_depth'||CHR(10)||
      9                     ' FROM bathyuser.sounding s,m_covr r '||CHR(10)||
    10                     'WHERE SDO_GEOM.RELATE (s.shape, '||
    11                     '''ANYINTERACT'''||
    12                     ', R.geom, 0.5) = '||'''TRUE'''||CHR(10)||
    13                     ' AND R.DSNM = CNT.DSNM '||CHR(10)||
    14                     ' AND s.SURVEY_ID IN '||
    15                     ' (SELECT UNIQUE s.survey_id FROM HEADER s, m_covr r'||CHR(10)||
    16                     ' WHERE SDO_GEOM.RELATE (s.shape, '||
    17                     '''ANYINTERACT'''||
    18                     ', r.geom, 0.5) = '||
    19                     '''TRUE'''||CHR(10)||
    20                     ' AND R.DSNM = '||CNT.DSNM||' )';
    21        DBMS_OUTPUT.Put_Line (statement);
    22     END LOOP;
    23  END;
    24  /
    CREATE TABLE JUNK AS SELECT s.survey_id,s.shape,s.original_depth
    FROM bathyuser.sounding s,m_covr r
    WHERE SDO_GEOM.RELATE (s.shape, 'ANYINTERACT', R.geom, 0.5) = 'TRUE'
    AND R.DSNM = CNT.DSNM
    AND s.SURVEY_ID IN  (SELECT UNIQUE s.survey_id FROM HEADER s, m_covr r
    WHERE SDO_GEOM.RELATE (s.shape, 'ANYINTERACT', r.geom, 0.5) = 'TRUE'
    AND R.DSNM = X )
    PL/SQL procedure successfully completed.You have at least two issues with this CREATE TABLE statement. The last line needs to have the X (which came from dual) quoted since it is a string. You also still have a reference to CNT.DSNM, unless you fixed both occurences.
    Another major problem is that if your cursor will return more than one row, and by the structure of this I assume that it might, the on the second record you are going to get:
    ORA-00955: name is already used by an existing object.
    Although I see no reason why you need dynamic sql here, you really need to use bind variables whereever possible (everywhere you use a variable except ofr names of database objects. So, your procedure should look more like:
    DECLARE
       statement varchar2(1000);
       CURSOR C_DSNM5 IS
          SELECT distinct DSNM from M_COVR where dsnm like 'US5%';
    BEGIN
       FOR CNT IN C_DSNM5 LOOP
          STATEMENT := 'CREATE TABLE JUNK'||
                       ' AS SELECT s.survey_id,s.shape,s.original_depth'||
                       ' FROM bathyuser.sounding s,m_covr r '||
                       'WHERE SDO_GEOM.RELATE (s.shape, '||
                       '''ANYINTERACT'''||
                       ', R.geom, 0.5) = '||'''TRUE'''||
                       ' AND R.DSNM = :b1 '||
                       ' AND s.SURVEY_ID IN '||
                       ' (SELECT UNIQUE s.survey_id FROM HEADER s, m_covr r'||
                       ' WHERE SDO_GEOM.RELATE (s.shape, '||
                       '''ANYINTERACT'''||
                       ', r.geom, 0.5) = '||
                       '''TRUE'''||
                       ' AND R.DSNM = :b2 )';
          EXECUTE IMMEDIATE statement USING cnt.dsnm, cnt.dsnm
       END LOOP;
    END;But it is still very wrong.
    Perhaps if you can explain in words what you are trying to accomplish someone can provide a much better response.
    John

  • Single quote in dynamic query

    Hi all;
    Can u please help me on the following dynamic query code ? I know I am missing the single quote around 2 dates but could not figure out where to put it ! I have tried putting 2 or 3 quotes around 2 bind vars but to no avail.
    Want to create a dynamic query to simulate the the following:
    select
    EMPNO,ENAME,JOB,MGR,HIREDATE from emp where HIREDATE >= to_date('01/01/1981','MM/DD/YYYY') and HIREDATE <= to_date('12/31/1982','MM/DD/YYYY');
    dynamic code:
    declare
    v_q varchar2(4000);
    begin
    v_q :='select EMPNO,ENAME,JOB,MGR,HIREDATE from emp ';
    V_q := V_Q
    || 'where HIREDATE >= '
    || 'to_date(' || :P_DATE1 || ',' ||'''MM/DD/YYYY''' || ' )'
    || 'and HIREDATE <= '
    || 'to_date(' || :P_DATE2 || ',' ||'''MM/DD/YYYY''' || ' )';
    -- end the sql
    v_q := v_q ||';';
    dbms_output.put_line ('V_Q is ' || V_Q);
    end;
    Thanks.
    Zen

    declare
        v_q varchar2(4000);
        v_rec emp%rowtype;
        v_cur sys_refcursor;
    begin
        v_q :='select EMPNO,ENAME,JOB,MGR,HIREDATE from emp ';
        V_q := V_Q  || 'where HIREDATE >= to_date(:P_DATE1,''MM/DD/YYYY'') and HIREDATE <= to_date(:P_DATE2,''MM/DD/YYYY'')';
        dbms_output.put_line ('V_Q is ' || V_Q);
        open v_cur
          for v_q
          using '01/01/1981',
                '12/31/1982';
        loop
          fetch v_cur
            into v_rec.empno,
                 v_rec.ename,
                 v_rec.job,
                 v_rec.mgr,
                 v_rec.hiredate;
          exit when v_cur%notfound;
          dbms_output.put_line('empno = ' || v_rec.empno);
          dbms_output.put_line('ename = ' || v_rec.ename);
          dbms_output.put_line('job = ' || v_rec.job);
          dbms_output.put_line('mgr = ' || v_rec.mgr);
          dbms_output.put_line('hiredate = ' || to_char(v_rec.hiredate,'MM/DD/YYYY'));
          dbms_output.put_line('====================');
        end loop;
        close v_cur;
    end;
    V_Q is select EMPNO,ENAME,JOB,MGR,HIREDATE from emp where HIREDATE >=
    to_date(:P_DATE1,'MM/DD/YYYY') and HIREDATE <= to_date(:P_DATE2,'MM/DD/YYYY')
    empno = 7499
    ename = ALLEN
    job = SALESMAN
    mgr = 7698
    hiredate = 02/20/1981
    ====================
    empno = 7521
    ename = WARD
    job = SALESMAN
    mgr = 7698
    hiredate = 02/22/1981
    ====================
    empno = 7566
    ename = JONES
    job = MANAGER
    mgr = 7839
    hiredate = 04/02/1981
    ====================
    empno = 7654
    ename = MARTIN
    job = SALESMAN
    mgr = 7698
    hiredate = 09/28/1981
    ====================
    empno = 7698
    ename = BLAKE
    job = MANAGER
    mgr = 7839
    hiredate = 05/01/1981
    ====================
    empno = 7782
    ename = CLARK
    job = MANAGER
    mgr = 7839
    hiredate = 06/09/1981
    ====================
    empno = 7839
    ename = KING
    job = PRESIDENT
    mgr =
    hiredate = 11/17/1981
    ====================
    empno = 7844
    ename = TURNER
    job = SALESMAN
    mgr = 7698
    hiredate = 09/08/1981
    ====================
    empno = 7900
    ename = JAMES
    job = CLERK
    mgr = 7698
    hiredate = 12/03/1981
    ====================
    empno = 7902
    ename = FORD
    job = ANALYST
    mgr = 7566
    hiredate = 12/03/1981
    ====================
    empno = 7934
    ename = MILLER
    job = CLERK
    mgr = 7782
    hiredate = 01/23/1982
    ====================
    PL/SQL procedure successfully completed.
    SQL> SY.

  • Reporting data with quotes around each column, separating with ,

    I want to report data with quotes (") around the data and make is CSV.
    I use colsep , to allow the comma separator, but how can I get " around each column?
    I do not know the column I am dealing with, since it's over several tables from a dynamic script.
    EG
    set pagesize 90 linesize 1000 colsep ,                                     
    spool FND_SESSION_REP.csv  
    with mycount as (select count(*) numrows from FND_SESSION_REP) select vi.instance_name, vi.version, moredata.* from (select rownum r,mycount.numrows, data.* from FND_SESSION_REP data, mycount where mycount.numrows>0) moredata,v$instance vi where r>numrows-10;                                                  
    spool off       And I'd like
    "col1","col2","col3"
    etc
    Possible?

    SQL> select '"'||empno||'","'||ename||'"' from scott.emp;
    '"'||EMPNO||'","'||ENAME||'"'
    "7369","SMITH"
    "7499","ALLEN"
    "7521","WARD"
    "7566","JONES"
    "7654","MARTIN"
    "7698","BLAKE"
    "7782","CLARK"
    "7788","SCOTT"
    "7839","KING"
    "7844","TURNER"
    "7876","ADAMS"
    "7900","JAMES"
    "7902","FORD"
    "7934","MILLER"
    14 rows selected
    SQL>

  • Any way to generate a single quote (') with XSLT?

    Hi:
    I guess this is really an XSLT question. I'm using the Transform() method of an XMLType variable to apply a style sheet. The XML in the variable is just something simple like
    <TBL>
    <LAST_NAME>LIKE|JONES</LAST_NAME>
    <FIRST_NAME>=|MARY</FIRST_NAME>
    <AGE>=|50</AGE>
    </TBL>
    I am trying to get a stylesheet to transform something like the above into SQL such as
    Select * from foo where LAST_NAME like 'JONES'
    and FIRST_NAME ='MARY'
    and AGE = 50But to do this, I need to generate the single quotes around the search terms and I can't get anything but LAST_NAME LIKE &apos;JONES&apos;. Is there a way to do this? For now I am generating a ~ and replacing ~ for ' throughout the generated SQL text but that's a pretty sorry solution.
    I thought that something like <xsl:text disable-output-escaping="yes">&amp;</xsl:text> was going to work but then found out it has been deprecated. I was thinking character-map might work but that's an XSLT 2.0 thing and apparently 10g is on XSLT 1.0? In any case, it had no idea what I was trying to do with a character map.
    So, am I overlooking an obvious way to get my stylesheet to insert apostrophes?
    Thanks.

    It's 10.2.0.4.
    Here's the procedure that accepts the XML/XSL clobs and tries to produce a SQL statement.
    PROCEDURE GetSQLQueryFromXML(XMLClob in CLOB, XSLStylesheet in CLOB,
                SQLQuery out CLOB, status out integer) IS
        -- Define the local variables
      xmldata               XMLType;  -- The XMLType format of the XML to transform
      xsldata               XMLType;  -- The XMLType format of the stylesheet to apply
      sqlQuery_XMLType      XMLType;  -- The XMLType format of the SQL query.
      v_SQLQuery            Clob;     -- Holds XML Clob before translating ~ to '
    BEGIN
    status := -1;  -- Initially unsuccessful
      -- Get the XML document using the getXML() function defined in the database.
      -- Since XMLType.transform() method takes XML data as XMLType instance,
      -- use the XMLType.createXML method to convert the XML content received
      -- as CLOB into an XMLType instance.
      xmldata := XMLType.createXML(XMLClob);
      -- Get the XSL Stylesheet using the getXSL() function defined in the database.
      -- Since XMLType.transform() method takes an XSL stylesheet as XMLType instance,
      -- use the XMLType.createXML method to convert the XSL content received as CLOB
      -- into an XMLType instance.
      xsldata := XMLType.createXML(XSLStylesheet);
      -- Use the XMLtype.transform() function to get the transformed XML instance.
      -- This function applies the stylesheet to the XML document and returns a transformed
      -- XML instance.
      sqlQuery_XMLType := xmldata.transform(xsldata);
      -- Return the transformed XML instance as a CLOB value.   
      v_SQLQuery := sqlQuery_XMLType.getClobVal();
      -- Change tildas to apostrophes.  Currently unable to get an XSLT transformation
      -- to insert single quotes, so we're inserting ~ instead.  Now we need to
      -- translate all ~s to 's in our query.
      SQLQuery := translate(to_char(v_SQLQuery),'~','''');
      status := 1; -- Everything went fine to get here
    EXCEPTION
      WHEN OTHERS THEN         
        raise_application_error
        (-20102, 'Exception occurred in GetSQLQueryFromXML :'||SQLERRM);
    END GetSQLQueryFromXML;The XML it works off of is
        someXML CLOB :=
        to_clob('<?xml version="1.0" encoding="windows-1252" ?>
    <variable table_name="SOME_PERSON_TABLE" query_type="PERSON">
      <item>
        <fieldName><![CDATA[PERSON_KEY]]></fieldName>
        <criteria><![CDATA[=]]></criteria>
        <fieldType><![CDATA[Integer]]></fieldType>
        <value><![CDATA[123456789]]></value>
      </item>
      <item>
        <fieldName><![CDATA[LAST_NAME]]></fieldName>
        <criteria><![CDATA[=]]></criteria>
        <fieldType><![CDATA[String]]></fieldType>
        <value><![CDATA[DOE]]></value>
      </item>
      <item>
        <fieldName><![CDATA[FIRST_NAME]]></fieldName>
        <criteria><![CDATA[=]]></criteria>
        <fieldType><![CDATA[String]]></fieldType>
        <value><![CDATA[JOHN]]></value>
      </item>
      <item>
        <fieldName><![CDATA[MIDDLE_NAME]]></fieldName>
        <criteria><![CDATA[-]]></criteria>
        <fieldType><![CDATA[String]]></fieldType>
        <value />
      </item>
      <item>
        <fieldName><![CDATA[SUFFIX]]></fieldName>
        <criteria><![CDATA[-]]></criteria>
        <fieldType><![CDATA[String]]></fieldType>
        <value />
      </item>
    </variable>');And the corresponding XSLT that should translate it is:
      myStylesheet  CLOB :=
      to_clob('<?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <!-- <xsl:preserve-space elements="list-of-element-names"/> -->
      <!-- We just want the SQL text output.  No XML declaration etc. -->
      <xsl:output method="text" omit-xml-declaration="yes" indent="no"/>
    <!-- Apostrophes will be made tildas and the PL/SQL will translate those to -->
    <!-- apostrophes for the final SQL string. -->
    <xsl:variable name="apos">~</xsl:variable>
      <xsl:template match="/">
        select * from
        <xsl:value-of select="variable/@table_name"/>
        where 1=1
        <xsl:for-each select="variable/child::node()">
          <xsl:choose>
            <!-- if the value node is not null... -->
            <xsl:when test="./value/text()[normalize-space(.)]">
            <!-- There is another predicate.  Add the AND term and the predicate -->
              AND <xsl:value-of select="./fieldName"/>
              <xsl:text> </xsl:text>
              <xsl:value-of select="./criteria"/>
              <xsl:text> </xsl:text>       
              <xsl:choose>
                <xsl:when test="string(./fieldType)=''String''">
                  <xsl:copy-of select="$apos" />
                  <xsl:value-of select="./value"/>
                  <xsl:copy-of select="$apos" />
                </xsl:when>         
                <xsl:when test="string(./fieldType)=''Clob''">
                  <xsl:copy-of select="$apos" />
                  <xsl:value-of select="./value"/>
                  <xsl:copy-of select="$apos" />
                </xsl:when>
                <xsl:otherwise>
                  <xsl:value-of select="./value"/>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:when>
          </xsl:choose>
        </xsl:for-each>
      </xsl:template>
    </xsl:stylesheet>');Basically if the VALUE element has a value then the fieldType is checked. If fieldType is String or Clob then we'll need the apostrophes. For now I'm putting in tildas and changing them later.

  • Single Quotes Issue??

    Hi,
    Bit of a strange one - hopefully there is a really simple answer that I will kick myself over….!
    I have a query which references a partioned table. When the following condition is added, the query references the intended partion - evident by looking at the explain plan:
    and e.dac_end_date >= '20080401'
    (VARCHAR2 (8 Byte))
    However, I want to automate my script. When I use a variant of the Sysdate function (detailed below) and execute the query, the explain plan indicates that Oracle is doing a full table scan….. Not good!!
    e.dac_end_date >= to_char(add_months(sysdate,-1),'YYYYMM')||'01'
    I'm guessing this may have something to do with single quotes… I have done a forum trawl, and tried some of the suggestions (char(39)||, three quotes surrounding the 'YYYYMM', concatenating single quotes around the format mask etc) - but I either get an error message, or the query just bombs out after a few seconds.
    Anyone have any ideas or suggestions??
    Any help greatly appreciated….
    Cheers in advance.

    Firstly - thanks for the replies.
    Just to confirm - the table I'm referring too is ranged partioned on a varchar2 column that contains a date-as-a-string. I didn’t build the tables - I'm not a developer. I'm just trying to automate a query that I have written which on the surface appears to do a full table scan when I use the Sysdate function (instead of a hard coded date).
    'Bomb out' - bad grammar, apologies. What I meant was the query appears to complete within a few seconds, however does not return any data.
    peticH - I was using 'Session Browser' within Toad to monitor the query (running in another session) - I didn’t realise that even in this instance Explain Plan provides expected rather than actual behaviour. I'll do some reading up on the 'Trace' functionality, to try and see what is actually happening.
    Cheers guys.

Maybe you are looking for

  • PO Print of Free Goods

    Vendor has send free goods but excise duty and freight, etc we have to pay. If I put free item tick in the PO, the condition tab disappears. I cannot enter the basic price and any other condition in the PO. therefore tax and other conditions cannot b

  • Query Performance - Query not using proper plan

    Hello, I am experiencing a performance issue with queries that span multiple partitions/tablespaces. Specifically, a query utilizing a stored procedure does not use the indices, rather, full table scans are being done resulting in the query taking 30

  • Help for transfering data from one user' all tables to another

    Hello guys, I have trim the extra sizes of columns in almost all tables of my database. Before doing this, I saved the data of tables by creating another user "User1" with the same objects and importing dmp file in it. After this I cleared my origina

  • Shadow instance disp+work stopped during PREPARE_JSPM_QUEUE

    Hi Gurus, I have started an upgrade EHP3 on ERP 6.0 using Ehpi tool. During the phase PREPARE_JSPM_QUEUE the tool starts the shadow instance and then disp+work stopped after a minute. dbs_ora_schema is setup with SAPSR3. whatever if the main instance

  • FTPS podcast producer

    Anybody have any luck publishing with FTPS? I am able to publish via ftp to a filezilla server but am unable with FTPS. I get a "not logged in" error on filezilla. I am using the exact same workflow. I change from ftp to ftps and it does not work. An