How to extract WHERE clause from a SQL using UNIX???


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to extract WHERE clause from a SQL using UNIX???
# 15  
Old 01-12-2011
A delete statement would be easier, as the syntax is much the same as the select statement:

Code:
sed "s/^DELETE/SELECT COUNT(1)/" file.sql

Where does your DML come from? Wouldn't it be better to have whatever generates that, generate a separate script to do the select count(1) stuff too - instead of this hacky stuff?
# 16  
Old 01-12-2011
First of all thanks a lot......!!!
you came like a savior.....

there is a separate script which checks the count.....I implemented simple extraction of WHERE clause and creation of SELECT COUNT(*) statements but it is not working for complex statements.....

let me try the logic you suggested to create SELECT COUNT(*) statements for DELETE statements

---------- Post updated at 07:39 PM ---------- Previous update was at 07:04 PM ----------

it is working for DELETE too....
thanks Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] Using AWK to extract SQL result

I just wish to extract the result onli... but I dont which edit to perform to start from (**) :wall: Current display result SQL*Plus: Release 10.2.0.1.0 - Production on Mon Sep 24 14:14:49 2012 Copyright (c) 1982, 2005, Oracle. All rights reserved. Connected to: Oracle Database 10g... (4 Replies)
Discussion started by: ment0smintz
4 Replies

2. Shell Programming and Scripting

How to extract the sql from file?

Hi Firends I have this type of file Rows read = 4823832 Statement text = SELECT QUEUE, REPLY_QUEUE, REPLY_QMGR FROM HUB_REF.CORNERSTONE.HUB_REF_QUEUE AS RQ WHERE (RQ.SERVICE_NAME = 'modifyParty' OR RQ.SERVICE_NAME = '*') AND RQ.SERVICE_TYPE =... (1 Reply)
Discussion started by: atul9806
1 Replies

3. Shell Programming and Scripting

Extract text from a SQL Script

Hi All, I want to extact text which start with "Group" case insenstive and end with ";" and in between there should be "partition"(case insenstive) . I write a script, but that script also giving me FILE2.txt and file3.txt as outputs. I shouldn't get anything from file2 and file3. Beacuse... (1 Reply)
Discussion started by: molakal9
1 Replies

4. Shell Programming and Scripting

How to grep the where clause of a SQL?

Hi UNIX Gurus, I want to use extract the where clause of a SQL present in a file. Please suggest me how can I do it. Select * from emp where emp_id>10; cat <file_name> | grep -i "where" returns whole SQL. how can I extract only "where emp_id>10;" Thanks in advance (4 Replies)
Discussion started by: ustechie
4 Replies

5. UNIX for Advanced & Expert Users

Extract Oracle DB Connect and SQL execution log

Hi, I am trying to write a generic script as a part of a framework which will establish Oracle DB connection once and loops in to check for some files which gives the SQL statements to execute. The script is running but I am stuck with capturing errors ( ORA and SP) and outputs. Example: ... (4 Replies)
Discussion started by: mirage0809
4 Replies

6. Shell Programming and Scripting

How to use sql data file in unix csv file as input to an sql query from shell

Hi , I used the below script to get the sql data into csv file using unix scripting. I m getting the output into an output file but the output file is not displayed in a separe columns . #!/bin/ksh export FILE_PATH=/maav/home/xyz/abc/ rm $FILE_PATH/sample.csv sqlplus -s... (2 Replies)
Discussion started by: Nareshp
2 Replies

7. Shell Programming and Scripting

Dynamic SQL for where clause

Hi, I have an app which user can query the database based on 4 criteria, that is Field1, Field2, Field3 and Field4 Mya I know how to write a dynamic SQL where I can choose to retrieve data based on their selected value. eg. where Field1=AAA eg. where Field1=AAA and Field2=BBB eg.... (1 Reply)
Discussion started by: TeSP
1 Replies

8. UNIX for Dummies Questions & Answers

Execute PL/SQL function from Unix script (.sql file)

Hi guys, I am new on here, I have a function in oracle that returns a specific value: create or replace PACKAGE BODY "CTC_ASDGET_SCHED" AS FUNCTION FN_ASDSCHEDULE_GET RETURN VARCHAR2 AS BEGIN DECLARE ASDSchedule varchar2(6); ASDComplete... (1 Reply)
Discussion started by: reptile
1 Replies

9. Shell Programming and Scripting

unix variables from sql / pl/sql

How do I dynamically assign the below output to unix shell variables so I can build a menu in a shell script? Example: var1 = 1 var2= SYSTEM var3 = 2 var4= UNDOTBS1 and so on, then in the shell script I can use the variables to build a menu. set serveroutput on declare... (2 Replies)
Discussion started by: djehres
2 Replies

10. Shell Programming and Scripting

Need to extract .sql files

Hi, I am trying to extract all .sql files present in a particular directory and its sub directories. How can i do this using shell script or awk? any help would be earnestly appreciated. thanks. (1 Reply)
Discussion started by: sprinleo
1 Replies
Login or Register to Ask a Question