Sponsored Content
Top Forums Shell Programming and Scripting calling sqlplus, read table return etc Post 302306797 by TimHortons on Monday 13th of April 2009 09:00:38 PM
Old 04-13-2009
Bug calling sqlplus, read table return etc

I have korn shell scripts.

I want to pass a variable to a script which will execute a a sql script to read a table that contains env. variables. I want to read and then somehow export at unix level variables

example
for every row selected from the table build export command line

field1 := 'export SHELL = /app/pasf/sqr; ';

I some how need to get these back to unix korn script so I can create the variable at the unix level. It will be valid only while the session is open.

Not sure the best way to do this.

So far I created a the following(its just a start):

Code:
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);

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;
    
 
   LOOP
    fetch XXX_cursor into XXX_VARS;
    EXIT WHEN XXX_cursor%notfound; 
     SHELL2 := XXX_VARS.STRING_TEXT ;
     SHELL1 := XXX_VARS.STRING_ID;
    DBMS_OUTPUT.put_line (SHELL1);
        EXIT WHEN XXX_cursor%notfound; 
   END LOOP;
   CLOSE XXX_cursor ;
END;

output is

EXPORT PARMS= /unixsxxx/apps/psf/zzz/CCC/

EXPORT SHELL= /unixsxxx/apps/psf/zzz/CCC/

EXPORT SQL= /unixsxxx/apps/psf/zzz/CCCC/

EXPORT SQR= /unixsxx/apps/psf/zzz/

Last edited by TimHortons; 04-14-2009 at 08:50 AM.. Reason: code tag added
 

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
OCI_FETCH_OBJECT(3)													       OCI_FETCH_OBJECT(3)

oci_fetch_object - Returns the next row from a query as an object

SYNOPSIS
object oci_fetch_object (resource $statement) DESCRIPTION
Returns an object containing the next result-set row of a query. Each attribute of the object corresponds to a column of the row. This function is typically called in a loop until it returns FALSE, indicating no more rows exist. For details on the data type mapping performed by the OCI8 extension, see the datatypes supported by the driver PARAMETERS
o $statement -A valid OCI8 statement identifier created by oci_parse(3) and executed by oci_execute(3), or a REF CURSOR statement identifier. RETURN VALUES
Returns an object. Each attribute of the object corresponds to a column of the row. If there are no more rows in the $statement then FALSE is returned. Any LOB columns are returned as LOB descriptors. DATE columns are returned as strings formatted to the current date format. The default format can be changed with Oracle environment vari- ables such as NLS_LANG or by a previously executed ALTER SESSION SET NLS_DATE_FORMAT command. Oracle's default, non-case sensitive column names will have uppercase attribute names. Case-sensitive column names will have attribute names using the exact column case. Use var_dump(3) on the result object to verify the appropriate case for attribute access. Attribute values will be NULL for any NULL data fields. EXAMPLES
Example #1 oci_fetch_object(3) example <?php /* Before running, create the table: CREATE TABLE mytab (id NUMBER, description VARCHAR2(30)); INSERT INTO mytab (id, description) values (1, 'Fish and Chips'); COMMIT; */ $conn = oci_connect('hr', 'welcome', 'localhost/XE'); if (!$conn) { $e = oci_error(); trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); } $stid = oci_parse($conn, 'SELECT id, description FROM mytab'); oci_execute($stid); while (($row = oci_fetch_object($stid)) != false) { // Use upper case attribute names for each standard Oracle column echo $row->ID . "<br> "; echo $row->DESCRIPTION . "<br> "; } // Output is: // 1 // Fish and Chips oci_free_statement($stid); oci_close($conn); ?> Example #2 oci_fetch_object(3) with case sensitive column names <?php /* Before running, create the table with a case sensitive column name: CREATE TABLE mytab (id NUMBER, "MyDescription" VARCHAR2(30)); INSERT INTO mytab (id, "MyDescription") values (1, 'Iced Coffee'); COMMIT; */ $conn = oci_connect('hr', 'welcome', 'localhost/XE'); if (!$conn) { $e = oci_error(); trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); } $stid = oci_parse($conn, 'SELECT id, "MyDescription" FROM mytab'); oci_execute($stid); while (($row = oci_fetch_object($stid)) != false) { // Use upper case attribute names for each standard Oracle column echo $row->ID . "<br> "; // Use the exact case for the case sensitive column name echo $row->MyDescription . "<br> "; } // Output is: // 1 // Iced Coffee oci_free_statement($stid); oci_close($conn); ?> Example #3 oci_fetch_object(3) with LOBs <?php /* Before running, create the table: CREATE TABLE mytab (id NUMBER, description CLOB); INSERT INTO mytab (id, description) values (1, 'A very long string'); COMMIT; */ $conn = oci_connect('hr', 'welcome', 'localhost/XE'); if (!$conn) { $e = oci_error(); trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); } $stid = oci_parse($conn, 'SELECT id, description FROM mytab'); oci_execute($stid); while (($row = oci_fetch_object($stid)) != false) { echo $row->ID . "<br> "; // The following will output the first 11 bytes from DESCRIPTION echo $row->DESCRIPTION->read(11) . "<br> "; } // Output is: // 1 // A very long oci_free_statement($stid); oci_close($conn); ?> SEE ALSO
oci_fetch(3), oci_fetch_all(3), oci_fetch_assoc(3), oci_fetch_array(3), oci_fetch_row(3). PHP Documentation Group OCI_FETCH_OBJECT(3)
All times are GMT -4. The time now is 01:38 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy