Quoted string in select

When doing a select statement, is it possible to get sqlplus to automatically put quotes around data in varchar columns?

Rick,
Yes, this is possible. I'm guessing that you want to generate output that can be imported into another system or application? Regardless, this is how you'd do it.
Lets say you have a table called EMP, with columns LAST_NAME VARCHAR2(40) and FIRST_NAME VARCHAR2(40), and you want your output to look like this:
LAST_NAME FIRST_NAME
'Smith' 'John'
your SELECT statement should be:
SELECT ''''||last_name||'''' last_name, ''''||first_name||'''' first_name FROM emp;
Now if you're creating a comma-delimited file, and want your output to be:
'Smith','John'
your SELECT statement would be something like this:
SELECT ''''||last_name||''','''||first_name||'''' FROM emp;
Enjoy!
Armand

Similar Messages

  • Quoted string not properly terminated

    I am trying to use the tune_mview package. I am setting up variables in sqlplus to use when calling the package. I am using the following to set the entire create Mview staement into a variable, but am getting a ORA-01756: quoted string not properly terminated. I can execute the select statement inside the create mview statement, and can execute the create mview statement, but when I try to set the entire statement into a variable I get the error. This is 10gR2.
    EXECUTE :create_mv_ddl := q'|CREATE MATERIALIZED VIEW WH.MV_SPS_CONTRIB_SPLITS ENABLE QUERY REWRITE AS
    select
    c.rep_nbr rep_number
    ,decode(p.override,null,c.rep_nbr,p.override) override
    ,c.rep_type
    ,decode(s.rep_number,null,1,decode(s.summed_perc,0,1/s.number_of_splits,p.payout_perc/s.summed_perc)) Comm_Contr
    ,p.payout_perc Split_Percentage
    ,s.summed_perc Sum_Of_All_Splits
    from
    wh.t_stg_sps_rep_control c
    ,(select *
    from wh.t_stg_sps_rep_payout p
    where
    p.payout_cat = 'PRC'
    and production_credit = 'Y') p
    select
    rep_nbr rep_number
    ,sum(payout_perc) summed_perc
    ,count(*) number_of_splits
    ,count(payout_perc) used_for_MV_rewrite
    from
    wh.t_stg_sps_rep_payout
    where
    production_credit = 'Y'
    and payout_cat = 'PRC'
    group by
    rep_nbr
    ) s
    where
    c.rep_nbr = p.rep_nbr (+)
    and p.rep_nbr = s.rep_number (+)
    order by
    c.rep_type
    ,p.rep_nbr |';

    Hi,
    If i spotted the error I would write...two ('|') in the beggining and end of the CREATE statement .
    EXECUTE :create_mv_ddl := q'||CREATE MATERIALIZED VIEW WH.MV_SPS_CONTRIB_SPLITS ENABLE QUERY REWRITE AS
    select
    c.rep_nbr rep_number
    ,decode(p.override,null,c.rep_nbr,p.override) override
    ,c.rep_type
    ,decode(s.rep_number,null,1,decode(s.summed_perc,0,1/s.number_of_splits,p.payout_perc/s.summed_perc)) Comm_Contr
    ,p.payout_perc Split_Percentage
    ,s.summed_perc Sum_Of_All_Splits
    from
    wh.t_stg_sps_rep_control c
    ,(select *
    from wh.t_stg_sps_rep_payout p
    where
    p.payout_cat = 'PRC'
    and production_credit = 'Y') p
    select
    rep_nbr rep_number
    ,sum(payout_perc) summed_perc
    ,count(*) number_of_splits
    ,count(payout_perc) used_for_MV_rewrite
    from
    wh.t_stg_sps_rep_payout
    where
    production_credit = 'Y'
    and payout_cat = 'PRC'
    group by
    rep_nbr
    ) s
    where
    c.rep_nbr = p.rep_nbr (+)
    and p.rep_nbr = s.rep_number (+)
    order by
    c.rep_type
    ,p.rep_nbr[b] ||';
    Regards,
    Simon

  • ORA-01756: quoted string not properly terminated (using (q) operator

    Hi
    I tried this example but giving the error
    select q'( it's done )' from dualbut the following is working
    select q'( it''s done )' from dualIf i need to use it''s done then what is the use of (q) operator
    Thanks..
    Edited by: josh1612 on May 10, 2010 11:09 PM

    What is your database version ? Q-quote operator introduced in Oracle 10g and see the example, you might be facing this error.
    This is in SQL *PLUS V 9.2.0.1.0
    SQL> select * from v$version;
    BANNER
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
    PL/SQL Release 10.2.0.1.0 - Production
    CORE    10.2.0.1.0      Production
    TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    SQL> select q'( it's done )' from dual;
    ERROR:
    ORA-01756: quoted string not properly terminated
    SQL*Plus: Release 10.2.0.1.0 - Production on Tue May 11 12:58:12 2010
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    SQL> conn hr/hr
    Connected.
    SQL> select q'( it's done )' from dual;
    Q'(IT'SDONE
    it's doneEdited by: Saubhik on May 11, 2010 12:28 AM

  • Urgent: help me on: ORA-01756: quoted string not properly terminated

    I got the following error message when I tried to insert a record into database.
    Please help me in this regard. I need to insert upto 2000 bytes.
    insert into activity_reason values(1733214, 3234, 23,'P54I8N',to_date('04/19/2006','MM/DD/YYYY'),NULL, NULL, NULL, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd1600', NULL, NULL, NULL, NULL);
    ERROR:
    ORA-01756: quoted string not properly terminated
    table desc:
    SQL> desc activity_reason;
    Name Null? Type
    CASE_ACTIVITY_ID NOT NULL NUMBER(10)
    REASON_CDE NOT NULL NUMBER(5)
    QUESTION_ID NOT NULL NUMBER(10)
    OPER_ID NOT NULL CHAR(8)
    LAST_UPD_TMS DATE
    COMMENT_TXT_1 VARCHAR2(240)
    COMMENT_TXT_2 VARCHAR2(240)
    COMMENT_TXT_3 VARCHAR2(240)
    COMMENT_TXT_4 VARCHAR2(2000)
    LETTER_TXT_1 VARCHAR2(240)
    LETTER_TXT_2 VARCHAR2(2000)
    PATIENT_LETTER_TXT_1 VARCHAR2(240)
    PATIENT_LETTER_TXT_2 VARCHAR2(2000)

    Hi,
    It's work fine on my 9.2.0.4 database.
    SQL> create table activity_reason
      2  (CASE_ACTIVITY_ID  NUMBER(10) NOT NULL,
      3  REASON_CDE NUMBER(5) NOT NULL,
      4  QUESTION_ID NUMBER(10) NOT NULL,
      5  OPER_ID CHAR(8) NOT NULL,
      6  LAST_UPD_TMS DATE,
      7  COMMENT_TXT_1 VARCHAR2(240),
      8  COMMENT_TXT_2 VARCHAR2(240),
      9  COMMENT_TXT_3 VARCHAR2(240),
    10  COMMENT_TXT_4 VARCHAR2(2000),
    11  LETTER_TXT_1 VARCHAR2(240),
    12  LETTER_TXT_2 VARCHAR2(2000),
    13  PATIENT_LETTER_TXT_1 VARCHAR2(240),
    14  PATIENT_LETTER_TXT_2 VARCHAR2(2000));
    Table created.
    SQL>
    SQL> insert into activity_reason values(1733214, 3234, 23,'P54I8N',to_date('04/19/2006','MM/DD/YYYY'),NULL, NULL, NULL, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd1600', NULL, NULL, NULL, NULL);
    1 row created.
    SQL> What is your db version ?
    Nicolas.

  • Runtime.getRuntime().exec and quoted strings?

    Attempting to execute a command containing a quoted string. Being very new to Java I'm guessing I'm not doing it right. Below are two code bits the first one works the second doesn't. So the question is "How do I use quoted strings in a command with .exec?"
    // this one works
    try {               
    p = Runtime.getRuntime().exec("ls -l tst.java");
    p.waitFor();
    System.out.println("Done!");
    catch(Throwable e) {                                  
    system.out.println("Errors!");
    // this one fails
    try {               
    p = Runtime.getRuntime().exec("ls -l \"tst.java\"");
    p.waitFor();
    System.out.println("Done!");
    catch(Throwable e) {                                  
    system.out.println("Errors!");

    I don't know if it is too late for the answer, but I think I know what the problem is.
    You are using exec(String) method, and passed String parameter is parsed using StringTokenizer class. This means that when you use quotes as in "file1 file2", StringTokenizer parses this as "file1 and then file2" so it is not understandable command.
    To solve the problem, do not use exec(String) method, use exec(String[])
    Using this you can send separate command and separate parameters as in following example:
    If you want to send (in Unix)
    grep "SHOW lotid" text.txt
    (using exec("grep \"SHOW lotid\" text.txt") would not work)
    Do the following
    exec(new String[]{"grep", "SHOW lotid", "text.txt"});
    This avoids parsing problem when quotes are used.
    Mehmed

  • Can I use the quoted string in the field like  dbms-column or table-name

    I see some examples like table name using quoted string in the weblogic-rdbms20-persisstence-810.dtd.
    Can the experts tell me how the quoted string should be used for EJB 20?

    Hi,
    Whether the identifiers should be quoted or not depends whether they were defined that way when the table and colums were created. Whether they can be created/accessed this way depends on the policy of the database that you are using with regards to 'Quoted Identifiers' (also known as 'Delimited Identifiers'). On databases this feature is on by default, on others it is not. If you database objects require quoted identifiers then you may enter them as quoted as you've seen in the weblogic-rdbms20-persistence-810.dtd
    Hope this helps
    -thorick

  • Embedded double quotes in a quoted string not working.

    It seems that Numbers doesn't process embedded double quotes correctly in a quoted string. Is this an issue that Apple are aware about? Any fixes planned? Is this an issue that Apple are aware about? Any fixes planned?
    This is not an issue in Excel, but I'd prefer to use Numbers.

    To run Hiroto's script, copy and paste into AppleScript Editor.  Click the compile "hammer" to make sure the copy/paste went well.  Then (still in AppleScript Editor click the run button.  Then, back in Numbers, click once in a cell in an existing table, and paste.
    To run the service in the post immediately above Hiroto's, just click the link in my post and doubleclick the downloaded .workflow package. (You may have to go to System Preferences > Privacy & Security and click "Download Anyway").  It then appears automatically in your Numbers > Services menu.  Then to run the script just choose the item in the menu item CSV to Tabs on Clipboard.
    You can uninstall the Service at any time by holding down the option key while in Finder and from the menu Go > Library > Services.
    If you have a chance to try these, would be interested in hearing back whether they worked for you. They are working well on my setup here.
    SG

  • Quoted string

    I have a string like this: This is the A' tring sample. into a variable
    Obviously when I tray to insert this I get the error because the middle quote:
    ORA-01756 quoted string not properly terminated
    What can I do if I need to sotred as it appears (with the middle quote)?

    If ur string is like "This's sample" then try to insert it with this 'This''s sample' .
    hope this will hepl u...
    null

  • Finding strings in "Selected Files in Site" not working

    When searching files for a string, and selecting "Selected Files in Site", Dreamweaver (starting today) will only search the root directory, NOT the selected subdirectory.  This is uselss.  I've been using Dreamweaver for years.  Today I switched to mapping the site with an IP address instead of a server/domain name, could this be the culprit?

    I encountered exactly the same problem.
    I'm trying to solve this problem...

  • "quoted string not properly terminated" error in File to Oracle interface

    We have an interface at our site that is a simple file to Oracle interface. We used the sqlldr LKM and the SQL Control Append IKM. The interface bombs out when one of the unmapped Oracle fields has this for a string literal in it: '--A'. It's a size 3 varchar field in Oracle. We can put in other literals fine in it, but using the '--A' one brings back this error in the Insert portion of the interface:
    1756 : 42000 : java.sql.SQLException: ORA-01756: quoted string not properly terminated
    java.sql.SQLException: ORA-01756: quoted string not properly terminated
    I ran the sql query that ODI bombs out on and the record inserts fine inside sql developer.
    Anybody else experience this and if so what was the solution to get past this?
    We're using ODI 10.1.3.5.5.

    Hi A,
    I tried this but it didn't work. I am puzzled as to why OBIEE prints any special character after a % twice. For example %& becomes %&& or %' become %'' . I guess it is the Evaluate function that is fiddling with the % .
    Thanks.
    Edited by: 900740 on Feb 9, 2012 9:22 AM

  • Concatination of string to select statement

    hi all,
    pl help me out.
    i want to concatenate string to select statement like
    create or replace procedure my_proc(p_sal number)
    as
    v_name varchar2(20);
    ssql varchar2(4000);
    begin
    ssql := ' ';
    select ssql || ' '|| select emp_name
    into v_name
    from employees
    where sal =p_sal;
    end;
    but it is giving error .
    pl correct it.
    thanks
    pavani

    Pavani,
    Still not clear.
    "Multiple conditions" sounds like you are trying to build predicates in the where clause, but in your example it looks like you are trying to build a select clause. Also your parameter is p_sal so the where clause "sal = p_sal" is fixed.
    The real question is WHY you want to "write multipul conditions"? WHY you want to "store it in a string .and then concatenate the string to next condition so on"?
    Regards,
    Rob.

  • String str = " Select ? , ...

    Hi ,
    I have a query for which I need to use PreparedStatement .The query runs likes this :-
    String str = " Select ? , ename from emp where deptno ? ";
    The values of ? need to be assigned dynamically.
    But I cannot create Prepared Statement from this query .
    If you have got answer to your questions can you inform me at
    Thanks in advance

    No, and you can't use a PreparedStatement where you have ? for the table name either. The database can't prepare it because it doesn't know what fields you will be asking for. So you will have to use a Statement and generate the SQL with string calculations. Sorry.

  • Printing out double quote string

    Hello,
    I would like to know how can i print out the double quote string (")
    in JSP using out.print(), because a double qoute has already used
    for indicating the string. If the string that i want to print out is including double quote("), how can i print that string out.
    THX !

    out.println("\"mystring\"");
    generally: backslash "\" is used in Java to quote special characters e.g. out.println("c:\\my documents\\bla");

  • SSRS Report Returning Double Quote string from a Single Quote String

    Hi, I'm getting weird thing in resultset from SSRS report when executed. When I pass parameter to a report, which passes String that has single quote value to a split function , it returns rows with double quote. 
    For example  following string:
    'N gage, Wash 'n Curl,Murray's, Don't-B-Bald
    Returns: 
    ''N gage, Wash ''n Curl,Murray''s, Don''t-B-Bald
    through SSRS report.
    Here is the split function Im using in a report.
    CREATE Function [dbo].[fnSplit] (
    @List varchar(8000), 
    @Delimiter char(1)
    Returns @Temp1 Table (
    ItemId int Identity(1, 1) NOT NULL PRIMARY KEY , 
    Item varchar(8000) NULL 
    As 
    Begin 
    Declare @item varchar(4000), 
    @iPos int 
    Set @Delimiter = ISNULL(@Delimiter, ';' ) 
    Set @List = RTrim(LTrim(@List)) 
    -- check for final delimiter 
    If Right( @List, 1 ) <> @Delimiter -- append final delimiter 
    Select @List = @List + @Delimiter -- get position of first element 
    Select @iPos = Charindex( @Delimiter, @List, 1 ) 
    While @iPos > 0 
    Begin 
    -- get item 
    Select @item = LTrim( RTrim( Substring( @List, 1, @iPos -1 ) ) ) 
    If @@ERROR <> 0 Break -- remove item form list 
    Select @List = Substring( @List, @iPos + 1, Len(@List) - @iPos + 1 ) 
    If @@ERROR <> 0 Break -- insert item 
    Insert @Temp1 Values( @item ) If @@ERROR <> 0 Break 
    -- get position pf next item 
    Select @iPos = Charindex( @Delimiter, @List, 1 ) 
    If @@ERROR <> 0 Break 
    End 
    Return 
    End
    FYI: I'm getting @List value from a table and passing it as a string to split function. 
    Any help would be appreciated!
    ZK

    Another user from TSQL forum posted this code which is returning the same resultset but when I execute both codes in SQL server it works and return single quote as expected.
    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/8d5c96f5-c498-4f43-b2fb-284b0e83b205/passing-string-which-has-single-quote-rowvalue-to-a-function-returns-double-quoate?forum=transactsql
    CREATE FUNCTION dbo.splitter(@string VARCHAR(MAX), @delim CHAR(1))
    RETURNS @result TABLE (id INT IDENTITY, value VARCHAR(MAX))
    AS
    BEGIN
    WHILE CHARINDEX(@delim,@string) > 0
    BEGIN
    INSERT INTO @result (value) VALUES (LEFT(@string,CHARINDEX(@delim,@string)-1))
    SET @string = RIGHT(@string,LEN(@string)-CHARINDEX(@delim,@string))
    END
    INSERT INTO @result (value) VALUES (@string)
    RETURN
    END
    GO
    ZK

  • How to use a single quote string in where condition

    Hi,
    I have one problem in building a query.
    SELECT agx_drug_indication.record_id, agx_drug_indication.fk_ad_rec_id,
    agx_drug_indication.drugindicationmeddraver, agx_drug.record_id,
    agx_drug.fk_apat_rec_id,
    REPLACE (agx_drug.medicinalproduct, '''', '''') AS "MEDICINALPRODUCT",
    pack_imp_objects.fn_get_arisg_code
    (147,
    agx_drug_indication.drugindicationmeddraver
    ) AS "DRUGINDICATIONMEDDRAVER",
    agx_drug.drugindication,
    NVL (agx_drug.drugcharacterization, 1) AS "DRUGCHARACTERIZATION",
    agx_safety_report.record_id, agx_safety_report.case_identifier_no,
    agx_safety_report.fk_apat_rec_id,
    pack_imp_objects.fn_meddra_llt_matching
    (agx_drug_indication.drugindication,
    agx_drug_indication.drugindication,
    agx_drug_indication.drugindicationmeddraver,
    1
    ) AS "LLT_CODE",
    pack_imp_objects.fn_meddra_soccode_matching
    (agx_drug_indication.drugindication,
    agx_drug_indication.drugindicationmeddraver
    ) AS "PRIMARY_SOC_CODE",
    pack_imp_objects.fn_meddra_soccode_matching
    (agx_drug_indication.drugindication,
    agx_drug_indication.drugindicationmeddraver
    ) AS "CASE_SOC_CODE",
    pack_imp_objects.fn_meddra_pt_matching
    (agx_drug_indication.drugindication,
    agx_drug_indication.drugindication,
    agx_drug_indication.drugindicationmeddraver
    ) AS "PT_CODE",
    pack_imp_objects.fn_get_aer_id (11) AS "AER_ID"
    FROM agx_drug_indication,
    agx_drug,
    agx_safety_report
    WHERE agx_drug_indication.fk_ad_rec_id = agx_drug.record_id
    AND agx_drug.fk_apat_rec_id = agx_safety_report.fk_apat_rec_id
    AND agx_safety_report.case_identifier_no IS NOT NULL
    AND agx_drug_indication.drugindication IS NOT NULL
    AND agx_drug.medicinalproduct =
    REPLACE ('*-qVAGX_DRUG.MEDICINALPRODUCT*', '''', '''')
    In the above query last line '-qVAGX_DRUG.MEDICINALPRODUCT' is a dynamic variable which may or may not contain the single quotes.
    Ex: ABC's or just ABC.
    The query has to support both single quote and without quote in it.
    I wanted everything to be done in the sinlq query on not a PL/SQL Block.
    Please help me ASAP

    kumar0828 wrote:
    <font color="#FF0000"> ... </font>
    REPLACE (agx_drug.medicinalproduct, '''', '''') AS "MEDICINALPRODUCT",
    <font color="#FF0000"> ... </font> <pre>
    REPLACE (agx_drug.medicinalproduct, '<font style="background-color: #E7FA6B">''</font>', '<font style="background-color: #E7FA6B">''</font>')
    </pre>
    With the above statement you are replacing single quote with another single quote
    (which is nonsense).
    <font color="#FF0000"> ... </font>
    AND agx_drug.medicinalproduct = REPLACE ('*-qVAGX_DRUG.MEDICINALPRODUCT*', '''', '''')
    In the above query last line '-qVAGX_DRUG.MEDICINALPRODUCT' is a dynamic variable which may or may not contain the single quotes.This is not a dynamic variable but a string value:
    <pre>
    AND agx_drug.medicinalproduct =
    REPLACE (<font style="background-color: #FF3D55">'*</font>-qVAGX_DRUG.MEDICINALPRODUCT<font style="background-color: #FF3D55">*'</font>, '<font style="background-color: #E7FA6B">''</font>', '<font style="background-color: #E7FA6B">''</font>')
    </pre>
    *-qVAGX_DRUG.MEDICINALPRODUCT* <pre>
    AND agx_drug.medicinalproduct =
    REPLACE (<font style="background-color: #FF3D55">q'*</font>-qVAGX_DRUG.MEDICINALPRODUCT<font style="background-color: #FF3D55">*'</font>, '<font style="background-color: #E7FA6B">''</font>', '<font style="background-color: #E7FA6B">''</font>')
    </pre>
    -qVAGX_DRUG.MEDICINALPRODUCT q'[a]' => a
    q'[a']' => a'
    q'[a'']' => a''
    q'*a*' => a
    q'*a'*' => a'
    q'*a''*' => a''
    A variable also cannot contain a dot (.):
    <pre>VAGX_DRUG<font style="background-color: #FF3D55">.</font>MEDICINALPRODUCT</pre>
    Ex: ABC's or just ABC.
    The query has to support both single quote and without quote in it.
    I wanted everything to be done in the sinlq query on not a PL/SQL Block.
    Please help me ASAPTry this:
    <pre>
    AND agx_drug.medicinalproduct = MY_VARIABLE
    </pre>

Maybe you are looking for