Parse a SQL select statement

Discussion in 'Java' started by james zhou, Feb 27, 2004.

  1. james zhou

    james zhou Guest

    Hi, in the project I am currently working on I need to parse a SQL
    SELECT statement so that I can get all the selected elements in the
    query. For example I need to parse the following stmt:
    Select SUBSTR(ACCT_USAGE_DETAIL_GUIDE_VIEW.C1,1,60) AS KEY,
    ACCT_USAGE_DETAIL_GUIDE_VIEW.BEGINTS,
    TO_CHAR(TO_DATE(BEGINTS, 'YYYYMMDDHH24MISS') - 30,
    'YYYYMMDDHH24MISS') AS XBEGINTS,
    ACCT_USAGE_DETAIL_GUIDE_VIEW.CCS_ACCOUNT,
    ACCT_USAGE_DETAIL_GUIDE_VIEW.REPORTING_NUMBER,
    ACCT_USAGE_DETAIL_GUIDE_VIEW.ENDTS,
    DECODE(ENDTS, '99999999999999', '99999999999999',
    TO_CHAR(TO_DATE(ENDTS, 'YYYYMMDDHH24MISS') + 30, 'YYYYMMDDHH24MISS'))
    AS XENDTS,
    ACCT_USAGE_DETAIL_GUIDE_VIEW.SYMBOLIC_CATALOG_ENTRY
    from ACCT_USAGE_DETAIL_GUIDE_VIEW
    where length(originating_number) = 10;

    In the above example, "SUBSTR(ACCT_USAGE_DETAIL_GUIDE_VIEW.C1,1,60) AS
    KEY" is the first element, and "ACCT_USAGE_DETAIL_GUIDE_VIEW.BEGINTS"
    is the second element, so on and so forth. Apparently I cant use comma
    as delimiter to break down the elements. Can anyone shed some lights
    on this?

    Thanks,
     
    james zhou, Feb 27, 2004
    #1
    1. Advertising

  2. james zhou wrote:
    >
    > Hi, in the project I am currently working on I need to parse a SQL
    > SELECT statement so that I can get all the selected elements in the
    > query. For example I need to parse the following stmt:
    >
    > ...
    >
    > In the above example, "SUBSTR(ACCT_USAGE_DETAIL_GUIDE_VIEW.C1,1,60) AS
    > KEY" is the first element, and "ACCT_USAGE_DETAIL_GUIDE_VIEW.BEGINTS"
    > is the second element, so on and so forth. Apparently I cant use comma
    > as delimiter to break down the elements. Can anyone shed some lights
    > on this?


    No problem. Elements in the list are separated by commas which are not enclosed in
    parentheses or quotes (single or double). This syntax is common to many languages.

    --
    Lee Fesperman, FirstSQL, Inc. (http://www.firstsql.com)
    ==============================================================
    * The Ultimate DBMS is here!
    * FirstSQL/J Object/Relational DBMS (http://www.firstsql.com)
     
    Lee Fesperman, Feb 28, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UGF1bA==?=

    trying to use fill method with SQL select statement

    =?Utf-8?B?UGF1bA==?=, Apr 28, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    449
    =?Utf-8?B?UGF1bA==?=
    Apr 29, 2004
  2. Kenneth Ljunggren
    Replies:
    0
    Views:
    937
    Kenneth Ljunggren
    May 18, 2005
  3. J. Muenchbourg

    Select TOP sql statement with date datatypes

    J. Muenchbourg, Sep 11, 2003, in forum: ASP General
    Replies:
    5
    Views:
    109
    Aaron Bertrand - MVP
    Sep 12, 2003
  4. Guy Hocking

    ASP / SQL Query - Conditional SELECT Statement

    Guy Hocking, Jan 21, 2004, in forum: ASP General
    Replies:
    7
    Views:
    204
    Bob Barrows
    Jan 21, 2004
  5. palmiere
    Replies:
    1
    Views:
    413
    Erwin Moller
    Feb 9, 2004
Loading...

Share This Page