<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Test return code from sql in script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/test-return-code-from-sql-in-script/m-p/3212769#M899397</link>
    <description>You should be able to retrieve the return code as follows:&lt;BR /&gt;#sqlscript&lt;BR /&gt;sqlplus internal &amp;lt;&amp;lt; EOF&lt;BR /&gt;command&lt;BR /&gt;command&lt;BR /&gt;command&lt;BR /&gt;rc=$?&lt;BR /&gt;EOF&lt;BR /&gt;&lt;BR /&gt;return $rc&lt;BR /&gt;&lt;BR /&gt;The stub above is called by another script which will get the return code from here with the following code:&lt;BR /&gt;&lt;BR /&gt;sqlscript&lt;BR /&gt;return_code=$?&lt;BR /&gt;SEP</description>
    <pubDate>Mon, 08 Mar 2004 19:00:12 GMT</pubDate>
    <dc:creator>Steven E. Protter</dc:creator>
    <dc:date>2004-03-08T19:00:12Z</dc:date>
    <item>
      <title>Test return code from sql in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/test-return-code-from-sql-in-script/m-p/3212767#M899395</link>
      <description>I know I've seen this before, but I can't find it.  &lt;BR /&gt;&lt;BR /&gt;I want to run an Oracle (9i) SQL script from a ksh script. Can I set a return code within the SQL script that can be tested within the ksh script?&lt;BR /&gt;&lt;BR /&gt;Thanks!</description>
      <pubDate>Mon, 08 Mar 2004 18:31:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/test-return-code-from-sql-in-script/m-p/3212767#M899395</guid>
      <dc:creator>Scott Williams_5</dc:creator>
      <dc:date>2004-03-08T18:31:39Z</dc:date>
    </item>
    <item>
      <title>Re: Test return code from sql in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/test-return-code-from-sql-in-script/m-p/3212768#M899396</link>
      <description>Yes you can...&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://metalink.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&amp;amp;p_id=73788.1" target="_blank"&gt;http://metalink.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&amp;amp;p_id=73788.1&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Example PL/SQL: How to Pass Status from PL/SQL Script to Calling Shell Script &lt;BR /&gt;&lt;BR /&gt;Overview&lt;BR /&gt;&lt;BR /&gt;--------&lt;BR /&gt;&lt;BR /&gt;This article contains an example of returning the status from a PL/SQL&lt;BR /&gt;&lt;BR /&gt;program to a shell script.&lt;BR /&gt;&lt;BR /&gt;It is intended for use by PL/SQL and shell script programmers. In&lt;BR /&gt;&lt;BR /&gt;principle, this approach is transferable to all operating systems capable&lt;BR /&gt;&lt;BR /&gt;of receiving a return value from a called program in a script. The example&lt;BR /&gt;&lt;BR /&gt;given is (in part) UNIX specific.&lt;BR /&gt;&lt;BR /&gt;SQL*Plus is commonly run interactively. It is also possible to pass&lt;BR /&gt;&lt;BR /&gt;SQL*Plus the name of a SQL script file and have it run the script file&lt;BR /&gt;&lt;BR /&gt;non-interactively and pass the result status back to the caller. In&lt;BR /&gt;&lt;BR /&gt;this manner, SQL scripts may be executed via SQL*Plus from UNIX shell&lt;BR /&gt;&lt;BR /&gt;scripts and, based upon the return status from SQL*Plus, the shell script&lt;BR /&gt;&lt;BR /&gt;may make decisions about how to proceed.&lt;BR /&gt;&lt;BR /&gt;Sample Code&lt;BR /&gt;&lt;BR /&gt;-----------&lt;BR /&gt;&lt;BR /&gt;ret.sql:&lt;BR /&gt;&lt;BR /&gt;prompt Look in your SQL*Plus User's guide for other datatypes&lt;BR /&gt;&lt;BR /&gt;prompt that EXIT can pass to a calling script via a bind variable&lt;BR /&gt;&lt;BR /&gt;prompt&lt;BR /&gt;&lt;BR /&gt;set serveroutput on&lt;BR /&gt;&lt;BR /&gt;variable ret_val number&lt;BR /&gt;&lt;BR /&gt;declare&lt;BR /&gt;&lt;BR /&gt;dstr varchar2(40);&lt;BR /&gt;&lt;BR /&gt;thedate date;&lt;BR /&gt;&lt;BR /&gt;begin&lt;BR /&gt;&lt;BR /&gt;select sysdate into thedate from dual;&lt;BR /&gt;&lt;BR /&gt;dstr := to_char(thedate, 'MON');&lt;BR /&gt;&lt;BR /&gt;dbms_output.put_line('Month: '||dstr);&lt;BR /&gt;&lt;BR /&gt;if(dstr = 'JUL') then&lt;BR /&gt;&lt;BR /&gt;:ret_val := 100;&lt;BR /&gt;&lt;BR /&gt;else&lt;BR /&gt;&lt;BR /&gt;:ret_val := 200;&lt;BR /&gt;&lt;BR /&gt;end if;&lt;BR /&gt;&lt;BR /&gt;end;&lt;BR /&gt;&lt;BR /&gt;/&lt;BR /&gt;&lt;BR /&gt;exit :ret_val;&lt;BR /&gt;&lt;BR /&gt;The key is the SQL*Plus bind variable.&lt;BR /&gt;&lt;BR /&gt;You must first declare a bind variable. Second, specify the anonymous&lt;BR /&gt;&lt;BR /&gt;PL/SQL block which must set the bind variable to some meaningful value.&lt;BR /&gt;&lt;BR /&gt;Third, run the anonymous PL/SQL block via the '/'. Then exit the SQL&lt;BR /&gt;&lt;BR /&gt;script specifying the bind variable.&lt;BR /&gt;&lt;BR /&gt;The exit command tells SQL*Plus to exit with the value specified. This&lt;BR /&gt;&lt;BR /&gt;value is passed back to the calling UNIX script, where the command&lt;BR /&gt;&lt;BR /&gt;completion status may be examined.&lt;BR /&gt;&lt;BR /&gt;Here is the korn shell script:&lt;BR /&gt;&lt;BR /&gt;#!/bin/ksh&lt;BR /&gt;&lt;BR /&gt;sqlplus scott/tiger @ret&lt;BR /&gt;&lt;BR /&gt;if [ $? -eq 100 ]&lt;BR /&gt;&lt;BR /&gt;then&lt;BR /&gt;&lt;BR /&gt;echo "The month is July"&lt;BR /&gt;&lt;BR /&gt;else&lt;BR /&gt;&lt;BR /&gt;echo "The month is not July"&lt;BR /&gt;&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;This script simply calls SQL*Plus using the user name and password of scott&lt;BR /&gt;&lt;BR /&gt;and tiger and tells it to execute the ret.sql PL/SQL script. Subsequently,&lt;BR /&gt;&lt;BR /&gt;the script checks the return status and prints out an appropriate message.&lt;BR /&gt;&lt;BR /&gt;Other platforms may have their own script language into which you must embed&lt;BR /&gt;&lt;BR /&gt;the SQL*Plus call.&lt;BR /&gt;&lt;BR /&gt;Test Platforms:&lt;BR /&gt;&lt;BR /&gt;--------------&lt;BR /&gt;&lt;BR /&gt;The above scripts were tested succesfully on:&lt;BR /&gt;&lt;BR /&gt;SunSolaris with rdbms 8.1.6.2.0&lt;BR /&gt;&lt;BR /&gt;IBM RS/6000 AIX with rdbms 8.1&lt;BR /&gt;&lt;BR /&gt;References&lt;BR /&gt;&lt;BR /&gt;----------&lt;BR /&gt;&lt;BR /&gt;"SQL*Plus User's Guide and Reference, Release 8.1.5", (A66736-01)&lt;BR /&gt;&lt;BR /&gt;Note:2177.1 Pass a parameter with spaces to SQL*Plus&lt;BR /&gt;&lt;BR /&gt;Note:6841.1 Using a PL/SQL Varianle to set the EXIT code of a SQL script</description>
      <pubDate>Mon, 08 Mar 2004 18:59:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/test-return-code-from-sql-in-script/m-p/3212768#M899396</guid>
      <dc:creator>James A. Donovan</dc:creator>
      <dc:date>2004-03-08T18:59:39Z</dc:date>
    </item>
    <item>
      <title>Re: Test return code from sql in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/test-return-code-from-sql-in-script/m-p/3212769#M899397</link>
      <description>You should be able to retrieve the return code as follows:&lt;BR /&gt;#sqlscript&lt;BR /&gt;sqlplus internal &amp;lt;&amp;lt; EOF&lt;BR /&gt;command&lt;BR /&gt;command&lt;BR /&gt;command&lt;BR /&gt;rc=$?&lt;BR /&gt;EOF&lt;BR /&gt;&lt;BR /&gt;return $rc&lt;BR /&gt;&lt;BR /&gt;The stub above is called by another script which will get the return code from here with the following code:&lt;BR /&gt;&lt;BR /&gt;sqlscript&lt;BR /&gt;return_code=$?&lt;BR /&gt;SEP</description>
      <pubDate>Mon, 08 Mar 2004 19:00:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/test-return-code-from-sql-in-script/m-p/3212769#M899397</guid>
      <dc:creator>Steven E. Protter</dc:creator>
      <dc:date>2004-03-08T19:00:12Z</dc:date>
    </item>
    <item>
      <title>Re: Test return code from sql in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/test-return-code-from-sql-in-script/m-p/3212770#M899398</link>
      <description>Thanks guys -- Really appreciate it.&lt;BR /&gt;&lt;BR /&gt;Scott</description>
      <pubDate>Mon, 08 Mar 2004 19:21:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/test-return-code-from-sql-in-script/m-p/3212770#M899398</guid>
      <dc:creator>Scott Williams_5</dc:creator>
      <dc:date>2004-03-08T19:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: Test return code from sql in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/test-return-code-from-sql-in-script/m-p/3212771#M899399</link>
      <description>This is what I did. Note that the script below contains a typo in the "FROM" clause: dba_xablespaces, instead of dba_tablespaces.&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;#typeset -i rc=0&lt;BR /&gt;&lt;BR /&gt;sqlplus /nolog &amp;lt;&lt;EOD&gt;&lt;/EOD&gt;connect / as  sysdba;&lt;BR /&gt;whenever sqlerror exit 9&lt;BR /&gt;set echo on;&lt;BR /&gt;SELECT tablespace_name&lt;BR /&gt;FROM   sys.dba_xablespaces&lt;BR /&gt;ORDER BY 1;&lt;BR /&gt;EOD&lt;BR /&gt;rc=$?&lt;BR /&gt;&lt;BR /&gt;print "returning: \"$rc\""&lt;BR /&gt;return $rc&lt;BR /&gt;=====================================&lt;BR /&gt;Running this script gives the following output:&lt;BR /&gt;SQL&amp;gt; Connected.&lt;BR /&gt;SQL&amp;gt; SQL&amp;gt; buffer cleared&lt;BR /&gt;SQL&amp;gt; SQL&amp;gt; SQL&amp;gt; SQL&amp;gt; SQL&amp;gt; SQL&amp;gt; SQL&amp;gt; SQL&amp;gt; SQL&amp;gt; SQL&amp;gt;   2    3  FROM   sys.dba_xablespaces&lt;BR /&gt;           *&lt;BR /&gt;ERROR at line 2:&lt;BR /&gt;ORA-00942: table or view does not exist&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production&lt;BR /&gt;With the Partitioning, OLAP and Oracle Data Mining options&lt;BR /&gt;JServer Release 9.2.0.4.0 - Production&lt;BR /&gt;returning: "9"&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks again,&lt;BR /&gt;&lt;BR /&gt;Scott</description>
      <pubDate>Tue, 09 Mar 2004 11:12:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/test-return-code-from-sql-in-script/m-p/3212771#M899399</guid>
      <dc:creator>Scott Williams_5</dc:creator>
      <dc:date>2004-03-09T11:12:57Z</dc:date>
    </item>
  </channel>
</rss>

