To insert single quotes

Hi
All,
Oracle 10.2.0.3
AIX 5.3
I have following query
select 'ALTER DATABASE RENAME FILE ' || name || ' TO /u44/ORACLE/CMS' || substr(name,16) as move_datafile from v$datafile where name like '/u41%';
Now, I want to type ALTER DATABASE RENAME FILE with single quotes. In other words I want to type string with single quotes. How can I achieve this?
Thanks,
Vishal

Since you have Oracle 10G, you can use the new quote notation:
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/fundamentals.htm#i38404
Examples, sorry about the orthographic faults:
SQL> select q'"this it's a test of data's string"' from dual;
Q'"THISIT'SATESTOFDATA'SSTRING"'
this it's a test of data's string
SQL> select q'/ this it's another's test of quotes isn't /' from dual;
Q'/THISIT'SANOTHER'STESTOFQUOTESISN'T/'
this it's another's test of quotes isn't

Similar Messages

  • JDBC insert single quote ???

    Hi,
    I want to insert a string which could contain a single quote ( ' ) into my database . But if this is the case, the regular insert command fails, since the single quote from the string collides with the ones from the command. What can I do???

    Try placing an escape char "\".
    So its like:
    String s="Sachin\'s page";
    If ur using it in xml use:
    ' to replace '.
    Hope this helps.
    Sachin

  • To insert single quote in a varchar2 field

    hi guys,
    i am facing a simple problem, can any one of you help me in this regard. the problem is i am unable to insert a single quote in a varchar2 field like
    SQL> DESC EMP
    Name Null? Type
    EMPNO NOT NULL NUMBER(4)
    ENAME VARCHAR2(10)
    JOB VARCHAR2(9)
    MGR NUMBER(4)
    HIREDATE DATE
    SAL NUMBER(7,2)
    COMM NUMBER(7,2)
    DEPTNO NUMBER(2)
    SQL> INSERT INTO EMP (EMPNO, ENAME) VALUES (100, 'Mc'Aure') ;
    ERROR:
    ORA-01756: quoted string not properly terminated
    oracle takes ' as the delimiters for identifying the word. in my case the name itself contains a single quote which is to be inserted. how to insert the single quote
    i want to insert it from asp coding and also from sql plus 8.0.
    advanced thanks
    ananth

    If you use a ' in a varchar2, it must be marked with a second '.
    In your case:
    SQL> INSERT INTO EMP (EMPNO, ENAME) VALUES
    (100, 'Mc''Aure') ;
    null

  • Insert single quote into the table

    Hi
    I have to insert values into a column that are retrieved by a select query on another table.
    The values inserted have single quotes (').
    Does anybody know how to do it?
    Thanks in advance

    If you get from one table and then insert in the other there shouldn't be any problem at all.
    SQL> create table blah_one as
      2  select 'Radha''s Sarma' col from dual
      3  /
    Table created.
    SQL> select * from blah_one
      2  /
    COL
    Radha's Sarma
    SQL> create table blah_two as
      2* select col from blah_one
    SQL> /
    Table created.
    SQL> select * from blah_two
      2  /
    COL
    Radha's Sarma
    SQL>Cheers
    Sarma.

  • Help with sql insert single quotes

    String insert = "INSERT INTO users(firstName, lastName, emailAdd, password) VALUES("+ firstNameForm + "," + lastNameForm + "," + emailForm + "," + passwordForm + ")";
    Statement stmt = conn.createStatement();
         int ResultSet = stmt.executeUpdate(insert);
    I have that sql insert statment in my servlet the servlet compiles fine but does not insert into the users table, i have been told that it is something to do with single quotes in sql statement, can anybody help me out?

    Or can i change my sql table is there a autonumber which would increase everytime this servlet runs?make your field autoincrement :-)
    example
    ALTER TABLE `users` CHANGE `user_id` `user_id` INT( 10 ) UNSIGNED DEFAULT '0' NOT NULL AUTO_INCREMENT To insert record in the table.
    example:
    you have a table test and got two fields,
    id = (INT) autoincrement
    name = VARCHAR / TEXT etc.
    to insert data to the table test try something like this:
    String SQLStatement = "INSERT INTO test";
    SQLStatement += "(name)";
    SQLStatement += " VALUES (?)";
    statement = Conn.prepareStatement(SQLStatement);
    statement.setString(1, "Duke");
    statement.executeUpdate();
    statement.close();
    Conn.close();Note we dont provide the field for id on our sql statement since it is set as auto-increment ;-)
    regards,
    Message was edited by:
    jie2ee

  • How to insert single quote in to the table

    Pl help me out in how to insert the single quote ie ' into the table. If there is no other way, i will go for some other alternative
    Regards,
    Basavaraju

    SQL> desc varchar2_test
    Name                                      Null?    Type
    TEXT                                               VARCHAR2(4000)
    SQL> insert into varchar2_test values ('''ABCDEFGHIJ''');
    1 row created.
    SQL> select * from varchar2_test;
    TEXT
    'ABCDEFGHIJ'Thanks,
    BB

  • 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 the query

    Hi,
    I am inserting a string literal that contains one or more single quotes. I know i have to use two single quote ('') to represent one single quote in my insert query and four single quotes('''') to show two single quotes. However, when i do a select from the table, all single quotes are escaped with a backslash in front of it (\'). This cause some problem when i display the string in html page. How can i skip the back slash and keep only the single quote in my select query? Thanks
    Kim Titu

    Kim,
    To insert single quote or double quote string try using the ascii values as below -
    CHR(34) ==> " (double quote)
    CHR(39) ==> ' (single quote)
    Example:
    Insert into emp(EMPNAME) values(CHR(39)||'TEST'||CHR(39));
    Now,
    Select EMPNAME from emp;
    will give you the result - 'TEST'
    Regards,
    Murali Mohan

  • Getting rid of single quotes and other bad characters

    Hello All-
    I am writing a servlet that takes a value from a form, and saves it to a database. However, when single quotes, and other illegal characters are entered, i get all sorts of errors. I am certain their is some function that would take care of all of this.
    Help!

    Hi there,
    When you try to insert single quotes into the database it gives an error or problem because a single quote is a reserved character in the database.
    If you want to store a single quote or any other character that is reserved in the database then you need to find out how to escape that reserved character.
    One option is to use the single quote twice, so instead of ' , use '' (not double quote but , type single quote twice).
    Another option is to use HTML entity code for single quote
    "Message was edited by:
    appy77

  • Trouble with inserting a string containing a single quote

    Using php with Oracle
    If I do the following two lines before sending my $Query string through the parse function
    $name = "Dominick's";
    $Query = "INSERT INTO customers (name) values ('$name')";
    it gives me the following error:
    Warning: Ora_Parse failed (ORA-00917: missing comma -- while processing OCI function OPARSE)
    If I try and force the single quote to be surrounded by double quotes and therefore not be confused:
    $name = "Dominick's";
    Query = "INSERT INTO customers (name) values (\"$name\")";
    Trying that yields the following error:
    Warning: Ora_Parse failed (ORA-01741: illegal zero-length identifier -- while processing OCI function OPARSE)
    Help
    Jeff

    If it is possible (and here it is) you should use str_replace instead of ereg_replaceThanks for the reminder about str_replace().
    $Query = "INSERT INTO customers (name) values ('".addSlashes($name)."')";This gives an invalid Oracle SQL statement, which will generally fail with
      ORA-01756: quoted string not properly terminatedFor Oracle, single quotes must be doubled, not escaped with backslash.
    Of the solutions to insert the data, I'd prefer using bind variables
    since no escaping or quote doubling is needed.
    -- CJ

  • Is there a way to insert a string even if the value has a single quote in it?

    Hi,
    I have a varchar string like
    Name: D'souza
    I am getting an error when i am inserting  like this.
    insert into table (D'souza)
    Is there any way to allow inserting the exact value even if it has single quotes attached to it like set define off in oracle ?
    Regards
    Gautam S
    Gautam S

    insert into table values('D''souza')
    insert into table values('D'''+'souza')
    Try also this one
    SET QUOTED_IDENTIFIER { ON | OFF }
    http://msdn.microsoft.com/en-us/library/ms174393.aspx

  • How to insert a string containing a single quote to the msql database? help

    how can i insert a string which contains a single quote in to database... anyone help
    Message was edited by:
    sijo_james

    Absolutely, Positively use a PreparedStatement. Do not use sqlEscape() function unless you have some overriding need (and I don't know what that could possibly be).
    There are 1000's of posts on the positive aspects of using a PreparedStatement rather than using a Statement. The two primary positive attributes of using a PreparedStatement are automatic escaping of Strings and a stronger security model for your application.

  • Problem in insertion with string containing   ' (single quote)

    i have a text field in jsp.
    when i submit the content need to be inserted/updated.
    when the text field contains character's with single quote( ' )..
    i am unable to insert/update values in database..
    where as if the text field contains characters without single quote..there is no problem in Database insertion/updation.
    i am using create statement .. and oracle database..
    can any one help ...

    The usual answer for this in the JDBC forum (where this should have been posted because it's completely about JDBC) is to use a PreparedStatement.

  • Single quote in  insert statement

    Hi can anybody please tell how to insert a single quote in value say insert into ex values('example's')

    Hi
    insert into ex values('example''s')
    Sam

  • Problem with single quote when exporting insert statement

    Hi
    I'm using Oracle SQL Developer 2.1.1.64 on Ubuntu 10.04. I got some records which has single quote in it.
    For example,
    Let says Table '*TABLE_A*' has varchar2 column called '*COL_A*'.
    And there is only one record in the table and the value is:
    his friend's dog name is dog.
    When I export that table data to insert statement, i got this:
    Insert into TABLE_A (COL_A) VALUES ('his friend's dog name is dog.');
    As you can see friend's is wrong, it should be friend''s instead. (note the double single quotes).
    Anyone knows how to fix this please?

    Yes - that's a bug. But probably not what you're expecting.
    Mind you really can't use "normal" SQL on LOBs, because they're just too big to fit in the statements.
    You should export and import them through e.g. the DBMS_LOB package.
    I do remember some request on the SQL Developer Exchange to automate this, so go vote there to add weight for future implementation.
    So the bug is that the column's fields should all yield NULL inside the INSERTs.
    Regards,
    K.

Maybe you are looking for

  • Unable to identify the exchange protocol of the message (sync AS2 MDN)

    Hi, We got the following error: Description: Unable to identify the exchange protocol of the message StackTrace: Error -: AIP-50080: Exchange protocol identification error      at oracle.tip.adapter.b2b.engine.Engine.processIncomingMessage(Engine.jav

  • Treo Pro will not sync with Vista SP1

    I'm really hoping somebody can help me here.  I just replaced my aging 700p with the long-awaited Treo Pro (Sprint).  I've actually been looking forward to getting fully Windows-based, since my 700p syncing was routinely problematic - always having t

  • Films stuck on Apple TV

    I have 3 films stuck on Apple TV which will not transfer over to my Mac. Since I found this problem I just purchase now through my Mac. I recently lost some Apps I purchased and when I went to purchase them again iTunes came up saying something along

  • How to receive replies back to SAP user's inbox from external domain.

    We are facing a scenario where an email should be sent from SAP to any external domain ( ie: abc.com ) and  I know that we can trigger outgoing mail from SAP but not sure about receiving emails to a specific SAP User id's inbox (SBWP). I was searchin

  • I cannot copy/paste in CS3

    Pretty basic functionality we're talking about here. I also cannot copy back and forth between Ps and Ai. Am I missing some "cool new feature"? I already tried trashing the prefs.