Embedding quotes in strings

In the code segment below (hope it appears right) I can understand the use of single quotes in the first two examples but in the third example below I had to use double quotes around the word - Today's - and I not sure I understand why?!
I'm aware of the rules ...
If you want a single quote to appear in the middle of a string add another single quote to it.
If you want a single quote to appear at the beginning or end of a string add 2 single quotes to it.
If you want a single quote to appear on its own add 3 single quotes to it.
I'm hoping someone can shed some light on this for me.
SQL> select 'This isn''t' from dual;
'THISISN''
This isn't
SQL> select to_number('34@456#789', '999G999D999', 'nls_numeric_characters=''#@'' ') from dual;
TO_NUMBER('34@456#789','999G999D999','NLS_NUMERIC_CHARACTERS=''#@''')
                                                            34456.789
SQL> select to_char(sysdate, 'fm"Today''s" ddth Month YYYY') from dual;
TO_CHAR(SYSDATE,'FM"TODAY''S"DDTHMONTHYYYY')
Today's 16th August 2013

I'm aware of the rules ...
Actually, there is only one. I'll explain;
If you want a single quote to appear in the middle of a string add another single quote to it.
SQL> create table test (col1 varchar2(50));
Table created.
SQL> insert into test values(' Today''s ');
1 row created.
SQL> select * from test;
COL1                                                                           
Today's 
If you want a single quote to appear at the beginning or end of a string add 2 single quotes to it.
SQL> insert into test values(' ''Today''s ');
1 row created.
Elapsed: 00:00:00.03
SQL>
SQL> select * from test;
COL1                                                                           
'Today's
If you want a single quote to appear on its own add 3 single quotes to it. (This should be corrected however, it should actually be 4).
insert into test values ('''');
1 row created.
Elapsed: 00:00:00.00
SQL>
SQL> select * from test;
COL1                                                                           
All the three rules written by you are shown above. And now if you observe carefully, what I have done is preceded my single quote (that needs to be inserted) with another single quote('). So basically all rules points to only one rule.
Precede your single quote with another single quote and the job is done.
PS: Writing two single quotes back to back doesn't mean that it's a double quote. It looks same but actually aren't.
Ishan

Similar Messages

  • 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

  • (JDBC)how to diffrenciate a single quote in string ? eg : 'Micheal's Store'

    Hi all,
    I wanted to difrrenciate a single quote in string. Is there any way to do so ?
    I'm using Java.
    Thanks

    If you're using Java, I assume you're using straight JDBC rather than one of the many APIs layered on top of JDBC.
    You should be using PreparedStatement objects with bind variables and you should be passing in string values by making appropriate setString() calls. When you're using bind variables, rather than building up SQL strings in your app, you won't have any issues with escaping quotes. You also won't have to worry about defending against SQL injection attacks and your application will perform much better since you won't be re-parsing the same statement over and over and won't be flooding your library cache with thousands of mostly identical statements.
    Justin
    I intended to say that you won't be flooding your shared pool with thousands of mostly identical statements, not the library cache.
    Message was edited by:
    Justin Cave

  • JDBC Adapter Quoting of String

    Hi everybody!
    I am posting data to a JDBC Receiver adapter using the JDBC adapter's XML format. I have configured the logging of the adapter to show the SQL commands issued to the adapter, since I received some strange errors from the database.
    I now find entries like:
    INSERT INTO  xxx (field1, field2, field3) VALUES (value1, , value3)
    Notice the "missing" value2 - the field's value is a space character (" "). However, I actually wanted to quote the values in this field, since this SQL command of course gives a syntax error because of the two consecutive commas...
    How can I quote strings in this SQL command?
    Regards, Joerg

    Hi,
    I don't know if I stated my problem clearly enough... Here is the XML document I post to the JDBC adapter:
    <root>
      <insert>
        <xxx action="INSERT">
          <field1>value1</field1>
          <field2> </field2>
          <field3>value1</field3>
        </xxx>
      </insert>
    </root>
    (note the blank character for field2's value). If I understand your answer correctly, I should use the following instead:
    <root>
      <insert>
        <xxx action="INSERT">
          <field1>'value1'</field1>
          <field2>' '</field2>
          <field3>'value1'</field3>
        </xxx>
      </insert>
    </root>
    This is somewhat inconvenient, since there might be <b>NULL</b> values as well and I'd have to code manymany <b>if</b> statements and <b>mapWithDefaults</b>, then. I was wondering if there is something like the config setting "Interpretation of Empty String Values" for NULL values, some switch I set globally in order to <i>always</i> quote a string...
    Regards,  Joerg

  • JSP's include embedded in a String ???

    Hi All,
    I'am building an HTML string, which includes a JSP file as,
    "<%@ include file=\"../jsp/SST_Links.jsp\" %>"
    When the JSP is converted to a servlet the above line becomes,
    "<%@ include file=\"../jsp/SST_Links.jsp\"
    which means, the rest of the string is cutoff.obviously,
    '%>' is interpreted as probably the end of the string.
    It also throws up an error,
    org.apache.jasper.JasperException: Unable to compile class for
    JSPC:\tomcat\work\localhost_8080%
    2Fsst\_0002fjsp_0002fSST_0005fPDFReport_0002ejspSST_0005fPDFReport_jsp_13.java:137: String not terminated at end of line.
    "<%@ include file=\"../jsp/SST_Links.jsp\"
    is there any syntax error ???
    please help !
    thanks,
    nazhat
    p.s.
    have tried unsuccessfully,
    "<%@ include file=\"../jsp/SST_Links.jsp\" >"
    "<%@ include file=\"../jsp/SST_Links.jsp\" \%>"
    "<%@ include file=\"../jsp/SST_Links.jsp\" %%>"

    Hi! I have all my files in the same folder so I am not sure how to give the actual path but this is what I am doing and works just fine.:
    <%@include file="header.html"%>
    Make sure there are no double quotes around the <% %>.
    hope this helps.

  • Embedded Quote in an SQL Statement

    How do you embed a double quote in a java string? I'm doing some processing where I need to generate and execute some SQL, but I need to wrap the string in double quotes, something like:
    select sysdate "My Column Header" from dual;
    I've been using the syntax in java of:
    String mySql = "select sysdate from dual";
    How do I insert the double-quoted string into a java string? Gotta be simple, but I'm just not seeing it.

    Use backslash to escape the quote:
    String mySql = "select sysdate \"My Column Header\" from dual";
    Brian

  • Using Regular Expressions to replace Quotes in Strings

    I am writing a program that generates Java files and there are Strings that are used that contain Quotes. I want to use regular expressions to replace " with \" when it is written to the file. The code I was trying to use was:
    String temp = "\"Hello\" i am a \"variable\"";
    temp = temp.replaceAll("\"","\\\\\"");
    however, this does not work and when i print out the code to the file the resulting code appears as:
    String someVar = ""Hello" i am a "variable"";
    and not as:
    String someVar = "\"Hello\" i am a \"variable\"";
    I am assumming my regular expression is wrong. If it is, could someone explain to me how to fix it so that it will work?
    Thanks in advance.

    Thanks, appearently I'm just doing something weird that I just need to look at a little bit harder.

  • Java Embedding for writing string into file

    Hi ,
    According to my requirement I need to create a file and write string data into file.
    This string data I am getting as a output of the partner link. Their is 5 string variable which I need to write in file .
    I want to use java Embedding activity .
    So plz provide me any solution or any link.

    Hi,
    Why would you want to do this with java embeding? Why not just use the assign activity to create/concatenate the string and then write it to a file with the file adapter?
    Andre

  • [JS - CS4] Help w/ JS choking on quotes in strings & regex

    Does anyone have an easy way to extract text from a string with quotes in JavaScript? I seem to have run into a few limitations in the implementation of javascript's regex and how a script handles a string with quotes in it.
    Here's what I'm working with: a regular string like:
    {appliedParagraphStyle:"Headline 6", changeConditionsMode:1919250519}
    from which I'd like to extract just the text 'Headline 6' without any quotes
    I came across a regex that would get just the text without the quotes, but apparently Javascript does not support lookbacks. For instance, Jongware's wonderful WhatTheGrep script can decode this regex:
    (?<=")[^"]*?(?=")
    but ID finds nothing with it when run in a GREP search. The same search without the lookback finds stuff:
    "[^"]*?(?=")
    but what it finds still has the quote at the start of the string.
    I thought I could just use substrings to extract the text without the quote, but apparently this has issues. See these examples from the Javascript console:
    testStr;
    Result: "Headline 6"
    testStr.length;
    Result: 1
    testStr;
    Result: Headline 6
    testHL.length;
    Result: 10
    testHL;
    Result: "Headline 6
    testHL.length;
    Result: 1
    So if the string has a quote mark in it, it doesn't return the true length, so I can't code a start and end of the string to extract the part without the quote.
    Do any of you more experienced folks have some magic insight? TIA!

    It's an InDesign Oddity.
    Double quotes inside GREP strings behave a bit strange. Usually, the " character will find any sort of double quote -- straight, curly open, and curly closed. But inside a GREP lookbehind string this suddenly fails (in a lookahead it seems to work fine).
    If you replace it with its "forced" variant ~{ it will work on open curly quotes:
    (?<=~{)[^"]*?(?=")
    and if you need it to work on the 'any kind of double quotes' you can even use this:
    (?<=["])[^"]*?(?=")
    But ... all of the above only applies to searching in InDesign! And that's what WhatTheGrep reports upon.
    GREP-inside-Javascript has nothing to do with InDesign's implementation -- it's part of Javascript itself, and it is a completely different thing. (Well, it's still GREP of course. But there is no such thing as "It's still GREP" -- there are lots of different implementations.)
    So it's perfectly possible that this expression works in InDesign but does not work inside Javascript, when applied to Javascript strings. It seems the lookbehind isn't working at all (as it seems you alread found out, uh, on 2nd reading...).
    So you have to think of something else. How about this one? Using parentheses in a find expression can be useful!
    var str = "Hello world!";
    var f = str.match (/"([^"]+)(?=")/);
    if (f)
    alert ("Result: "+f.join("\r"));
    else
    alert ("Nothing matches...");
    str = "Hello \"world\"!";
    f = str.match (/"([^"]+)(?=")/);
    if (f)
    alert ("Result: "+f.join("\r"));
    else
    alert ("Nothing matches...");

  • Formatted file input of integers

    I can see how to do low-level file i/o and how to read in
    strings in Lingo, but I have a long list/array of numbers(
    integers) that I want to read into the program from a file once and
    for all at the start of the movie. Then later, I want to use these
    integers to control the movie display. Is there any easy way to do
    formatted file reads in Lingo, or do I have to write my own
    number-parsing routine? Thanks for any help.
    John

    Here are a couple of handlers that should return a string
    whose value() is the original list:
    on GetStringList(aList)
    -- INPUT: <aList> should be a linear or property list
    -- OUTPUT: Returns a string whose value is the original
    list. The
    -- use of embedded quotes in strings and the appearance of
    -- <Void> are explicitly treated. Void in sublists
    will
    -- be correctly treated, but strings with embedded quotes
    -- will only be treated in the outermost values
    if listP(aList) then
    aList = aList.duplicate() -- so that we don't change the
    original
    i = aList.count
    repeat while i
    tValue = aList
    case ilk(tValue) of
    #string:
    if tValue contains QUOTE then
    -- Replace embedded quotes
    aList =
    ReplaceAll(tValue,QUOTE,QUOTE&"&QUOTE&"&QUOTE)
    end if
    end case
    i = i - 1
    end repeat
    end if
    tString = string(aList)
    -- Replace any occurrences of <Void> with Void
    tString = ReplaceAll(tString, "<Void>", "Void")
    return tString
    end GetStringList
    on ReplaceAll(aString, aSubString, aReplacement)
    -- INPUT: <aString> is the main string to search in
    -- <aSubString> is a string which may appear in
    <aString>
    -- <aReplacement> is a string which is to replace all
    -- occurrences of <aSubString> in <aString>
    -- OUTPUT: returns an updated version of <aString>
    where all
    -- occurrences of <aSubString> have been replaced by
    -- <aReplacement>
    if aSubString = "" then
    return aString
    end if
    tTreatedString = ""
    tLengthAdjust = the number of chars of aSubString - 1
    repeat while TRUE
    tOffset = offset(aSubString, aString)
    if tOffset then
    if tOffset - 1 then
    put chars(aString, 1, (tOffset - 1)) after tTreatedString
    end if
    put aReplacement after tTreatedString
    delete char 1 to (tOffset + tLengthAdjust) of aString
    else -- there are no more occurrences
    put aString after tTreatedString
    return tTreatedString
    end if
    end repeat
    end ReplaceAll

  • Error while passing parameter(quoted string parameter ) to sql script

    Hi all,
    I have a master script insert_attribute_single.sql which takes 6 parameter. when i am using in sql prompt
    SQL>@@INSERT_ATTRIBUTE_SINGLE.SQL 'LEED PROJECT START DATE' 7 'N' 27265185 '7'22'008' NULL;
    then it is giving error for the 5th parameter. and i need to pass 5th parameter '7'22'008' in this.
    in the master script it is giving error - ORA-06550 here.
    dbms_output.put_line('Processing attribute : &1 Project : &4 Char value : &5 Numeric Value : &6 ' ) ;
    can you please help me to resolve this with single quotes in string.
    Thanks in advance.
    regards
    shyam~

    Here is my sql file:
    declare
    a_Var VARCHAR2(10) := '&1';
    begin
    dbms_output.put_line(a_var||','||'&2');
    end;
    /Here is how I am calling the sql file with parameter values containing quotes in itself:
    SQL> @@d:\a.sql '12''''23''''23' '123'
    old   2: a_Var VARCHAR2(10) := '&1';
    new   2: a_Var VARCHAR2(10) := '12''23''23';
    old   4: dbms_output.put_line(a_var||','||'&2');
    new   4: dbms_output.put_line(a_var||','||'123');
    12'23'23,123
    PL/SQL procedure successfully completed.
    SQL>

  • Create a Calculated field in Powershell that has embedded double quotes

    Hi
    I have a requirement that I am not quite sure is even possible in the context of Site Column
    I am getting an error - maybe though lack of embedded quotes but also I am wondering if this should be possible since Created is an OOTB column even if it is not currently used yet.
    $formula = 'TEXT(Created,mmYYYY)'
    $calcualtedField = $web.Fields.Add($siteColumn.DisplayName , "Calculated" , $false)
    $spField.Formula = $formula
    $spFeld.Update()
    Does this look correct or not
    Freelance consultant

    hi Devendra
    Thanks for the reply. In my case I want to set of Site Columns to be provisioned so that I can later pick these to be added to my Content Types.  I drive this entirely though .csv files and PowerShell.   Hence, I am working at the Site Collection
    level :
    $calcualtedField = $web.Fields.Add($siteColumn.DisplayName , "Calculated" , $false)
    Your code is does a similar thing to what I want but you are building a list with user defined fields. 
    I will log on the SharePoint server a bit later but do you see this code being valid ... "Created" is the display name for the OOTB Site Column and I have tired to embed quotes for the date mask. This Calc column should  be populated when
    the site column is added to Content Type which subsequently added to a list or library
    $formula = 'TEXT(Created,"mmYYYY")'
    Keep going with the YouTube videos as these are really useful
    Daniel
    Freelance consultant

  • How can i escape two quotes to assign text to string ?

    I have this text: <li><a
    href="/en/
    And i want to assign the text to a string:
    string t1 = "<li><a href="/en/";
    But i'm getting error on the en

    So you just can remove the last quote as
    string t1 = "<li><a href=\"/en/"
    Bob Bao
    Do you still use the same Windows 8 LockScreen always? Download Chameleon Win8 App quickly, that changes your LockScreen constantly.
    你是否还在看着一成不变的Windows 8锁屏而烦恼,赶紧下载这个
    百变锁屏
    应用,让你的锁屏不断地变化起来。

  • Quoting values

    This seems awfully elementary but I wonder if others have a better answer than I do.
    Like many, I'm sure, I routinely build SQL statements with code, often including literal string values. But if a literal value includes quotes, you have to escape these. For example, suppose you write:
    stmt.executeQuery("select * from customer where lastname='"+name+"'");
    Great if the name is "Smith", but if the name is "O'Malley" you get SQL syntax errors.
    I've gotten around this in two ways:
    1. Use a PreparedStatement and setString to get the values in.
    2. Write a function to massage the string, namely, put quotes around it and escape any embedded quotes. I generally call this "q" or some such so I can write concise code, like:
    stmt.executeQuery("select * from customer where lastname="+q(name));
    Is there a "right answer" to this? I hate to have to write my own function to do the escaping: What if I switch database engines and it has a different method of doing the escapes? Indeed, I've already had to deal with this: I wrote a similar "q" function to massage dates, but I need different versions for mySQL, MS Access, and SQL Server. Okay, put it all into a function and you only have to change one place when you swap engines, but still, it just seems that something like internal date formats in the database engine shouldn't be my problem: I should just give a SQL.Date object and it should work. But I can't find a built-in function, other than using PreparedStatement. Maybe PreparedStatement is the right answer, but I worry that,
    a) When I'm only doing it once, I'm now making two trips to the DBMS instead of one, which maybe is a trivial problem, so more important ...
    b) Sometimes the query generation is complex, like
    StringBuffer sql="select * from order where ";
    if (byname)
    sql.append("custname="+q(name));
    else
    sql.append("custid="+q(id));
    if (timerange)
    sql.append(" and shipdate>="+q(fromdate)+"and shipdate<="+q(thrudate));
    ... and so on. I've had a few where there were half a dozen conditions that changed what fields were included in a query. To do this with a PreparedStatement would make me then test all the conditions a second time, which makes the code hard to maintain.
    How are others dealing with this?

    I use PreparedStatements, they generally make for cleaner code, more portable across DBs, and more robust. Trying to avoid them for performance reasons sounds a bit like premature optimization to me, although you are correct in that they may be slower if used only once.
    There's a great discussion of Statement vs PreparedStatement in 'J2EE Design and Development' by Rod Johnson, pages 323-4.
    -Scott
    http://www.swiftradius.com

Maybe you are looking for

  • Embedding expanding flash ads in existing web page.. help!

    Hi guys! I am having a problem and can't find a site anywhere that helps. My company have just started selling expanding flash ad spaces but I have no idea how to make these work on a current and very clunky site. The space on the page I have for sky

  • Can FCP Black and Code HDV tapes?

    (Reposted from the FCP Express forum) I'm running FCP Studio 5.0.4. I'm trying to stripe some HDV tapes for an upcoming shoot. I've set up a project using the 1080i60 Easy Setup. I have my Sony FX-1 set to HDV record mode and HDV input. When I go to

  • How can I make a scrolling text in keynote for iPad?

    I have a long text box I have typed on keynote for iPad 2 on iOS 5.1.1 and I am trying to get it to scroll so I can fit it on one slide... How? I have tried using moving in and moving out but it moves too fast for anyone to read.

  • Set required fields for listbox RP_OPTIONS_INTO_STRING

    Hi Experts, I want to creat a listbox using FM RP_OPTIONS_INTO_STRING. And I want to set some fields as mandatory fields such as Personal number and Company code. I noticed there is a column in the component named 'Requried' Does anyone know how to s

  • MDIS Value Map and Add

    I know this has been discussed but I'm running into a peculiar problem. For Default MDIS Handling: Automap unmapped values: Yes Unmapped value handling: Add I'm trying to import into Catalog Items table. The field Supplier is setup with 2 display fie