Find the answer to your Linux question:
Results 1 to 2 of 2
Hi! I've a text file programme1.out : Code: CONNECT TO ORACLE (&CONXORA); CREATE TABLE TABLE1 AS SELECT ID_PERS FROM CONNECTION TO ORACLE ( SELECT DISTINCT PERS.ID_PERS FROM TAB_GRP GRP , ...
  1. #1
    Just Joined!
    Join Date
    May 2009
    Posts
    1

    Question "Parse" SQL in bash or ksh

    Hi!

    I've a text file programme1.out :

    Code:
    CONNECT TO ORACLE (&CONXORA);
    
    CREATE TABLE TABLE1 AS
        SELECT  ID_PERS
    
            FROM CONNECTION TO ORACLE
            (
            SELECT  DISTINCT PERS.ID_PERS
    
            FROM TAB_GRP GRP , TAB_PERS PERS
    
            WHERE DATE_DEB_GRP <= &DATE_QUOTE
                  AND (DATE_FIN_GRP IS NULL OR DATE_FIN_GRP > &DATE_QUOTE)
                  AND PERS.ID_PERS = GRP.ID_PERS
                  AND (PERS.DATE_SUPP_SI IS NULL OR PERS.DATE_SUPP_SI > &DATE_QUOTE)
    ORDER BY ID_PERS
    );
    DISCONNECT FROM ORACLE;
    CONNECT TO ORACLE (&CONXORA);
    
    CREATE TABLE TABLE2 AS
      SELECT    ID_PERS,
                ID_PRODUIT,
                CODE_PRODUIT,
                TOP_1
                TOP_2
                    
        FROM CONNECTION TO ORACLE
        (
            SELECT ID_PERS,
                   ID_PRODUIT,
                    CODE_PRODUIT,
                    MAX (CASE WHEN (CODE ='01' ) THEN 1 ELSE 0 END) AS TOP_1
                    MAX (CASE WHEN (CODE='02' ) THEN 1 ELSE 0 END) AS TOP_2
            FROM TABLE_FROM1
            WHERE  CODE IN ('01','02')
            AND    ID_MOIS <= &ID_MOIS
            GROUP BY ID_PERS,ID_PRODUIT
        );
    DISCONNECT FROM ORACLE;
    For each query (between connect to oracle and disconnect from oracle), I have to display the name of the create table, the name of tables used (real name of the table) and the name of the columns in the SELECT.

    At the end, I would like an output like this : table_create ; table_from ; column_name

    Example :

    table1;tab_grp;
    table1;tab_pers;ID_PERS
    table2;table_from1;ID_PRODUIT
    table2;table_from1;CODE_PRODUIT
    table2;table_from1;TOP_1
    table2;table_from1;TOP_2

    Is it possible to do this easily with a script in ksh or bash (UNIX AIX IBM)? (with sed, awk..)

    Regards

  2. #2
    tpl
    tpl is offline
    Linux User
    Join Date
    Jan 2007
    Location
    cleveland
    Posts
    452
    welcome to the forum

    can you show the output from that Oracle macro?
    then perhaps we can help you convert that output into
    your desired final form
    the sun is new every day (heraclitus)

Posting Permissions

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