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.

Similar Messages

  • 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

  • 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;

  • 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.

  • 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.

  • 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

  • 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

  • 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 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.

  • How to concatenate a string with single quotes

    Hi all,
        how to concatenate a string with single quotes to a variable.
    Sathya

    Hi sathyabama,
    1. simple
    2. use TILDE character <b>(`)</b>
       (just left to the '1' key)
    <b> `'mystring'`</b>
    3. just copy paste
    report abc.
    data : m(100) type c.
    concatenate `'amit mittal'` 'hello' into m separated  by space.
    write m.
    regards,
    amit m.

  • 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.

  • XLIFF escaping (single quote)

    i have a resource string that looks like,
    <trans-unit id="...">
    <source>'{0}'</source>
    <target/>
    </trans-unit>
    notice the single quotes around the token. when i do this, the token won't get replaced by MessageFormat.format(). i tried escaping the single quotes like \'{0}\' which had no effect.
    thanks.

    answering my own question ... this has nothing to do w/ XLIFF. looking at the MessageFormat javadocs, there are some rather confusing details about how single quotes are used to escape. it turns out that a double single quote gets a single quote in the output,
    ''{0}''

  • How to pass a string variable in a single quote

    Hi,
    I am trying to pass a single quoted string, 'some string', into a concat expression.
    My situation is some thing like
    I have an array of states
    <copy>
    <from>
    <ListOfValues xmlns="http://tbone.coi.test/amis">
    <!-- State -->
    <Value>A</Value>
    <Value>B</Value>
    <Value>C</Value>
    </ListOfValues></from>
    <to variable="StateList"/>
    </copy>
    then I loop through the StateList array to get each state as
    <copy>
    <from variable="StateList" query="/tns:ListOfValues/tns:Value[bpws:getVariableData('iterator')]"></from>
    <to variable="currentState"/>
    </copy>
    I then build an xpath expression like:
    <copy>
    <from expression="concat('/nsxml0:GetSummariesResponse/nsxml1:Summaries[nsxml1:State = ',bpws:getVariableData('currentState'), ']')"></from>
    <to variable="xpath"/>
    </copy>
    As the result, my xpath look like:
    /nsxml0:GetSummariesResponse/nsxml1:Summaries[nsxml1:State = A]
    but I need a state surrounded by single quote as 'A' or xpath query like
    /nsxml0:GetSummariesResponse/nsxml1:Summaries[nsxml1:State = 'A']
    Any ideas how can I single quote a value of bpws:getVariableData('currentState') in my concat expression
    Thanks,
    -V

    Have you tried 'the string contain''s an &apos;'?

  • Escape single quote from a String variable

    Hi,
    I have a String variable called "name" which i am using in my form tag.
    <form name=test action="test.jsp?fname=<%=name%>" method="post">
    But i am getting Javascript error if the "name" variable contains a string with some special characters like single quote( ' ).
    Plz help me to escape this special char from my String variable.
    Thanks..

    You need to url-encode the value using the URLEncoder class.
    http://java.sun.com/javase/6/docs/api/java/net/URLEncoder.html
    For example:
    <form name=test action="test.jsp?fname=<%=URLEncoder.encode(name, "ISO-8859-1")%>" method="post">

  • How do I pass single quotes into a string variable?

    Thanks for any help?
    Example
    Select xdat, yday
    from foo
    where
    xdat = to_char(sysdate, 'mm/dd/yyyy')
    How do I pass the single quoted stuff above into a string variable?

    Thank you but that is not the same thing. I am building a dynamic sql statement and need to pass the quoted material into a statement that is quoted Is that not what my example above shows?
    My example above has a quoted string inside a string. I think this is exactly what you were asking for.

Maybe you are looking for