Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2003
    Posts
    38

    Post Unanswered: Inserting record in Db2 along with single quote

    Hi,

    I have following sql statement in Oracle where the values are inserted along with single quote i.e 'T' or 'F' instead of T or F . Eg:

    INSERT INTO CLASSIFIERPROPERTY ( CLASSIFIERPROPERTYID, SHOWATTRIBUTES, MODELID, SHOWOPERATIONS,
    SUPPRESSATTRIBUTES, SUPPRESSOPERATIONS, SHOWVISIBILITY, SHOWOPERATIONSIGNATURE,
    ) VALUES ( 71, ''T'','|| p_uname || ' , ''T'', ''F'', ''F'', ''F'' );

    I tried to insert the same record in Db2 by putting 'F' or 'T' within double quote as "'T'" like :

    INSERT INTO CLASSIFIERPROPERTY ( CLASSIFIERPROPERTYID, SHOWATTRIBUTES, MODELID, SHOWOPERATIONS,
    SUPPRESSATTRIBUTES, SUPPRESSOPERATIONS, SHOWVISIBILITY,
    ) VALUES ( 71, "'T'","'"|| p_uname || "'" , "'T'", "'F'", "'F'", "'F'");

    But it gave me the following error :

    ADMINISTRATOR.SP_DEFAULTDATA: 45: [IBM][CLI Driver][DB2/NT] SQL0206N "'T'" is not valid in the context where it is used. LINE NUMBER=45. SQLSTATE=42703


    Can u please help.

    Thanks
    Raj Shekhar

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1

    Re: Inserting record in Db2 along with single quote

    Originally posted by Raj Shekhar
    Hi,

    I have following sql statement in Oracle where the values are inserted along with single quote i.e 'T' or 'F' instead of T or F . Eg:

    ...

    I tried to insert the same record in Db2 by putting 'F' or 'T' within double quote as "'T'" like :

    In DB2 string constants are enclosed in single quotes, not in double quotes; that's why your attempt at using double quotes fails. To use a string containing single quotation mark characters duplicate these characters. That is, to insert your string, 'T', use the following construct:

    INSERT INTO ... (SHOWATTRIBUTES) VALUES ('''T''');

    Note: ''' above is three single quotes in a row

  3. #3
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    Try this:

    INSERT INTO CLASSIFIERPROPERTY ( CLASSIFIERPROPERTYID, SHOWATTRIBUTES, MODELID, SHOWOPERATIONS,
    SUPPRESSATTRIBUTES, SUPPRESSOPERATIONS, SHOWVISIBILITY, SHOWOPERATIONSIGNATURE,
    ) VALUES ( 71, '''T''','|| p_uname || ' , '''T''', '''F''', '''F''', '''F''' );

    Those are 3 separate single quotes.

    Andy

  4. #4
    Join Date
    Jun 2003
    Posts
    38

    Thumbs up Re: Inserting record in Db2 along with single quote

    Originally posted by n_i
    In DB2 string constants are enclosed in single quotes, not in double quotes; that's why your attempt at using double quotes fails. To use a string containing single quotation mark characters duplicate these characters. That is, to insert your string, 'T', use the following construct:

    INSERT INTO ... (SHOWATTRIBUTES) VALUES ('''T''');

    Note: ''' above is three single quotes in a row

    Thanks. It worked.
    Raj Shekhar

  5. #5
    Join Date
    Jun 2003
    Posts
    38

    Re: Inserting record in Db2 along with single quote

    Originally posted by n_i
    In DB2 string constants are enclosed in single quotes, not in double quotes; that's why your attempt at using double quotes fails. To use a string containing single quotation mark characters duplicate these characters. That is, to insert your string, 'T', use the following construct:

    INSERT INTO ... (SHOWATTRIBUTES) VALUES ('''T''');

    Note: ''' above is three single quotes in a row
    Thanks. It worked.
    Raj Shekhar

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •