Sponsored Content
Top Forums Shell Programming and Scripting Problem in passing IFS array to SQL Query Post 303025323 by yuvi on Tuesday 30th of October 2018 04:26:17 PM
Old 10-30-2018
Problem in passing IFS array to SQL Query

Hi,

I have created a shell script that reads line from text file and insert into DB table. I have used IFS to separate the line text. Looks IFS is splitting text properly but while passing one of the values that has special characters in it to query, it is giving weird issue. Below is my script looks like

Code:
IFS.OLD=$IFS
IFS='#'
while read line
do
read -r -A a <<< "$line"
echo "flag is- ${a[0]}"
if [ "${a[0]}" = "Flag" ];
then
echo "Header"
elif [ "${a[0]}" = "NU" ];
then
echo "User - Insert"
echo "company is- ${a[4]}"
sqlplus -s $DB_PATH  <<EOF
set head off feedback off
INSERT INTO USERS (EMAIL, FULL_NAME, CONTACT_PHONE_NUMBER,COMPANY, USER_ID) VALUES ( '${a[1]}', '${a[2]}','${a[3]}','${a[4]}',999527 );
commit;
exit;
EOF
fi

Below is my text file data
Code:
Flag#NEW#EMAIL#Name#Phno#Comp#***
NU#john@gmail.com#John Mathew#1122333#A&N Services, Inc.

when I run the script, output is coming as below

Code:
flag is- Flag
Header
flag is- NU
User - Insert
company is- A&N Services, Inc.
 Enter value for n: old   1: INSERT INTO USERS (EMAIL, FULL_NAME, CONTACT_PHONE_NUMBER,COMPANY, USER_ID) VALUES ( 'john@gmail.com', 'John Mathew','1122333','A&N Services, Inc.',999527 )
 new   1: INSERT INTO USERS (EMAIL, FULL_NAME, CONTACT_PHONE_NUMBER,COMPANY, USER_ID) VALUES ( 'john@gmail.com', 'John Mathew','1122333','Acommit; Services, Inc.',999527 )

I really do not understand why it is showing output like this but I investigated and found that this issue is coming due to the parameter COMPANY in the query. It has special characters. If I remove and change to simple text then it is not giving this issue and record is inserting successfully. Please suggest if any solution.

Last edited by vgersh99; 10-30-2018 at 05:29 PM.. Reason: Code tags, please!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

problem with IFS

hi, :) I set IFS=":" But when i try to echo $IFS,i am not getting any thing on the screen escept a blank line. any help pls. cheers RRK (11 Replies)
Discussion started by: ravi raj kumar
11 Replies

2. Shell Programming and Scripting

Problem while storing sql query value in a variable

Hi, When i execute the below statement , the value is not getting stored in the variable. AnneeExercice=`sqlplus $LOGSQL/$PASSWORDSQL << FIN >> $GEMOLOG/gemo_reprev_reel_data_ventil_$filiale.trc SELECT bi09exercice FROM bi09_scenario WHERE bi09idfiliale=UPPER('de') AND ... (1 Reply)
Discussion started by: krishna_gnv
1 Replies

3. Shell Programming and Scripting

Problem in Passing sql query for a script

Unix prompt ========= echo "Enter the query" read q ========== User has entered : SELECT * FROM employee ===================== Now the problem starts.. echo $q Output: SELECT "all files names in the PWD" FROM employee ================================================ ... (5 Replies)
Discussion started by: Niroj
5 Replies

4. Shell Programming and Scripting

sql query problem

Hi, I am passing an argument for the script and that argument values should exist in database. bill_period_input="'""$1""'" bill_period=`sqlplus uname/pwd@dbname <<eof! set verify off set heading off set feedback off select bill_period from bill_period_ref where... (4 Replies)
Discussion started by: ss_ss
4 Replies

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

6. UNIX for Advanced & Expert Users

Passing Hash variable in to sql query in perl

Hi Everyone, Can anyone help me how do i call hash variable in to sql query in perl. Please see the script below i have defined two Hash %lc and %tab as below $lc{'REFF'}='V_RES_CLASS'; $lc{'CALE'}='V_CAP_CLASS'; $lc{'XRPD'}='V_XFMR_CLASS'; $tab{'V_RES_CLASS'}='V_MFR_SERS';... (6 Replies)
Discussion started by: jam_prasanna
6 Replies

