Sponsored Content
Top Forums Shell Programming and Scripting Convert Update statement into Insert statement in UNIX using awk, sed.... Post 302969364 by dev123 on Tuesday 22nd of March 2016 03:37:55 AM
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..
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
DRIZZLEDUMP(1)							      Drizzle							    DRIZZLEDUMP(1)

NAME
drizzledump - a database backup program SYNOPSIS
drizzledump [OPTIONS] database [tables] drizzledump [OPTIONS] --databases DB1 [DB2 DB3...] drizzledump [OPTIONS] --all-databases DESCRIPTION
drizzledump is used for backing up and restoring logical backups of a Drizzle database, as well as for migrating from a more traditional MySQL server. When connecting to a Drizzle server it will do a plain dump of the server. When connecting to a MySQL server, it will automatically detect this, and will convert the dump of the tables and data into a Drizzle compatible format. Any binary data in tables will be converted into hexadecimal output so that it does not corrupt the dump file. DRIZZLEDUMP OPTIONS
The drizzledump tool has several available options: --all-databases, -A Dumps all databases found on the server apart from information_schema and data_dictionary in Drizzle and information_schema, perfor- mance_schema and mysql in MySQL. --force, -f Continue even if a sql-error is received. --help Show a message with all the available options. --lock-all-tables, -x Locks all the tables for all databases with a global read lock. The lock is released automatically when drizzledump ends. Also turns on --single-transaction. --single-transaction Creates a consistent snapshot by dumping the tables in a single transaction. During the snapshot no other connected client should use any of the following as this will implicitly commit the transaction and prevent the consistency: ALTER TABLE DROP TABLE RENAME TABLE TRUNCATE TABLE Only works with InnoDB. --skip-opt A shortcut for --skip-drop-table, --skip-create, --skip-extended-insert and --skip-disable-keys --tables t1 t2 ... Dump a list of tables. --skip-drop-table Do not add a 'drop table' before each create. --show-progress-size rows (=10000) Show progress of the dump every rows of the dump. Requires --verbose --verbose, -v Sends various verbose information to stderr as the dump progresses. --skip-extended-insert Dump every row on an individual line. For example: INSERT INTO `t1` VALUES (1,'hello'); INSERT INTO `t1` VALUES (2,'world'); This is useful for calculating and storing diffs of dump files. --skip-dump-date Do not display the date/time at the end of the dump. --no-defaults Do not attempt to read configuration from configuration files. --add-drop-database Add DROP DATABASE statements before CREATE DATABASE. --compact Gives a more compact output by disabling header/footer comments and enabling --skip-disable-keys. --databases, -B Dump several databases. The databases do not need to follow on after this option, they can be anywhere in the command line. --skip-disable-keys, -K Do not dump the statements ALTER TABLE ... DISABLE KEYS and ALTER TABLE ... ENABLE KEYS --ignore-table table Do not dump specified table, needs to be in the format database.table. Can be specified multiple times for multiple tables. --insert-ignore Add the IGNORE keyword into every INSERT statement. --no-autocommit Make the dump of each table a single transaction by wrapping it in COMMIT statements. --no-create-db, -n Do not dump the CREATE DATABASE statements when using --all-databases or --databases. --skip-create, -t Do not dump the CREATE TABLE statements. --no-data, -d Do not dump the data itself. Used to dump the schemas only. --replace Use REPLACE INTO statements instead of INSERT INTO --destination-type type (=stdout) Destination of the data. stdout The default. Output to the command line database Connect to another database and pipe data to that. New in version Drizzle7: 2010-09-27 --destination-host hostname (=localhost) The hostname for the destination database. Requires --destination-type = database New in version Drizzle7: 2010-09-27 --destination-port port (=3306) The port number for the destination database. Requires --destination-type = database New in version Drizzle7: 2010-09-27 --destination-user username The username for the destinations database. Requires --destination-type = database New in version Drizzle7: 2010-09-27 --destination-password password The password for the destination database. Requires --destination-type = database New in version Drizzle7: 2010-09-27 --destination-database database The database for the destination database, for use when only dumping a single database. Requires --destination-type = database New in version Drizzle7: 2010-09-27 --my-data-is-mangled If your data is UTF8 but has been stored in a latin1 table using a latin1 connection then corruption is likely and drizzledump by default will retrieve mangled data. This is because MySQL will convert the data to UTF8 on the way out to drizzledump and you effectively get a double-conversion to UTF8. This typically happens with PHP apps that do not use SET NAMES. In these cases setting this option will retrieve the data as you see it in your application. New in version Drizzle7: 2011-01-31 --host, -h hostname (=localhost) The hostname of the database server. --user, -u username The username for the database server. --password, -P password The password for the database server. --port, -p port (=4427) The port number of the database server. --protocol protocol (=mysql) The protocol to use when connecting to the database server. Options are: mysql The standard MySQL protocol. drizzle The Drizzle protocol. BACKUPS USING DRIZZLEDUMP
Backups of a database can be made very simply by running the following: $ drizzledump --all-databases > dumpfile.sql This can then be re-imported into drizzle at a later date using: $ drizzle < dumpfile.sql MYSQL MIGRATION USING DRIZZLEDUMP
As of version 2010-09-27 there is the capability to migrate databases from MySQL to Drizzle using drizzledump. drizzledump will automatically detect whether it is talking to a MySQL or Drizzle database server. If it is connected to a MySQL server it will automatically convert all the structures and data into a Drizzle compatible format. Warning drizzledump will by default try to connect via. port 4427 so to connect to a MySQL server a port (such as 3306) must be specified. So, simply connecting to a MySQL server with drizzledump as follows will give you a Drizzle compatible output: $ drizzledump --all-databases --host=mysql-host --port=3306 --user=mysql-user --password > dumpfile.sql Additionally drizzledump can now dump from MySQL and import directly into a Drizzle server as follows: $ drizzledump --all-databases --host=mysql-host --port=3306 --user=mysql-user --password --destination-type=database --desination-host=drizzle-host Note Please take special note of old-passwords-label if you have connection issues from drizzledump to your MySQL server. Note If you find your VARCHAR and TEXT data does not look correct in a drizzledump output, it is likely that you have UTF8 data stored in a non-UTF8 table. In which case please check the --my-data-is-mangled option. When you migrate from MySQL to Drizzle, the following conversions are required: o MyISAM -> InnoDB o FullText -> drop it (with stderr warning) o int unsigned -> bigint o tinyint -> int o smallint -> int o mediumint -> int o tinytext -> text o mediumtext -> text o longtext -> text o tinyblob -> blob o mediumblob -> blob o longblob -> blob o year -> int o set -> text [1] o date/datetime default 0000-00-00 -> default NULL [2] o date/datetime NOT NULL columns -> NULL [2] o any date data containing 0000-00-00 -> NULL [2] o time -> int of the number of seconds [3] o enum-> DEFAULT NULL [4] FOOTNOTES
[1] There is currently no good alternative to SET, this is simply to preserve the data in the column. There is a new alternative to SET to be included at a later date. [2] Currently, ALL date columns have their DEFAULT set to NULL on migration. This is so that any rows with 0000-00-00 dates can convert to NULL. [3] This prevents data loss since MySQL's TIME data type has a range of -838:59:59 - 838:59:59, and Drizzle's TIME type has a range of 00:00:00 - 23:59:59. [4] This is so that empty entries such as '' will convert to NULL. AUTHOR
Andrew Hutchings COPYRIGHT
2010, Drizzle Developers 7 June 03, 2012 DRIZZLEDUMP(1)
All times are GMT -4. The time now is 01:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy