Sponsored Content
Top Forums Shell Programming and Scripting Need inputs on UNIX script basics Post 302487445 by ustechie on Wednesday 12th of January 2011 02:13:47 PM
Old 01-12-2011
How to extract entire WHERE clause from a SQL using UNIX

Hi UNIX Gurus,

I have a SQL utility which fires DML statements against DB2 tables. Logic is to identify DML statements, put it into a file ($dml) and execute the job.

DML file can have more than 1 DML statements....but all of 1 type at a time.....either all UPDATE or all DELETE.

Job first check the count which is the records impacted by each DML statement. This was a pre-requisite condition.

So I used following code. It works fine for normal UPDATE/DELETE queries, but not fetching exact WHERE clause where we have in-queries.


Code:
sed 's/.*\([wW][hH][eE][rR][eE] .*$\)/\1/' $dml > $temp1 --> Selecting the WHERE clause of the DML mentioned in file $dml and put it in a temp file, temp1
sed "s/[wW][hH][eE][rR][eE]/select count(*) from $SCH.$TBL where/" $temp1 > $ddl --> use the WHERE clause mentioned in the temp file temp1 and creates SELECT COUNT(*) statement and put it in $ddl file
rm $temp1--> Remove temp file temp1


Example of DML statement for which I was executing it but it was not working correctly:

Code:
UPDATE 
<TABLE_NAME> 
SET 
<FIELD_NAME> = VALUE 
WHERE 
CONDITION_1 AND 
CONDITION_2 = (SELECT FIELD_NAME FROM TABLE_NAME WHERE CONDITION_XYZ);

P.S. - Format mentioned in above query is not fixed. It may be mentioned in 1 line or in multiple lines just like above. Also it can have more than 1 DML statement in input file.

Thanks in advance....
Beginner in UNIX

---------- Post updated at 02:13 PM ---------- Previous update was at 12:56 PM ----------

Is there anyone who can help me in resolving this?

Last edited by ustechie; 01-12-2011 at 04:07 PM..
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

UNIX Basics

I want to learn UNIX, but I have a few questions. If anybody could help me out I'd greatly appreciate it. First, I've decided I'm going to use Red Hat Linux and I've been told the only difference between 7.2 and the Professional (besides the price), is the tech support that you'll receive. Is... (2 Replies)
Discussion started by: paulSF
2 Replies

2. UNIX for Dummies Questions & Answers

Unix Basics

Hey, you said this forum was for Dummies, so don't blame me for the following! :D My whole "web building" life, I've had my sites hosted in one for or another. Lately, I've gotten into PHP and MySQL and, of course, those are also hosted for me. But lately, I've been thinking of using PHP and... (2 Replies)
Discussion started by: cap97
2 Replies

3. AIX

UNIX/AIX Performance Tuning = some basics please

Hi all, From Googling, I found that the basics used for troubleshooting UNIX/AIX performance issues are commands like vmstat, iostat and sar. I believe these are generic commands regardless of what UNIX flavour is in used, only difference being is the format of the output. In a real case... (2 Replies)
Discussion started by: newbie_01
2 Replies

4. Shell Programming and Scripting

Just started using UNIX, im at the basics and my scripts broken.

echo "Hi $username, guess what my favourite colour is!" count=0 while ] do read colour if then $count=1 echo "See ya later!" elif then $count=1 echo "You guessed correctly! Great job!"... (6 Replies)
Discussion started by: solomonsnare
6 Replies

5. UNIX for Dummies Questions & Answers

UNIX Basics

Hello, 1) I am trying to get involved in UNIX for educational purposes so I have installed the latest Ubuntu edition 12.04. Do you know another package that I could use it instead for educational purposes? 2)What is the difference between "~$" and "/$" (it comes with cd / and cd ~) .The... (1 Reply)
Discussion started by: Iwn
1 Replies

6. UNIX for Dummies Questions & Answers

How to send keyboard inputs toa UNIX command executed from a shell script?

I have a unix command that prompts for 'y'. How do I run this from my shell script? (4 Replies)
Discussion started by: Sree10
4 Replies

7. UNIX for Dummies Questions & Answers

UNIX basics

Hi, I am new to Unix. can you explain in brief with examples what is variable, what is argument and what is parameter? i searched a lot on other forums but not able to find a appropriate answer. thanks in advance!! (3 Replies)
Discussion started by: 21laps
3 Replies

8. UNIX for Dummies Questions & Answers

UNIX Basics about shell and editors and default settings

Hi all, I have 3-4 years of experience working on unix environment. I am not a beginner, but unix is not my primary skill set. I am very good at awk programming and doing many of my tasks very well, really very weak on basics. I moved to a new job recently and the settings there are driving me... (5 Replies)
Discussion started by: ysvsr1
5 Replies

9. UNIX for Beginners Questions & Answers

UNIX Shell Script to Remove MongoDB Document-Based on Many inputs

Here I am in a position to write a Unix Shell script(.sh) to remove MongoDB collection documents. I know how to remove based on a condition like below and it works for me. eval 'db.Collection.remove({TimeStamp:{$lte: "'$var'"}}) But I need to change the remove statement based on a new parameter... (1 Reply)
Discussion started by: senthilmadhanT
1 Replies
EXECUTE(7)                                                         SQL Commands                                                         EXECUTE(7)

NAME
EXECUTE - execute a prepared statement SYNOPSIS
EXECUTE name [ ( parameter [, ...] ) ] DESCRIPTION
EXECUTE is used to execute a previously prepared statement. Since prepared statements only exist for the duration of a session, the pre- pared statement must have been created by a PREPARE statement executed earlier in the current session. If the PREPARE statement that created the statement specified some parameters, a compatible set of parameters must be passed to the EXECUTE statement, or else an error is raised. Note that (unlike functions) prepared statements are not overloaded based on the type or number of their parameters; the name of a prepared statement must be unique within a database session. For more information on the creation and usage of prepared statements, see PREPARE [prepare(7)]. PARAMETERS
name The name of the prepared statement to execute. parameter The actual value of a parameter to the prepared statement. This must be an expression yielding a value that is compatible with the data type of this parameter, as was determined when the prepared statement was created. OUTPUTS
The command tag returned by EXECUTE is that of the prepared statement, and not EXECUTE. EXAMPLES
Examples are given in the Examples [prepare(7)] section of the PREPARE [prepare(7)] documentation. COMPATIBILITY
The SQL standard includes an EXECUTE statement, but it is only for use in embedded SQL. This version of the EXECUTE statement also uses a somewhat different syntax. SEE ALSO
DEALLOCATE [deallocate(7)], PREPARE [prepare(7)] SQL - Language Statements 2010-05-14 EXECUTE(7)
All times are GMT -4. The time now is 06:48 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy