Sponsored Content
Top Forums Shell Programming and Scripting Creating IN list in PLSQL script dynamically by using shell script Post 302910857 by durden_tyler on Monday 28th of July 2014 03:02:40 PM
Old 07-28-2014
Quote:
Originally Posted by LoneRanger
...
I have a PLSQL script which has a IN list where it takes some ids as input. For example

SELECT * FROM EMPLOYEE WHERE EMPLOYEE_ID IN (comma separated list )

I want to run this quest inside a shell script but I would like to prepare the IN list dynamically where the employee ids will be there in the same directory in a different file in the below format.

File Name - employee_list
234
456
784
123

How can I insert all the employee ID into the PLSQL script in one go ?...
You haven't mentioned your Oracle version. To solve this problem, you could use INSTR/SUBSTR functions in any (modern) version of Oracle, or if you have 10g or higher, you could use regular expressions.

Code:
SQL>
SQL> --
SQL> -- Check the data in the EMPLOYEES table for a few EMPLOYEE_IDs
SQL> --
SQL> select employee_id, first_name, last_name
  2    from employees
  3   where employee_id in (100, 121, 145, 179, 202);
 
EMPLOYEE_ID FIRST_NAME           LAST_NAME
----------- -------------------- -------------------------
        100 Steven               King
        121 Adam                 Fripp
        145 John                 Russell
        179 Charles              Johnson
        202 Pat                  Fay
 
5 rows selected.
 
SQL>
SQL> --
SQL> var str varchar2(30)
SQL> exec :str := '100,121,145,179,202';
 
PL/SQL procedure successfully completed.
 
SQL> print str
 
STR
------------------------------
100,121,145,179,202
 
SQL>
SQL> --
SQL> -- Query 1: Should work in any (non-ancient / real-life) version of Oracle
SQL> --
SQL> select e.employee_id, e.first_name, e.last_name
  2    from employees e,
  3         (
  4              select substr(','||:str||',',
  5                            instr(','||:str||',',',',1,level) + 1,
  6                            instr(','||:str||',',',',1,level+1) - instr(','||:str||',',',',1,level) - 1
  7                           ) as token
  8                from dual
  9               connect by level <= length(:str) - length(replace(:str,',')) + 1
 10         ) x
 11   where e.employee_id = x.token;
 
EMPLOYEE_ID FIRST_NAME           LAST_NAME
----------- -------------------- -------------------------
        100 Steven               King
        121 Adam                 Fripp
        145 John                 Russell
        179 Charles              Johnson
        202 Pat                  Fay
 
5 rows selected.
 
SQL>
SQL> --
SQL> -- Query 2: Should work in Oracle 10g and higher
SQL> --
SQL> select e.employee_id, e.first_name, e.last_name
  2    from employees e,
  3         (
  4              select regexp_substr(:str,'[^,]+',1,level) as token
  5                from dual
  6               connect by level <= length(:str) - length(replace(:str,',')) + 1
  7         ) x
  8   where e.employee_id = x.token;
 
EMPLOYEE_ID FIRST_NAME           LAST_NAME
----------- -------------------- -------------------------
        100 Steven               King
        121 Adam                 Fripp
        145 John                 Russell
        179 Charles              Johnson
        202 Pat                  Fay
 
5 rows selected.
 
SQL>
SQL>

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script dynamically case in VAR

Hallo, I am working on a kdialog. This shall be able to load the required commands from a .conf file. First step runs good by loading the entries (selectabel entries) in a variable: MIRRORSELECT=$(kdialog --radiolist "Select your nearest mirror" $VAR1) The kdialog is accordingly correct... (2 Replies)
Discussion started by: ACTGADE
2 Replies

2. Programming

UNIX Shell Script to Create a Document of a PLSQL code.

