"parse" SQL in bash or ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting "parse" SQL in bash or ksh
# 1  
Old 05-05-2009
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Explaining behaviour of sudo bash "$0" "$@";

I've found this script part on the stackoverflow: if ; then sudo bash "$0" "$@"; exit "$?"; fi I realized that sudo bash "$0" "$@"; is the only needed for me. But the strange thing happens when I move this line outside the IF statement: sudo bash "$0" "$@"; stops the... (9 Replies)
Discussion started by: boqsc
9 Replies

3. UNIX for Dummies Questions & Answers

"Help with bash script" - "License Server and Patch Updates"

Hi All, I'm completely new to bash scripting and still learning my way through albeit vey slowly. I need to know where to insert my server names', my ip address numbers through out the script alas to no avail. I'm also searching on how to save .sh (bash shell) script properly.... (25 Replies)
Discussion started by: profileuser
25 Replies

4. Shell Programming and Scripting

Purpose of "read" and "$END$" in ksh ?

Hi, Could anyone please shed some light on the following script lines and what is it doing as it was written by an ex-administrator? cat $AMS/version|read a b verno d DBVer=$(/usr/bin/printf "%7s" $verno) I checked that the cat $AMS/version command returns following output: ... (10 Replies)
Discussion started by: dbadmin100
10 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Shell Programming and Scripting

What is the ksh equivalent to bash's "history -c" command?

Hi, What is the korn shell equivalent of bash shell's "history -c" command? I do know, how to clear the history list in ksh, I can do the following: > ~/.sh_historybut still, I am interested to know the single one line command as 'history -c' gives error on my ksh (1 Reply)
Discussion started by: royalibrahim
1 Replies

7. Shell Programming and Scripting

Simplify Bash Script Using "sed" Or "awk"

Input file: 2 aux003.net3.com error12 6 awn0117.net1.com error13 84 aux008 error14 29 aux001.ha.ux.isd.com error12 209 aux002.vm.ux.isd.com error34 21 alx0027.vm.net2.com error12 227 dux001.net5.com error123 22 us008.dot.net2.com error121 13 us009.net2.com error129Expected Output: 2... (4 Replies)
Discussion started by: sQew
4 Replies

8. HP-UX

script running with "ksh" dumping core but not with "sh"

Hi, I have small script written in korn shell. When it is called from different script, its dumping core, but no core dump when we run it standalone. And its not dumping core if we run the script using "/bin/sh" instead of "ksh" Can some body please help me how to resolve this issue. ... (9 Replies)
Discussion started by: simhe02
9 Replies

9. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

10. Shell Programming and Scripting

Exactly How can we define "sh ksh csh &bash"

Hi - I m prashant. I m new in UNIX&LINUX world. I want to ask that how can we define the shell in Linux like bash,ksh,csh in Linux. What is the use of these shells. I know there are mny experts on net if you can tell me then please do me this favour and tell me about this topic. ... (1 Reply)
Discussion started by: prashantsingh
1 Replies
Login or Register to Ask a Question