Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2009
    Posts
    15

    Unanswered: Find Strings which Contain Double Quotes

    I need help with db2 sql syntax that uses posstr to find string taht contain double quotes. The following gives syntax error.

    testconnString = "Select * From amflib1.itemasa Where posstr(itdsc, '""') > 0"

  2. #2
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    Strings in DB2 sould enclosed with single quotations.

    Please try ...
    testconnString = 'Select * From amflib1.itemasa Where posstr(itdsc, ''"'') > 0'

  3. #3
    Join Date
    Aug 2009
    Posts
    15
    Still get syntax error

  4. #4
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    What was the exact error message(s)?

    You might want to assign a string to a variable testconnString. But it is not meet a syntax of DB2 SQL.

    DB2 syntax is
    Code:
    Syntax
    
    >>-SET---------------------------------------------------------->
    
         .-,------------------------------------------------------------------.     
         V                                                                    |     
    >--+---+-| target-variable |--=--+-expression-+-------------------------+-+-+-><
       |   |                         +-NULL-------+                         |   |   
       |   |                         '-DEFAULT----'                         |   |   
       |   |    .-,-------------------.             .-,--------------.      |   |   
       |   |    V                     |             V                |      |   |   
       |   '-(----| target-variable |-+--)--=--+-(----+-expression-+-+--)-+-'   |   
       |                                       |      +-NULL-------+      |     |   
       |                                       |      '-DEFAULT----'      |     |   
       |                                       '-(--row-fullselect--)-----'     |   
       +-boolean-variable-name--=--+-search-condition-+-------------------------+   
       |                           +-TRUE-------------+                         |   
       |                           +-FALSE------------+                         |   
       |                           '-NULL-------------'                         |   
       +-array-variable-name--[--array-index--]--=--+-expression-+--------------+   
       |                                            '-NULL-------'              |   
       +-target-cursor-variable--=--+-cursor-variable-name---------+------------+   
       |                            +-| cursor-value-constructor |-+            |   
       |                            '-NULL-------------------------'            |   
       |                                  .-,--------------.                    |   
       |                                  V                |                    |   
       '-| target-row-variable |--=--+-(----+-expression-+-+--)-+---------------'   
                                     |      '-NULL-------'      |                   
                                     +-(--row-fullselect--)-----+                   
                                     +-row-expression-----------+                   
                                     '-NULL---------------------'
    See more detailes in
    SET variable - IBM DB2 9.7 for Linux, UNIX, and Windows

  5. #5
    Join Date
    Nov 2011
    Posts
    334
    Maybe you can use chr() function to do this

    testconnString = "Select * From amflib1.itemasa Where posstr(itdsc, chr(34)) > 0"

  6. #6
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    SDyke,

    Is the code in op extracted from other than an SQL routine(compound SQL, SQL function, or SQL procedure, so on)?

    If so, I want to recommend you
    to extract the select statement from your program and execute it independently,
    and see exact error code/error text of the error message(s) you received.

Posting Permissions

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