7. Shell Programming and Scripting

problem in SQL query

I used the following code code select * from tablename where columnname Instead of printing the expected output it prints all the files in the present directory since there is a "*" in the code. Is there any way to overcome the problem? Thanks Ananth (2 Replies)
Discussion started by: Ananthdoss
2 Replies

8. Shell Programming and Scripting

Problem in formatting output of SQL query in excel sheet in shell script

Hi Guys.. Need your help to format the output of my shell script. I am using spool command to take out put in csv file. below is my code. (for example) col USERNAME for a15 col EMAIL for a30 col FULL_NAME for a20 col LAST_LOGIN for a40 col DATE_CREATED for a40 SPOOL 120.csv... (3 Replies)
Discussion started by: Agupte
3 Replies

9. Shell Programming and Scripting

Run SQL thru shell script: how to get a new line when run sql query?

Hi, this's Pom. I'm quite a new one for shell script but I have to do sql on shell script to query some information from database. I found a concern to get a new line...When I run my script, it retrieves all data as wondering but it's shown in one line :( What should I do? I'm not sure that... (2 Replies)
Discussion started by: Kapom
2 Replies

10. Shell Programming and Scripting

Taking information from a postgres sql query and putting it into a shell script array

I have a postgres sql statement that is the following: select age from students; which gives me the entries: Age --- 10 15 13 12 9 14 10 which is about 7 rows of data. Now what I would like to do with this is use a shell script to create an array age. As a results... (3 Replies)
Discussion started by: JSNY
3 Replies
Data::Phrasebook::SQL::Query(3pm)			User Contributed Perl Documentation			 Data::Phrasebook::SQL::Query(3pm)

NAME
Data::Phrasebook::SQL::Query - Query Extension to the SQL/DBI Phrasebook Model. SYNOPSIS
my $q = $book->query( 'find_author' ); my $q = $book->query( 'find_author', 'Dictionary' ); DESCRIPTION
An extension to the SQL class to specifically handle the DBI interface for each query requested. CONSTRUCTOR
new Not to be accessed directly, but via the parent Data::Phrasebook, by specifying the class as SQL. METHODS
sql Get/set the current "sql" statement, in a form suitable for passing straight to DBI. sth Get/set the current statement handle. args Return list of arguments that will be used as bind parameters to any placeholders. Any given arguments will replace the whole list. Returns list in list context, arrayref in scalar. order As for "args", but regarding the corresponding list of argument names. The assorted "order_XXX" methods are supported as for "args_XXX". dbh Get/set the database handle. PREPARATION
/ EXECUTING METHODS execute Executes the query. Returns the result of "DBI::execute". Any arguments are given to "order_args" with the return of that method being used as arguments to "DBI::execute". If no arguments, uses those already specified. Calls "prepare" if necessary. order_args Given a hash or hashref of keyword to value mappings, organises an array of arguments suitable for use as bind parameters in the order needed by the query itself. prepare Prepares the query for execution. This method is called implicitly in most cases so you generally don't need to know about it. rebind Rebinds any bound values. Lets one pass a scalar reference in the arguments to "order_args" and have the bound value update if the original scalar changes. This method is not needed externally to this class. DELEGATED METHODS
Any method not mentioned above is given to the statement handle. All these delegations will implicitly call "prepare". SEE ALSO
Data::Phrasebook, Data::Phrasebook::SQL. SUPPORT
Please see the README file. AUTHOR
Original author: Iain Campbell Truskett (16.07.1979 - 29.12.2003) Maintainer: Barbie <barbie@cpan.org> since January 2004. for Miss Barbell Productions <http://www.missbarbell.co.uk>. COPYRIGHT AND LICENSE
Copyright (C) 2003 Iain Truskett. Copyright (C) 2004-2010 Barbie for Miss Barbell Productions. This module is free software; you can redistribute it and/or modify it under the Artistic Licence v2. perl v5.10.1 2010-08-31 Data::Phrasebook::SQL::Query(3pm)
All times are GMT -4. The time now is 01:16 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy