Convert Update statement into Insert statement in UNIX using awk, sed....


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Convert Update statement into Insert statement in UNIX using awk, sed....
# 1  
Old 03-22-2016
Hammer & Screwdriver Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks,

I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex.

I have a bunch of update statements with all columns in a file which I need to convert into insert statements.

UPDATE TABLE_A SET COL1=1 WHERE COL2 is NULL AND COL2=3;

OUTPUT Should be:

INSERT INTO TABLE_A (COL1,COL2,COL3) VALUES (1,NULL,3);

Many Thanks.

Last edited by dev123; 03-22-2016 at 12:07 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk statement piped inside sed

Hello folks, I have multiple occurrences of the pattern: ).: where is any digit, in various text context but the pattern is unique as this regex. And I need to turn this decimal fraction into an integer (corresponding percent value: the range of 0-100). What I'm doing is: cat... (1 Reply)
Discussion started by: roussine
1 Replies

2. Shell Programming and Scripting

sed within awk statement

input | Jan 8 2018 11:28PM| 24 | 75 | 51 | 1 | 1.600| | Jan 8 2018 12:01PM| 52 | 823 | 21 | 6 | 2.675| desired output Jan-8-2018-11:28PM 24 75 51 1 1.600 Jan-8-2018-12:01PM 52 823 21 6 2.675 Dear friends, I have input file , as shown above and... (10 Replies)
Discussion started by: sagar_1986
10 Replies

3. Shell Programming and Scripting

Single quotes insert statement using awk

Hi, Need help, using awk command to insert statement awk -v q="'" '{ print "db2 connect to repolab > /dev/null; " "\n" "db2 -x \" select name from IBMPDQ.PROFILE where managed_database = " q $1"_"$3"__0" q "\"" } ' profile.txt | sh - | awk -v i="'" ' { print "db2 connect to repolab >... (1 Reply)
Discussion started by: Mathew_paul
1 Replies

4. Shell Programming and Scripting

Can we convert 3 awk statements in a single statement

Hi, Can we use 3 statements convert in a single statement. First statement output using the second statement and the second statement output using the third statement please let me know the syntax so that I can able to merge all the three statement. (2 Replies)
Discussion started by: Priti2277
2 Replies

5. Shell Programming and Scripting

Awk/sed problem to write Db insertion statement

Hi There, I am trying to load data from a csv file into a DB during our DB migration phase. I am successfully able export all data into a .csv file but those have to rewritten in terms insert statement which will allow for further population of same data in different DB My exiting csv record... (6 Replies)
Discussion started by: bhaskar_m
6 Replies

6. Shell Programming and Scripting

Use awk/sed/grep with goto statement!

Hi, I have an array with characters and I am looking for specific character in that array and if those specific character not found than I use goto statment which is define somehwhere in the script. My code is: set a = (A B C D E F) @ i = 0 while ($i <= ${#a}) if ($a != "F" || $a != "D")... (3 Replies)
Discussion started by: dixits
3 Replies

7. Shell Programming and Scripting

How is use sselect statement o/p in insert statement.

Hi All, I am using Unix ksh script. I need to insert values to a table using the o/p from a slelect statement. Can anybody Help! My script looks like tihs. ---`sqlplus -s username/password@SID << EOF set heading off set feedback off set pages 0 insert into ${TB_NAME}_D... (2 Replies)
Discussion started by: nkosaraju
2 Replies

8. Shell Programming and Scripting

How to convert unix command into Awk statement

Hi all, How can i use the below unix command in AWK . Can any one please suggest me how i can use. sed -e "s/which first.sh/which \$0/g" $shell > $shell.sal where $0=current program name(say current.sh) $shell=second.sh (1 Reply)
Discussion started by: krishna_gnv
1 Replies

9. Shell Programming and Scripting

(sed) parsing insert statement column that crosses multiple lines

I have a file with a set of insert statements some of which have a single column value that crosses multiple lines causing the statement to fail in sql*plue. Can someone help me with a sed script to replace the new lines with chr(10)? here is an example: insert into mytable(id, field1, field2)... (3 Replies)
Discussion started by: jjordan
3 Replies

10. Shell Programming and Scripting

awk command for INSERT statement

Hi, I sometimes bulk upload data in oracle. The problem is that I sometimes get an INSERT statemnt like this: INSERT INTO ALL_USER_HOTSPOT_DETAILS (USR_LOGIN,USR_LASTNAME,USR_FIRSTNAME,USR_EMAIL, PROPERTYNR) VALUES ('SABRDAG','D'AGOS','SABRINA','sabrina_d'agos@sheraton.com',70) I... (4 Replies)
Discussion started by: nattynatty
4 Replies
Login or Register to Ask a Question
DB2_PREPARE(3)								 1							    DB2_PREPARE(3)

db2_prepare - Prepares an SQL statement to be executed

SYNOPSIS
resource db2_prepare (resource $connection, string $statement, [array $options]) DESCRIPTION
db2_prepare(3) creates a prepared SQL statement which can include 0 or more parameter markers ( ? characters) representing parameters for input, output, or input/output. You can pass parameters to the prepared statement using db2_bind_param(3), or for input values only, as an array passed to db2_execute(3). There are three main advantages to using prepared statements in your application: o Performance: when you prepare a statement, the database server creates an optimized access plan for retrieving data with that statement. Subsequently issuing the prepared statement with db2_execute(3) enables the statements to reuse that access plan and avoids the overhead of dynamically creating a new access plan for every statement you issue. o Security: when you prepare a statement, you can include parameter markers for input values. When you execute a prepared statement with input values for placeholders, the database server checks each input value to ensure that the type matches the column defini- tion or parameter definition. o Advanced functionality: Parameter markers not only enable you to pass input values to prepared SQL statements, they also enable you to retrieve OUT and INOUT parameters from stored procedures using db2_bind_param(3). PARAMETERS
o $connection - A valid database connection resource variable as returned from db2_connect(3) or db2_pconnect(3). o $statement - An SQL statement, optionally containing one or more parameter markers.. o $options - An associative array containing statement options. You can use this parameter to request a scrollable cursor on database servers that support this functionality. For a description of valid statement options, see db2_set_option(3). RETURN VALUES
Returns a statement resource if the SQL statement was successfully parsed and prepared by the database server. Returns FALSE if the data- base server returned an error. You can determine which error was returned by calling db2_stmt_error(3) or db2_stmt_errormsg(3). EXAMPLES
Example #1 Preparing and executing an SQL statement with parameter markers The following example prepares an INSERT statement that accepts four parameter markers, then iterates over an array of arrays con- taining the input values to be passed to db2_execute(3). <?php $animals = array( array(0, 'cat', 'Pook', 3.2), array(1, 'dog', 'Peaches', 12.3), array(2, 'horse', 'Smarty', 350.0), ); $insert = 'INSERT INTO animals (id, breed, name, weight) VALUES (?, ?, ?, ?)'; $stmt = db2_prepare($conn, $insert); if ($stmt) { foreach ($animals as $animal) { $result = db2_execute($stmt, $animal); } } ?> SEE ALSO
db2_bind_param(3), db2_execute(3), db2_stmt_error(3), db2_stmt_errormsg(3). PHP Documentation Group DB2_PREPARE(3)