Sponsored Content
Full Discussion: Using unix array in sql
Top Forums Shell Programming and Scripting Using unix array in sql Post 302660859 by Mukta on Sunday 24th of June 2012 03:11:07 AM
Old 06-24-2012
Using unix array in sql

Hi all,

I have declared an array in unix as below.
Code:
 #!/bin/ksh
arr=()
for i in {0..4}
do
    arr[i]=$i;
done

.

i want to insert these array variables into the oracle table.can you guys please help me in doing this. my code is as below.
Code:
value=`sqlplus -s fos/fos << EOF

begin
for j in 0..4 loop
insert into test values ('${arr[j]}');
end loop;
end;
/
exit;
EOF`

its inserting 5 rows with value 4.
but it should insert
Code:
 0
1
2
3
4

.

Moderator's Comments:
Mod Comment edit by bakunin: Please view this code tag video for how to use code tags when posting code and data. Why you consistently used "[" and "]" instead of the tags eludes me.


---------- Post updated 06-24-12 at 02:11 AM ---------- Previous update was 06-23-12 at 12:41 PM ----------

hi guys,
please help me i need it badly.

Last edited by bakunin; 06-23-2012 at 03:43 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

sql variable as array index

hi folks i am facing problom while trying to access sql variable as array index ina unix shell script....script goes as below.. #!/bin/ksh MAX=3 for elem in alpha beeta gaama do arr=$elem ((x=x+1)) Done SQL_SERVER='servername' /apps/sun5/utils/sqsh -S $SQL_SERVER -U user -P pwd -b -h... (1 Reply)
Discussion started by: sudheer157
1 Replies

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

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

4. Shell Programming and Scripting

PERL : Bind 2D array to SQL

Hi, I am in the need of doing a bulk insert via : SQL - INSERT INTO <table> (SELECT..) OR PLSQL Block - FORALL i IN 1 .. count INSERT INTO <table>(arrayname(i)) I have a 2D array in my perl code which has the rows to be bulk inserted. Is there a way to bind the 2D array to the SQL... (4 Replies)
Discussion started by: sinpeak
4 Replies

5. Shell Programming and Scripting

PERL : SQL array bind issue while grouping

Hi, I have an array of strings. Each string has 4 comma separated values. I am binding this array to a SQL where I am required to do an INSERT after grouping. The binding is done as : $insertADWSth->bind_param_array(1,A_CONSTANT_STRING);... (1 Reply)
Discussion started by: sinpeak
1 Replies

6. UNIX and Linux Applications

SQL database call into Multidimensional Array using Perl Script

#!/usr/local/bin/perl use DBI; use File::Copy; use Time::Local; use Data::Dumper; -Comments Describing what I'm doing-------------- -I'm pulling information from a database that has an ID and Name. They are separated by a space and I'm trying to load them into a multidimensional array so as... (3 Replies)
Discussion started by: eazyeddie22
3 Replies

7. Shell Programming and Scripting

Pass perl array to SQL oracle

Hello, Could someone please suggest if there is a way to pass an perl array(pass @v_array) to SQL as in below eg : #!/usr/bin/perl @v_array = (1,2,4,5,6,8); $db_userid = 'ni71/ni711'; $bufTPO = qx{ sqlplus -s << EOF $db_userid set verify off set feedback off set... (1 Reply)
Discussion started by: arunshankar.c
1 Replies

8. Shell Programming and Scripting

error while updating rows in sql with values in array variable

Hi, I need to update rows in a table based on the values in an array variable. code is : while read line do error_msg="$(echo $line)" index=`expr $index+1` done <"logs/$ffile" rows_count=${#error_msg } i=0 while do echo "error msgs is... (2 Replies)
Discussion started by: RP09
2 Replies

9. Shell Programming and Scripting

Storing the SQL results in array variables

Requirement 1) I need to execute 15 SQL queries in oracle through linux script. All these query results needs to be stored in array variables. Requirement 2) And these 15 queries needs to be executed in parallel. Requirement 3) Once all the queries executed then the shell script should... (3 Replies)
Discussion started by: Niranjancse
3 Replies

10. Shell Programming and Scripting

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... (2 Replies)
Discussion started by: yuvi
2 Replies
Perl::Critic::Policy::Variables::RequireNegativeIndices(User Contributed Perl DocumentPerl::Critic::Policy::Variables::RequireNegativeIndices(3pm)

NAME
Perl::Critic::Policy::Variables::RequireNegativeIndices - Negative array index should be used. AFFILIATION
This Policy is part of the core Perl::Critic distribution. DESCRIPTION
Conway points out that $arr[$#arr]; $arr[$#arr-1]; $arr[@arr-1]; $arr[@arr-2]; are equivalent to $arr[-1]; $arr[-2]; $arr[-1]; $arr[-2]; and the latter are more readable, performant and maintainable. The latter is because the programmer no longer needs to keep two variable names matched. This policy notices all of the simple forms of the above problem, but does not recognize any of these more complex examples: $some->[$data_structure]->[$#{$some->[$data_structure]} -1]; my $ref = @arr; $ref->[$#arr]; CONFIGURATION
This Policy is not configurable except for the standard options. AUTHOR
Chris Dolan <cdolan@cpan.org> COPYRIGHT
Copyright (c) 2006-2011 Chris Dolan. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2012-06-07 Perl::Critic::Policy::Variables::RequireNegativeIndices(3pm)
All times are GMT -4. The time now is 11:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy