Sponsored Content
Top Forums Shell Programming and Scripting calling sqlplus, read table return etc Post 302307019 by jim mcnamara on Tuesday 14th of April 2009 11:27:07 AM
Old 04-14-2009
use UTL_FILE to open a file, write those script statements to the file, then close the file. For example call it /tmp/env.sh

Code:
# ........ sql code goes here in  a here document

sqlplus -s username/password@somedbname <<EOF
SET serveroutput ON
DECLARE
   recordtype   varchar2 (6)      :='DBASE1'; 
   SHELL        VARCHAR2 (36);
   SHELL1        VARCHAR2 (36);
   SHELL2        VARCHAR2 (36);
   PARMS        VARCHAR2 (36);
   SQR          VARCHAR2 (31);
   SQLq          VARCHAR2 (36);
   CTL          VARCHAR2 (36);
   TNS_ADMIN    VARCHAR2 (44);
   ORACLE_HOME1 VARCHAR2 (44);
   PATH1        VARCHAR2 (30);
   FP           UTL_FILE.FILE_TYPE;

CURSOR XXX_cursor IS
 SELECT  PROGRAM_ID,STRING_ID,LABEL_ID,STRING_TEXT,COL_WIDTH from PS_XXX_ENV_VARS
           WHERE PROGRAM_ID =  recordtype;
 XXX_VARS XXX_cursor%ROWTYPE;
BEGIN
    IF NOT XXX_cursor%isopen THEN
       OPEN XXX_cursor;
    END IF;
    
   FP:=UTL_FILE.FOPEN('/TMP','ENV.SH','W');
   LOOP
    	fetch XXX_cursor into XXX_VARS;
    	EXIT WHEN XXX_cursor%notfound; 
    	 SHELL2 := XXX_VARS.STRING_TEXT ;
    	 SHELL1 := XXX_VARS.STRING_ID;
    	UTL_FILE.put_line (FP, SHELL1||'='||SHELL2);        
   END LOOP;
   UTL_FILE.FCLOSE(FP);
   CLOSE XXX_cursor ;
END;
  exit
EOF

# set permissions on file:
chmod +x /tmp/env.sh
# source the shell script to bring env vars into this process
. /tmp/env.sh

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

calling sqlplus from shell

Hi All, I am executing the following code :- sqlplus -s ${DATABASE_USER} |& print -p -- 'set feed off pause off pages 0 head off veri off line 500' print -p -- 'set term off time off serveroutput on size 1000000' print -p -- "set sqlprompt ''" print -p -- "SELECT run_command from... (2 Replies)
Discussion started by: suds19
2 Replies

2. UNIX for Advanced & Expert Users

Problem while calling Oracle 10g SQLPLUS files

Hi all, Iam facing a lot of problem while calling Oracle 10g SQLPLUS files from shell. What is the standard procedures to be taken care. Any help would be useful for me. Thanks in advance, Ganapati. (2 Replies)
Discussion started by: ganapati
2 Replies

3. Shell Programming and Scripting

calling sqlplus from within a for loop

i'm not new to programming, but i AM new to unix scripting. here's my deal. this works: #!/bin/ksh echo "HELLO" /oracle_home/bin/sqlplus username/password@MYDB<<EOF SELECT COUNT(*) FROM EMPLOYEES; EOF exit echo "GOODBYE" this doesn't: #!/bin/ksh echo "HELLO" for x in 1 2... (4 Replies)
Discussion started by: akosz
4 Replies

4. UNIX and Linux Applications

How to access Oracle table using sqlplus

Hi, I want to use sqlplus from server1 sqlplus usr1/pass1@dns1 and I want to connect to an Oracle database from a server2. Unfortunately the database was created on the server1 and on server2. So when I use the command just like that...it connects to the database from the server2. ... (2 Replies)
Discussion started by: AngelMady
2 Replies

5. Shell Programming and Scripting

Error in calling store procedure using SQLPLUS in unix

Hi, I am facing the following error in calling the stored procedure from SQLPLUS in unix environment. SQL> set serveroutput on SQL> var store number; SQL> exec test_proc(:store, 200); BEGIN TEST_PROC(:store, 200); END; * ERROR at line 1: ORA-01858: a non-numeric character was found... (8 Replies)
Discussion started by: pradeep7986
8 Replies

6. UNIX for Dummies Questions & Answers

calling a unix shell script from sqlplus

I want to execute a shell script from sqlplus prompt and get its output back to sqlplus. Is this possible? if yes just give me an example for doing that. (2 Replies)
Discussion started by: boopathyvasagam
2 Replies

7. Shell Programming and Scripting

Calling sqlplus from Korn shell heredoc issue

Hi, I am facing an issue wherein some temporary files (here docs) are getting created in /tmp and are not getting deleted automatically. When i check the list of open files with below command i can see one file is getting appended continuously.(In this case /tmp/sfe7h.34p) The output is... (4 Replies)
Discussion started by: Navin_Ramdhami
4 Replies

8. Shell Programming and Scripting

Truncate table $TABLE -- SQLPLUS

I want to truncate a table using sqlplus where the table name is in shell variable: I am using : sqlplus -s / <<end truncate table $TABLE end (2 Replies)
Discussion started by: IB_88
2 Replies

9. Shell Programming and Scripting

Avoid $ symbol while calling sqlplus in shellscript.

Hi All, we have requirement, i am created a shell script , inside i am connecting sqlplus and execute the query. below my code for your reference. get_sqlid () { sqlid=$( sqlplus -s $PBDW_USERID/$PBDW_PW@$PBDW_SID <<EOF DEFINE TBLNAME=$1 set feedback off set serverout on size... (4 Replies)
Discussion started by: KK230689
4 Replies

10. UNIX for Beginners Questions & Answers

SQLPLUS calling Via Script

Hello All, Could you please help me if i am doing anything wrong in below script, especially the sqlplus part performance wise or anything else i could improvise in the script. Thank you. #!/bin/ksh ## Batch Obj Id MP_BCH_OBJ_ID=$1 PASS=$2 partition=$3 ## script dir... (6 Replies)
Discussion started by: Ariean
6 Replies
service(8)						      System Manager's Manual							service(8)

NAME
service - run a System V init script SYNOPSIS
service SCRIPT COMMAND [OPTIONS] service --status-all service --help | -h | --version DESCRIPTION
service runs a System V init script in as predictable environment as possible, removing most environment variables and with current working directory set to /. The SCRIPT parameter specifies a System V init script, located in /etc/init.d/SCRIPT. The supported values of COMMAND depend on the invoked script, service passes COMMAND and OPTIONS it to the init script unmodified. All scripts should support at least the start and stop commands. As a special case, if COMMAND is --full-restart, the script is run twice, first with the stop command, then with the start command. service --status-all runs all init scripts, in alphabetical order, with the status command. EXIT CODES
service calls the init script and returns the status returned by it. FILES
/etc/init.d The directory containing System V init scripts. ENVIRONMENT
LANG, TERM The only environment variables passed to the init scripts. SEE ALSO
/etc/init.d/skeleton, update-rc.d(8), init(8), invoke-rc.d(8). Jan 2006 service(8)
All times are GMT -4. The time now is 07:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy