With single quotes varchar column

Hello

How to extract a varchar column with single quotes in the DB

For example, I want the result as below

SELECT id, name of the cust

1, 'ABC '.

Kind regards
Abdul
select id
      ,''''||name||''''
  from cust

Tags: Database

Similar Questions

  • help request pivot with single quotes inside a string literal

    Hi all

    I have a little trouble with a pivot query. Oracle (10g R2) is:

    ORA-00604: an error occurred at recursive SQL level1
    ORA-01003: no instruction not analyzed

    My problem is pretty clear. When I do a pivot query to display a list of records where the countries are the column headers and rows headers is months that the system hesitates when she returns a country with an apostrophe in it. for example

    COUNTRY_NAME = ' KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF»

    I know that I have to catch the literal single quote and manipulate. I am just having unsuccessfully in management of it and I'm a little out of ideas. Can someone tell me a nice solution?

    The complete procedure is listed below: the


    PROCEDURE getCountryInvPlan)
    iINV_PLAN_DEPOT_ID in NUMBERS
    iITEM IN VARCHAR2,
    RC IN OUT pkg_DMT_INV_PLAN.t_rc,
    oErrorMsg OUT VARCHAR2)
    IS
    v_sql VARCHAR2 (32767).
    BEGIN


    v_sql: = 'select MONTH_BUCKET ';
    FOR rec IN
    (select distinct (COUNTRY_NAME) in the DMT_INV_PLAN_DEPOT_COUNTRY where INV_PLAN_DEPOT_ID = iINV_PLAN_DEPOT_ID)
    LOOP
    v_sql: = v_sql
    || ', MAX (DECODE (COUNTRY_NAME, "'))
    || recomm. COUNTRY_NAME
    || ((', PATIENT_DEMAND)) ' "»
    || recomm. COUNTRY_NAME
    || '"';
    END LOOP;
    v_sql: = v_sql
    || ', ' DECODE(MONTH_CLOSED,0,''OPEN'',1,''CLOSED'') AS MONTH_STATUS
    || ' FROM (SELECT DMT_INV_PLAN_DEPOT_COUNTRY. MONTH_BUCKET, DMT_INV_PLAN_DEPOT_COUNTRY. COUNTRY_NAME, DMT_INV_PLAN_DEPOT_COUNTRY. PATIENT_DEMAND, DMT_INV_PLAN_ITEM. DMT_INV_PLAN_DEPOT_COUNTRY MONTH_CLOSED, DMT_INV_PLAN_ITEM '
    || "where DMT_INV_PLAN_DEPOT_COUNTRY.". INV_PLAN_DEPOT_ID = DMT_INV_PLAN_ITEM. INV_PLAN_DEPOT_ID '
    || ' AND DMT_INV_PLAN_DEPOT_COUNTRY. ITEM_DESCRIPTION = DMT_INV_PLAN_ITEM. ITEM_DESCRIPTION '
    || ' AND DMT_INV_PLAN_DEPOT_COUNTRY. MONTH_BUCKET = DMT_INV_PLAN_ITEM. MONTH_BUCKET '
    || ' AND DMT_INV_PLAN_DEPOT_COUNTRY. INV_PLAN_DEPOT_ID = ' | iINV_PLAN_DEPOT_ID
    || ' AND DMT_INV_PLAN_DEPOT_COUNTRY. ITEM_DESCRIPTION = "' | iITEM | " ') '
    || 'GROUP by MONTH_BUCKET order MONTH_BUCKET MONTH_CLOSED';
    RC OPEN FOR v_sql;

    oErrorMsg: = v_sql;

    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
    oErrorMsg: = "NO DATA FOUND";

    WHILE OTHERS
    THEN
    oErrorMsg: = "ERROR";
    oErrorMsg: = v_sql;
    END getCountryInvPlan;

    Maybe you can try this:

    -- Etc --
    || ',MAX(DECODE(COUNTRY_NAME,'''
    || REPLACE(rec.COUNTRY_NAME,'''','''''')
    || ''',PATIENT_DEMAND)) "'
    || rec.COUNTRY_NAME
    || '"';
    -- Etc --
    

    8 2

  • Unable to [out] the value of the parameter put_line with single quotes (apostrophe)

    Hello

    I want to store a common code in a sql file and where the different clauses as a parameter, so the structure is:

    Main.SQL Script:
    set m_sWhere = ' owner = "SCOTT" ';
    @MyReport.sql '& m_sWhere '.

    MyReport.sql
    OK: SELECT * FROM MyTable WHERE & 1
    ERR: dbms_output.put_line ('MyWhere: & 1');

    I am not able to print the where the clause. I already tried to set the where clause with other delimiters (e.g. #SCOTT #) and replace # by ' in the MyReport but failed as well.

    All advice welcome.

    Published by: netaktiv on 11.02.2012 08:35

    Hello

    netaktiv wrote:
    Hello

    I want to store a common code in a sql file and where the different clauses as a parameter, so the structure is:

    Main.SQL Script:
    set m_sWhere = ' owner = "SCOTT" ';
    @MyReport.sql '& m_sWhere '.

    Sorry; It is unclear what you are trying to do, and what you're doing.
    I think the only single-quoptes in m_swhere are those before and after SCOTT:

    DEFINE  m_sWhere = owner='SCOTT'
    

    That's what you need to be able to use this variable in an SQL statement. SQL * more will replace & 1 with its value. If you were typing the statement directly, just type a single before and after SCOTT quote, if you want only a single quote before and after SCOTT in m_swhere. You use 2 single quotes in a row inside string literals, but the string literal only you need here is the literal 5 characters 'SCOTT', containing sound ", a 'C', 'o', two ' t and single quotes to zero."

    MyReport.sql
    OK: SELECT * FROM MyTable WHERE & 1
    ERR: dbms_output.put_line ('MyWhere: &1');)

    I am not able to print the where the clause. I already tried to set the where clause with other delimiters (e.g. #SCOTT #) and replace # by ' in the MyReport but failed as well.

    You do not want channels OK: or ERR: in the script.
    Dmbs_output.put_line, like any procedure, only works in PL/SQL.
    If you want to display text in a SQL * more script, use the SQL * FASTER command, like this:

    PROMPT  MyWhere: &1
    

    If you really must use dbms_output.put_line, then you will need to use a string literal, and single quotes can be tricky.
    In Oracle 10 (and more) use Q-rating:

    BEGIN
        dbms_output.put_line ( Q'{MyWhere: &1}' );
    END;
    /
    

    {Quotes will not be a problem unless they occur immediately after a right '}'.

  • Insert into DB using SQLservice: can't take the text with single quotes:

    I use Execute sql JDBC service statement.

    I'll explain with simple code:

    insert into mytable (id, desc) values (1, 'this is the document of the customer');

    This works perfectly.

    But if I have apostrophes in the desc-

    insert into mytable (id, desc) values (1, 'this is the document the customer' );

    It is throwing error at a standstill operation errors.

    I know that in Oracle, to escape the single quotes that write us

    insert into mytable (id, desc) values (1, "it is of customer" s document ");

    But, we can not control here in Adobe as the desc is from field on a form when the user enters it.

    I'm guessing that it might be a known issue & can someone tell me the solution.

    Thank you

    KC

    Use a parameter query to avoid this problem.

    insert into mytable (id, desc) values (?,?);

    The two parameters (? brands) can be replaced by actual values using XPATH Expression.

    If you do this, you query runs without raising any errors.

    Nith

  • Select statement with single quotes in the insert statement

    Dear Sir

    What's the trick to cover this issue:

    Insert into TEST_TABLE (SQL_SCRIPT_ID, SQL_SCRIPT)
    values ("1", "select count (*) from the SOURCE where SOURCE.") VALID = 'Y')

    because of the single quotes, I get an error and can not insert, the script works, is there a workaround somehow?

    Thank you 1 million,

    Erik

    Published by: 845498 on June 13, 2012 04:15
    create table testsql(script_id number,sql_script varchar2(1000));
    
    insert into testsql (script_id, SQL_SCRIPT)
    values (1, 'select count (*) from SOURCE where SOURCE.VALID = ''Y''');
    
  • Display the string with single quote

    Hello..

    I have a doubt.

    Below the statement works very well to get the result in single quotes as 'Hello world'
       SELECT '''Hello World'''
       FROM dual;
    Now my question is why we get error when we try to do the same.

       SELECT ''Hello World''
       FROM dual;
    Please let me know the reason, if an organization is to have an idea.

    Thank you
    Suri

    To print a single quotation mark, use two single quotes (IE he "s to print from) and to print a string to write the string inside the single quotation mark as"Hello Word ".
    You want to print "Hello World" your sql will be

    SELECT '''Hello World'''
       FROM dual;
    

    You get the following error as search oracle of KEYWORD Analyzer after "that a chain is closed using the" quote

    SELECT ''Hello World''
       FROM dual;
    ORA-00923: FROM keyword not found where expected
    
  • Operator with single quotes

    Hi all

    I quote the dealing with problem unique with OPERATOR. Procedure below explains my problem:
    create or replace procedure sp_countemp
    (
    p_empnames       in   varchar2
    )
    is
    
    v_cnt            integer:=0;
    
    BEGIN
    
    select count(*) into v_cnt from emp where ename in (p_empnames);
    DBMS_OUTPUT.PUT_LINE(v_cnt);
    
    END;
    I will get p_empnames as "ALLEN", "SMITH".

    But I don't get all the records here.


    Thank you
    Danish

    Hi, Danish,

    See this article on [Oracle Base | http://www.oracle-base.com/articles/misc/DynamicInLists.php].

  • dbms_xmlgen. GetXml with single quotes

    Can you get it someone please let me know what is wrong with this query. I try to convert the long and CLOB type. I wanted to convert long to varchar2 and to do this, I am to convert the long to clob or varchar2 clob.

    The query works fine when doing a rownum = 1 in the dynamic query but I would like to read carefully all the constraints so tried the underside and its failure with an error message for an unexpected end of SQL command.

    -with rownum

    SELECT dbms_lob.substr (longtoclob, 4000, 1) text

    of the double.

    (select (dbms_xmlgen.getxml ("SELECT t.search_condition ALIASLONG

    OF All_Constraints t WHERE rownum = 1')) longtoclob

    the double) Y where DBMS_LOB. GETLENGTH (Y.longtoclob) > 0;

    -generic query

    Select (SELECT (dbms_xmlgen.getxml (Q'[select search_condition in all_contstaints where cosntraint_name = ']' | constraint_name |))) Q '[']')) text, constraint_name from

    ALL_CONSTRAINTS

    where rownum < = 3;

    -generic query

    Select (SELECT (dbms_xmlgen.getxml (Q'[select search_condition in all_contstaints where cosntraint_name = ']' | constraint_name |))) Q '[']')) text, constraint_name from

    ALL_CONSTRAINTS

    where rownum<>

    'A few' bad stuff here:

    -keyword SELECT extra

    -typos in names of objects

    -DBMS_XMLGEN.getXML will give you a CLOB that represents a dataset XML to canonical format, not the search_condition directly necessary

    It is more what you are looking for, but know it's slow:

    select constraint_name
         , xmlcast(
             dbms_xmlgen.getxmltype(
               'select search_condition from all_constraints where constraint_name = ' || dbms_assert.enquote_literal(constraint_name)
             )
             as varchar2(4000)
           ) as text
    from all_constraints
    where rownum <= 3 ;
    

    (XMLCAST is 11g only, use the extractValue on lower versions)

  • Generation of single quotes in strings

    Version: 11.2.0.3

    We have a custom stored procedure called GENERATE_STATS and I want to run this procedure for each schema in the comic book as

    exec ('SCOTT', 'BASIC') generate_stats;

    generate_stats exec ('HR', 'BASIC');

    .

    .

    .

    .

    exec ('XXXXXX', 'BASIC') generate_stats;

    -All except XXXXXX is fixed.

    -XXXX is derived rom DBA_USERS

    I want to generate these commands dynamically as

    SQL > SELECT ' exec generate_stats ("' | username |) (', "'BASIC"); from dba_users;

    ERROR:

    ORA-01756: city not properly finished chain

    -I noticed that, to generate a single quotation mark, you need 4 quotes

    SQL > select "' double.

    '

    -

    '

    SQL > select "',"' double.

    '''

    ---

    ','

    -I managed to create so far without much trouble.

    SQL > SELECT ' exec generate_stats ("' | username |) "',"' from dba_users where rownum < 5;

    ' EXECGENERATE_STATS('''||) USER NAME | " ','' '

    --------------------------------------------------------

    generate_stats exec ("SYS"

    exec generate_stats ("SYSTEM",")

    exec generate_stats ('OUTLN', ')

    generate_stats exec ('DIP', ')

    It took a lot of trial and error to add the remaining portiton BASIC'); to added. The following finally worked.

    SQL > SELECT ' exec generate_stats ("' | username |) (', "BASIC");' from dba_users where rownum < 5;

    ' EXECGENERATE_STATS('''||) USER NAME | " (', "BASIC"); "

    ----------------------------------------------------------------

    generate_stats exec ('SYS', 'BASIC');

    exec ('SYSTEM', 'BASIC') generate_stats;

    generate_stats exec ('OUTLN', 'BASIC');

    exec ('DIVE', 'BASIC') generate_stats;

    To generate the string 'BASIC' . I didn't have to use single quotes 4 as I once did.

    It generated when I placed between her with just two single quotes like that "BASIC");'

    There are a few basic rules I should keep in mind when you try to generate strings with single quotes?

    Hello

    In a string literal, single quotes normally indicate the beginning or the end of the literal.

    If you want to specify a single quote, is to use 2 consecutive single quotes in the literal.  For example, the name of 9 characters O'Higgins could be written in a literal string like this

    'O' Higgins

    ICT that there are 4 single quotes above: 1 to indicate the beginning of the literal string, 2 to represent a single quotation mark in the literal and 1 at the end of the literal.

    If you want a string of characters-1 that contains only a single quote, and then, as you noticed, it was released as 4 of them in a row

    ''''

    If you want to represent the 12 string

    ","BASIC");"

    in a string literal, then you have to put everything in a pair of simple and douuble quotes all quotes that occur in the sting, like this:

    (', "BASIC"); "

    When you asked if there was a rule of THUMB , you were doing a play on words?

    There is a rule of practice. When you use this type of string literal, single quotes always occur in pairs.  You always need a pair to mark the beginning and the end of the literal.  For each single quote representation, you need a pair.  If the string that represents the 12 above string literal contains 4 pairs of single quotes.  I'll write this liteal once again, with the numbers in pairs:

    (', "BASIC"); "

    122 33 44 1

    1 pair surrounds the literal; pairs of 2, 3 and 4 represent single quotes in the literal.

    If ever you have an odd number of single quotes using this notation, then you know that something is wrong.

    It is the older way of the use of single quotes in the string literal.  From Oracle 10, you have the possibility to use Q-notaation as well:

    Q'<', 'basic');="">'

    When you use Q-rating, you can have literals well trained with an odd number of single quotes.  The literal above happens to have 5, 2 that surround the literal.

    See the manual of the SQL language for more info on Q-rating:

    Literals

  • To insert single quotes

    Hello
    All,

    Oracle 10.2.0.3
    AIX 5.3

    I have following the query

    Select 'ALTER DATABASE RENAME FILE ' | name | "To/ORACLE/u44/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 the string with single quotes. How can I achieve this?

    Thank you
    Vishal
    select '''ALTER DATABASE RENAME FILE'''  from dual
    
    o/p: 'ALTER DATABASE RENAME FILE'
    
  • How to write a query to return rows with the varchar column that contains even a single occurrence of the characters, such as Ÿ and

    How to write a query to return rows with the varchar column that contains even a single occurrence of the characters, such as Ÿ and

    I have a table whose columns with values such as

    MINNEAŸPOLIS and ¿VV ¿A

    Only the characters that are allowed in this column are alphabets, numbers, spaces, points and supports.

    Please help to write a SQL SELECT with Regexp_like query or any other option.

    Thanks to you all! Under query worked for me. Thank you Frank to explain the concept of hooks inside regexp_like.

    SELECT * FROM testspecial, WHERE REGEXP_LIKE (sampletext, "[^] ^ A - Z ^ a - z ^ 0-9 ^ [^.]") ^ {^} ^]') ;

  • magic_quotes_off, now this with the single quote in the variables?

    Okay, so I turned off magic_quotes because they go far anyway. Broke one of my pages and the list of items in the table of database that is supposed to appear was not there. So, I opened the recordset on the page and deleted the apostrophes in the recordset object variables and all reappeared. That tells me I should open EVERY single game records on this site and remove the single quotes? Does that include digital as well as text?

    Thank you for your help.

    Brian

    Magic quotes were originally intended to help beginners (and we are all beginners at some point), but found to be murkier than they are worth. I have to admit that the whole quote, addslashes() and stripslashes() functions had confused me for a while, and I found myself with the backslashes in all directions. It's the partition:

    When you create a query SQL in PHP, it must be a string, it must be enclosed in quotes (single or double - is not serious). However, SQL queries must be enclosed in quotes in the text, and the text you type may also contain a mixture of single and double quotes. The idea of magic quotes is that it automatically inserts a backslash before each quotation mark in a string, which makes the single quotes or double in safe to put in a SQL query text. When you pull the text from the database, you use stripslashes() to get rid of the back-slash.

    The problem is that magic quotes can be disabled, so many books and tutorials tell you move your text to function addslashes() before putting the text in a database. If magic quotes are still on, you end up with two backslashes instead of one. Nightmare. That's why magic quotes are underway.

    Rather than use the addslashes() and stripslashes() functions, it is now recommended to use mysql_real_escape_string() or prepared statements. Given that Dreamweaver does not support prepared commands, I'll leave them out of this. Whenever you pass a variable to a SQL query in Dreamweaver, it passes through the GetSQLValueString() variable, which can detect if magic quotes are enabled. If they are, it will use stripslashes() to get rid of the back-slash; and then it passes variables to mysql_real_escape_string() prepare for insertion in the database. All your single and double quotes in the text are preserved and not a backslash in sight.

    The problem is that if you have a text that has been inserted by using magic quotes and/or functions addslashes(). The simple solution is to use stripslashes() to remove the backslashes in the text stored before you post or use it somehow.

    echo stripslashes($row_recordsetName['fieldName']);
    

    I hope that clarifies the situation and provides a solution. If this isn't the case, it may be necessary to purge your database of backslashes.

    The problem with magic quotes affects only text. Numeric fields are not affected.

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

    Hello:

    I guess that's really a question of XSLT. I use the XMLType variable Transform() method to apply a style sheet. The XML code in the variable is just something simple like

    < TBL >
    < name > AS | JONES < / LAST_NAME >
    < name > = | MARIE < / name >
    < AGE > = | 50 < / AGE >
    < / TBL >

    I'm trying to get a style sheet to transform something like the above SQL such as
    Select * from foo where LAST_NAME like 'JONES' 
    and FIRST_NAME ='MARY'
    and AGE = 50
    But to do this, I need to generate single quotes around search terms and I can't get anything else that
    LAST_NAME LIKE &apos;JONES&apos;
    . Is there a way to do this? Because now I'm generating a ~ and replacement ~ for ' all the SQL generated text throughout, but is a pretty sorry solution.

    I thought that something like
    <xsl:text disable-output-escaping="yes">&amp;</xsl:text>
    go to work but then is found out that he has been deprecated. I thought about character-card would work, but it's one thing to XSLT 2.0 and apparently 10g is on XSLT 1.0? In all cases, he didn't know what I was trying to do with a character map.

    So, I forget one obvious way to get my style sheet to insert apostrophes?

    Thank you.

    Comment by Marco needing dbms_xmlgen.convert was OK for 10.2.0.4. Here is an example which produces the same result, but requires dbms_xmlgen.convert when I run it on 10.2.0.4 and works as an example of Mark on 11.1.0.x.

    declare
      l_xml   XMLTYPE := XMLTYPE('
    
      
        
        
        
        
      
      
        
        
        
        
      
      
        
        
        
        
      
      
        
        
        
        
      
      
        
        
        
        
      
    ');
    
       l_xsl XMLTYPE := XMLTYPE('
    
      
      
    
    
      
        select * from
        
        where 1=1
        
          
            
            
            
              AND 
               
              
               
              
                
                  '
                  
                  '
                
                
                  '
                  
                  '
                
                
                  
                
              
            
          
        
      
    ');
    
       l_result   CLOB := '1';
    begin
      -- 10.2.0.4 version
      --l_result := dbms_xmlgen.convert(l_xml.transform(l_xsl).getStringVal(), dbms_xmlgen.ENTITY_DECODE);
      l_result := l_xml.transform(l_xsl).getStringVal();
      -- 11.1.0.6 version
      dbms_output.put_line(l_result);
    end;
    
  • replace a single quote with the double quotes with the function replace

    I work with one apex page, which contains a text as a filter box. If I put a single quote and find then I get the error message saying that parse error.

    For this, I want to replace one single quotation mark with double quotes, so this should be perfect. and apex should show the result.

    A allow the query to the same which will replace the single quote with double quotes.

    Published by: Santhosh Kumar T 15 Sep 2008 05:13

    If it was confusing... Try the less confusion (according to you)! ...

    Select Replace ("ab" | ") "|' it," ',' "') twice;"

  • Using single quotes with MaxL in batch scripts

    I have the following MaxL, I need to pass to essmsh via a batch script:

    run the calculation ' FIX("Member 1") CLEARDATA "member 2"; ENDFIX' on App.Db;

    The problem is that the single quotes cause problems when it is passed as a variable in the batch script. However, if I change single quotes to double quotes the batch script is happy but the MaxL is not valid.

    Please can anyone suggest how I can get this to work?

    You also try that works

    ( @echo login %USER% identified by %PASS% on %SERVER%; & @echo execute calculation "'FIX(\"Member 1\") CLEARDATA \"Member 2\"; ENDFIX'" on App.Db; & @echo logout; & @echo exit; ) | essmsh
    

    See you soon

    John
    http://John-Goodwin.blogspot.com/

Maybe you are looking for