awk script to parse SQL from Pro*C program


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk script to parse SQL from Pro*C program
# 8  
Old 10-28-2013
Here is an awk approach based on some assumptions:
Code:
awk '
        {
                for ( i = 1; i <= NF; i++ )
                {
                        if ( $i == "FROM" )
                                F = 1
                        if ( ( F && $i ~ /SELECT/ ) || $i ~ /WHERE/ )
                                F = 0
                        if ( ( F && $i !~ /SELECT/ ) && $i !~ /FROM/ )
                        {
                                sub ( /,/, X, $i )
                                !T[$i]
                        }
                        if ( $i ~ /\./ )
                        {
                                split ( $i, A, "." )
                                TA[A[1]] = A[1]
                        }
                }
        }
        END {
                for ( k in T )
                {
                        if ( !(TA[k]) )
                                print k
                }
        }
' file.pc

# 9  
Old 10-29-2013
Thks! I will try it!
# 10  
Old 10-30-2013
Sorry, it didn't work. Smilie I thought it had to do with the fact that we're searching for "FROM" and "WHERE" clauses in uppercase so I added a
Code:
tr [:lower:] [:upper:]

before the AWK instruction, but still the wrong output.
# 11  
Old 10-30-2013
As I said earlier in my post, the code was based on some assumptions.

This is what I get with modified awk code:
Code:
awk '
        {
                for ( i = 1; i <= NF; i++ )
                {
                        if ( $i ~ /[Ff][Rr][Oo][Mm]/ )
                                F = 1
                        if ( ( F && $i ~ /[Ss][Ee][Ll][Ee][Cc][Tt]/ ) || $i ~ /[Ww][Hh][Ee][Rr][Ee]/ )
                                F = 0
                        if ( ( F && $i !~ /[Ss][Ee][Ll][Ee][Cc][Tt]/ ) && $i !~ /[Ff][Rr][Oo][Mm]/ )
                        {
                                sub ( /,/, X, $i )
                                !T[$i]
                        }
                        if ( $i ~ /\./ )
                        {
                                split ( $i, A, "." )
                                TA[A[1]] = A[1]
                        }
                }
        }
        END {
                for ( k in T )
                {
                        if ( !(TA[k]) )
                                print k
                }
        }
' file.pc

Input:
Code:
$ cat file.pc
EXEC SQL SELECT t1.field1, t1.field2
INTO :w_field
FROM TABLE1 t1, TABLE2 t2
WHERE t1.field1 = t2.field1
AND   t1.ID     = :wl_id;

EXEC SQL SELECT t3.field1, t4.field2
INTO :w_field
FROM TABLE3 t3, TABLE4 t4
WHERE t3.field1 = t4.field1
AND   t3.ID     = :wl_id;

EXEC SQL SELECT ID
INTO :twl_partition
FROM (SELECT (ROWNUM-1) ID FROM PERIODE WHERE ROWNUM  <= :wl_nb_partition)
WHERE :dlg_no_process = MOD(ID, :dlg_nb_process );

Output:
Code:
TABLE1
TABLE2
TABLE3
TABLE4
PERIODE

This User Gave Thanks to Yoda For This Post:
# 12  
Old 10-30-2013
I adapted it a little bit and it worked! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk Script to parse a XML tag

I have an XML tag like this: <property name="agent" value="/var/tmp/root/eclipse" /> Is there way using awk that i can get the value from the above tag. So the output should be: /var/tmp/root/eclipse Help will be appreciated. Regards, Adi (6 Replies)
Discussion started by: asirohi
6 Replies

2. Shell Programming and Scripting

AWK script to parse a data in a file

Hi Unix gurus.. I have a file which has below data, It has several MQ Queue statistics; QueueName= 'TEST1' CreateDate= '2009-10-30' CreateTime= '13.45.40' QueueType= Predefined QueueDefinitionType= Local QMinDepth= 0 QMaxDepth= 0 QueueName= 'TEST2' CreateDate= '2009-10-30'... (6 Replies)
Discussion started by: dd_psg
6 Replies

3. Programming

Sql Procedure in Pro C file

Hi, Can any one help me how to write a sql procedure in a pro *c file for selecting the data from a database and inserting the rows into a queue in a .pc file. thanx in advance. (1 Reply)
Discussion started by: jhon1257
1 Replies

4. Shell Programming and Scripting

script to parse text file into sql commands

Hello all, I tried searching for something similiar before posting but couldn't come up with anything that fit what I need. In Linux, I'm trying to parse through a number of files and take the info in them and put it into mysql. My file is a dump from an expect script: ---filename... (3 Replies)
Discussion started by: hamanjam
3 Replies

5. Programming

Do pro*c program need to recompile

hi, I have pro*c program running on sunsolaris 5.9.Currently the same program has been migrated to solaris 5.10.But the program is not giving the desired output.Do i need to recomplie the source code again. Regards, Megh (4 Replies)
Discussion started by: megh
4 Replies

6. Shell Programming and Scripting

awk script to parse results from TWO files

I am trying to parse two files and get data that does not match in one of the columns ( column 3 in my case ) Data for two files are as follows A.txt ===== abc 10 5 0 1 16 xyz 16 1 1 0 18 efg 30 8 0 2 40 ijk 22 2 0 1 25 B.txt ===== abc... (6 Replies)
Discussion started by: roger67
6 Replies

7. Programming

problem with sql command in pro*c

In a pro*C program, I use query follow: INSERT INTO radacct_wk SELECT (select psid from cscterminfo where cscterminfo.TELNO = username), nasipaddress, acctstarttime, acctstoptime, acctsessiontime, acctinputoctets, acctoutputoctets, acctterminatecause, framedipaddress FROM radacct@DBSV_B;... (7 Replies)
Discussion started by: quynhtrang
7 Replies

8. UNIX for Dummies Questions & Answers

PRo*C program for SQL queries using threading concept

Hi All, I have written 4 SQL queries. I want to write PRO*C program for this. I want to put these 4 queries in a single PR*C program using threading concept. Please guide me to write the pogram. the queries are as follows. 1. select * from head; 2. select * from details; 3. delete from head... (0 Replies)
Discussion started by: user71408
0 Replies

9. Shell Programming and Scripting

pro*c program for sql query

Hi all, I have sql query as follows. Please write a pro*c program for the following query. select sp1.cost_change ||','|| sp1.cost_change_desc ||','|| sp1.reason ||','|| to_char(sp1.active_date,'DD-MON-YYYY HH24:MI:SS') ||','|| sp1.status ||','|| sp1.cost_change_origin... (0 Replies)
Discussion started by: user71408
0 Replies
Login or Register to Ask a Question