Hi All, I am supposed to present the documentation for the PLSQL code (PACKAGES, PROCEDURE, FUNCTIONS) of my application. There are sufficient comments in my code. Has anyone written any Shell Script Utility which can parse the PLSQL code and generate some kind of document ( preferrably HTML not... (1 Reply)
Discussion started by: gauravsachan
1 Replies

3. Shell Programming and Scripting

Shell Script to Parse PLSQL code?

Hi All, I am supposed to present the documentation for the PLSQL code (PACKAGES, PROCEDURE, FUNCTIONS) of my application. There are sufficient comments in my code. Has anyone written any Shell Script Utility which can parse the PLSQL code and generate some kind of document ( preferrably HTML not... (2 Replies)
Discussion started by: gauravsachan
2 Replies

4. Shell Programming and Scripting

Dynamically creating text files using shell script

Hi All, I want to create a shell script which dynamically create text files. i am using the following script $i=1 while do cat > test_$i.txt done but while running the script it was stopping(the cursor not going to next step, i have to enter ctrl+c to make it stop). it is creating only... (2 Replies)
Discussion started by: KiranKumarKarre
2 Replies

5. Programming

running PLSQL scripts through shell script

I am running the following ealth checks on my server there are two databases in my server . MODEL1 and MODEL2 i connect with the first database as sqlplus model1/password Then i exceute a query select x from table (4 Replies)
Discussion started by: asalman.qazi
4 Replies

6. Programming

Executing shell script from PLSQL

Hi All, I have a requirement to mv a file in unix from plsql procedure. for that i have created a java host procedure, a host_command, given all grants as per ORACLE-BASE - Oracle8i Shell Commands From PL/SQL but i am getting an error ""Process err :/bin/sh: mv Not Found"" kindly let me... (1 Reply)
Discussion started by: aryan_styles
1 Replies

7. Shell Programming and Scripting

Execute shell script from plsql trigger

Hi, I have been assigned a job which requires me to send mails from unix(Mailx) upon on certain actions triggered in the database. On insert/update of a certain field into one of the database tables the shell script present in Unix box responsible to send mail though mailx needs to be triggered... (7 Replies)
Discussion started by: hemant.bs11
7 Replies

8. Shell Programming and Scripting

Creating variables dynamically and using it in script?

Hi, I have a problem that I am trying to solve and would greatly appreciate some input to solve this. I have a file containing variable length of line. Each line in the file has values separated by "," and i need to grep for these values in a some files. For example below is a sample file with 3... (12 Replies)
Discussion started by: davidtd
12 Replies

9. Shell Programming and Scripting

calling a plsql procedure through shell script

I have a plsql procedure inside a package which is having one IN parameter .I want to call that procedure through a shell script and that IN parameter is a column of a table in the database. So my requirement is that i need to loop all the entries of that IN parameter from the table through shell... (4 Replies)
Discussion started by: rspnf
4 Replies

10. Homework & Coursework Questions

How to Dynamically Pass Parameter to plsql Function & Capture its Output Value in a Shell Variable?

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: 2. Relevant commands, code, scripts, algorithms: #! /bin/ksh v="ORG_ID" ... (2 Replies)
Discussion started by: sujitdas2104
2 Replies
uudemon(4)						     Kernel Interfaces Manual							uudemon(4)

NAME
uudemon.admin, uudemon.cleanu, uudemon.hour, uudemon.poll - Administrative shell scripts for polling remote systems, cleaning up spool directories, reporting status to the system administrator, and routine invocations of the uuxqt and uusched daemons SYNOPSIS
These shell scripts reside in the following directory: /usr/lib/uucp DESCRIPTION
All the scripts can be run from the command line or can be run automatically by the cron daemon. To automatically run the scripts, remove the comment character (#) from the beginning of the relevant line in the /var/spool/cron/crontabs/uucp file. This script reports status to the system administrator. It issues the uustat command to find out the status of uucp jobs. It mails the results to the uucp login ID. The script may be modified to send mail to any login ID such as the uucp administrative login ID (uucpa) or root. This script cleans up the /var/spool/uucp and /var/spool/uucppublic directories by running the uucleanup command. The uucleanup com- mand is run with the following parameters: -C7, -D7, X2, -o2, -W1. This script runs the uusched and uuxqt daemons in the background. This script polls the systems listed in the /usr/lib/uucp/Poll file. The uudemon.poll script should be scheduled before the uudemon.hour script. This allows uudemon.poll to create any command files before cron runs the uudemon.hour script. FILES
Contains the uudemon.admin, uudemon.cleanu, uudemon.hour and uudemon.poll files. Contains the uucp file. RELATED INFORMATION
Commands: cron(8), uucleanup(8), uusched(8), uuxqt(1) Files: /usr/lib/uucp delim off uudemon(4)
All times are GMT -4. The time now is 06:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy