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
# 1  
Old 10-28-2013
awk script to parse SQL from Pro*C program

Hello,

I have a Pro*C program which contains SQL sentences, such as:

Code:
....
Pro*C sentences 
....
/*SQL 1*/
EXEC SQL SELECT t1.field1, t1.field2
INTO :w_field
FROM TABLE1 t1, TABLE1 t2
WHERE t1.field1 = t2.field1
AND   t1.ID     = :wl_id;
....
Pro*C sentences 
....
/*SQL 1*/
EXEC SQL SELECT t3.field1, t4.field2
INTO :w_field
FROM TABLE1 t3, TABLE1 t4
WHERE t3.field1 = t4.field1
AND   t3.ID     = :wl_id;
....
Pro*C sentences 
....

and I would like to parse just the SELECT (this I know how), but get only the list of tables involved the queries.
Can anyone help me do that?
Thanks in advance.
Marina.

Last edited by Scott; 10-28-2013 at 02:52 PM.. Reason: Use code tags, please...
# 2  
Old 10-28-2013
Quote:
Originally Posted by mvalonso
Hello,

I have a Pro*C program which contains SQL sentences, such as:

....
Pro*C sentences
....
/*SQL 1*/
EXEC SQL SELECT t1.field1, t1.field2
INTO :w_field
FROM TABLE1 t1, TABLE1 t2
WHERE t1.field1 = t2.field1
AND t1.ID = :wl_id;
....
Pro*C sentences
....
/*SQL 1*/
EXEC SQL SELECT t3.field1, t4.field2
INTO :w_field
FROM TABLE1 t3, TABLE1 t4
WHERE t3.field1 = t4.field1
AND t3.ID = :wl_id;
....
Pro*C sentences
....

and I would like to parse just the SELECT (this I know how), but get only the list of tables involved the queries.
Can anyone help me do that?
Thanks in advance.
Marina.
After 22 posts you should know codetag. use code tag first and show o/p expected
# 3  
Old 10-28-2013
Code:
....
Pro*C sentences 
....
/*SQL 1*/
EXEC SQL SELECT t1.field1, t1.field2
INTO :w_field
FROM TABLE1 t1, TABLE1 t2
WHERE t1.field1 = t2.field1
AND t1.ID = :wl_id;
....
Pro*C sentences 
....
/*SQL 1*/
EXEC SQL SELECT t3.field1, t4.field2
INTO :w_field
FROM TABLE1 t3, TABLE1 t4
WHERE t3.field1 = t4.field1
AND t3.ID = :wl_id;
....
Pro*C sentences 
....

# 4  
Old 10-28-2013
Quote:
Originally Posted by mvalonso
Code:
....
Pro*C sentences 
....
/*SQL 1*/
EXEC SQL SELECT t1.field1, t1.field2
INTO :w_field
FROM TABLE1 t1, TABLE1 t2
WHERE t1.field1 = t2.field1
AND t1.ID = :wl_id;
....
Pro*C sentences 
....
/*SQL 1*/
EXEC SQL SELECT t3.field1, t4.field2
INTO :w_field
FROM TABLE1 t3, TABLE1 t4
WHERE t3.field1 = t4.field1
AND t3.ID = :wl_id;
....
Pro*C sentences 
....

How do you expect output ?
Code:
Table : t1 t3 t4 used

like this ?
# 5  
Old 10-28-2013
Just the name of the tables separated by , or any other delimiter or one table name per line in the output. No preference. Just want to know the tables involved without having to look deeply in the source program.
Thks.
# 6  
Old 10-28-2013
Quote:
Originally Posted by mvalonso
Just the name of the tables separated by , or any other delimiter or one table name per line in the output. No preference. Just want to know the tables involved without having to look deeply in the source program.
Thks.

You want field name also ??

show output sample for given input.
# 7  
Old 10-28-2013
Somthing like:

TABLE1, TABLE2, ...

or

TABLE1
TABLE2

just the names of the tables appearing in the FROM clause.
Thks.

---------- Post updated at 03:16 PM ---------- Previous update was at 03:12 PM ----------

But all the tables in all SELECT statements.
Please note that there can be SELECT without WHERE clause and there can also be some subselects like in:

Code:
	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 );

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