I have the following shell script register as host executable calling a procedure, that will call a concurrent program in oracle , when I submit the job, it has no concurrent program spawn, I am using the same method in other instance before and it will work, wonder if I missed anything.
#!/bin/ksh
#--------------------------------------------------
# Get the current date
#--------------------------------------------------
HISTDATE=`date +"%m%d%y%H%M%S"`
#--------------------------------------------------
# Input Paramenters
#--------------------------------------------------
APPSPW=${1}
USERID=${2}
USERNAME=${3}
REQID=${4}
INTERFACE_PATH=${5}
AS_OF_DATE=${6}
FILENAME=${7}
echo "+---------------------------------------------------------------------------+"
echo "| 1. Get FTP Info"
echo "+---------------------------------------------------------------------------+"
echo "Request Id : " $REQID
echo "Used Id : " $USERID
echo "User Name : " $USERNAME
echo "Interface Path : " $INTERFACE_PATH
echo "As of Date : " $AS_OF_DATE
echo "File Name : " $FILENAME
if [ -d $INTERFACE_PATH ]; then
echo "- 1.1 Folder "$INTERFACE_PATH" exists"
else
echo "- 1.1 Folder "$INTERFACE_PATH" does not exist"
exit 1
fi
echo "+---------------------------------------------------------------------------+"
echo "| 2. Check File Exist or Not"
echo "+---------------------------------------------------------------------------+"
cd $INTERFACE_PATH
V_FILENAME="${FILENAME}${AS_OF_DATE}"
for files in `ls ${V_FILENAME}*`
do
echo "File Name : " $files
INPUT_FULL_FILENAME="${INTERFACE_PATH}${files}"
if [ -s $INPUT_FULL_FILENAME ]; then
echo "File found, now proceed SQL loader"
sqlplus $APPSPW <<ENDOFSQL
connect $APPSPW
SET SERVEROUTPUT ON
DECLARE
P_ERRBUFF VARCHAR2(4000);
P_ERRCODE VARCHAR2(100);
P_FULL_PATH VARCHAR2(400);
ln_request_id NUMBER;
lv_appl_name VARCHAR2(10) := 'XHGL';
lvc_sqlloader1 VARCHAR2(30) := 'XHGL_DCASS_STG';
lv_req_status1 VARCHAR2(1);
lv_msg VARCHAR2(1000);
ln_user_id NUMBER;
ln_resp_id NUMBER;
ln_resp_appl_id NUMBER;
BEGIN
BEGIN
SELECT APPLICATION_ID
INTO ln_resp_appl_id
FROM FND_APPLICATION
WHERE APPLICATION_SHORT_NAME = 'XHGL';
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('Failed to get ln_resp_appl_id');
END;
BEGIN
SELECT FND_GLOBAL.USER_ID
INTO ln_user_id
FROM DUAL;
END;
dbms_output.put_line('ln_user_id = ' || ln_user_id);
BEGIN
SELECT FND_GLOBAL.RESP_ID
INTO ln_resp_id
FROM DUAL;
END;
P_FULL_PATH := TO_CHAR('${INPUT_FULL_FILENAME}');
dbms_output.put_line('P_FULL_PATH = ' || P_FULL_PATH);
FND_GLOBAL.APPS_INITIALIZE(USER_ID => ln_user_id,
RESP_ID => ln_resp_id,
RESP_APPL_ID => ln_resp_appl_id);
XHGL_DCASS_INBOUND_PKG.SUBMIT_CCMS_STG( P_ERRBUFF, P_ERRCODE, P_FULL_PATH );
dbms_output.put_line('P_ERRBUFF = ' || P_ERRBUFF);
dbms_output.put_line('P_ERRCODE = ' || P_ERRCODE);
END;
/
exit
ENDOFSQL
fi
done
exit 0
Related
#!/bin/sh
output=ANIL;
#
# Ask user for database inputs
#
echo -n "Enter Database Server Hostname: "
read dba_host
echo -n "Enter Database SID: "
read dba_sid
echo -n "Enter DBA User: "
read dba_usr
echo -n "Enter DBA password: "
read dba_pwd
echo -n "What daemon are we using: "
read daemon_str
#
# Loop to connect to database and exit if something is found
#
while :
do
output=`sqlplus $dba_usr/$dba_pwd#$dba_sid <<+ | grep '^-' | sed 's/-//'
set serveroutput on
DECLARE
command VARCHAR2(50);
return_name VARCHAR2(30);
value VARCHAR2(10000);
status INT;
system_time TIMESTAMP := SYSTIMESTAMP;
WHILE TRUE
BEGIN
status := DBMS_PIPE.RECEIVE_MESSAGE($daemon_str);
IF status = 0 THEN
DMS_PIPE.UNPACK_MESSAGE(command);
END IF;
IF command = "STOP" THEN
DBMS_OUTPUT.PUT_LINE('STOP was encountered') >> file.log;
DBMS_OUTPUT.PUT_LINE(system_time) >> file.log;
BREAK
ELSIF command = "SYSTEM" THEN
DBMS_PIPE.UNPACK_MESSAGE(return_name);
DBMS_PIPE.UNPACK_MESSAGE(value);
EXIT
$value
ELSIF command = "SQL"
DBMS_PIPE.UNPACK_MESSAGE(return_name);
DBMS_PIPE.UNPACK_MESSAGE(value);
EXECUTE IMMEDIATE value;
ELSE
nap(10)
EXCEPTION
WHEN OTHERS THEN
dbms_ouput.put_line('Unknown Input Error') >> file.log;
DBMS_OUTPUT.PUT_LINE(system_time) >> file.log;
DBMS_PIPE.PACK_MESSAGE('done');
DBMS_PIPE.PACK_MESSAGE(status);
status := DBMS_PIPE.SEND_MESSAGE(return_name,10);
END;
dbms_output.put_line(chr(10) || '-' || command);
END;
/
exit
+`
echo $output
done
I am trying to convert a c code block to what you see now a shell script block. I am just a beginner in this coding language and was wanting to know if anyone is seeing something I am not. To sum up what I am trying to accomplish is ask user for the oracle database they want to connect to then keep connection and receive things through pipe. Then the usual of unpacking, outputting errors and such. Then sending it back through same pipe. Any input on possible syntax or anything at all that could be causing this to constantly echo out nothing but blank lines from while loop.
I have a user defined oracle function that returns a number that can be greater than 255. I call that function from a shell script using sql plus, it returns the value, for eg 296, but the scripts accepts it as 40, which is because the script can only accept return codes from 0-255.
This is how i am currently receiving the value
echo ${PASSWORD} | sqlplus ${USERNAME}#${SID} #$SQL getnumber.sql $PARAM> ${LOG}
number=$?
getnumber.sql has
set serveroutput on size 100
VARIABLE rc NUMBER;
call function_get_number('&2') into :rc;
print rc;
exit :rc;
How can i preserve the return value? Should i write it to a file? if so how/where
Script getnumber.sh:
cat << EOF | sqlplus /S /nolog >${LOG}
conn ${USERNAME}/${PASSWORD}#${SID}
set serveroutput on size 100
VARIABLE rc NUMBER;
exec :rc := function_get_number('$PARAM');
SELECT 'RETVAL:' || :rc || ':' theval FROM dual;
EOF
RC=$( grep '^RETVAL:' ${LOG} | cutr -d":" -f2 )
echo $RC
Here is the script which works well when executed in standalone but fails when scheduled as a cronjob,
#!/bin/bash
# TARGET TABLE COUNT FOR Server
#
CURRENTTARGETREF=$(sqlplus -s $DB_USER/$DB_PASS << END
set pagesize 0 feedback off verify off heading off echo off;
SELECT CURRENTTARGETREF FROM PARAMETER
exit;
END
)
TABLENAME="TARGET$CURRENTTARGETREF"
TARGETCOUNT=$(sqlplus -s $DB_USER/$DB_PASS << END
set pagesize 0 feedback off verify off heading off echo off;
SELECT COUNT(*) FROM $TABLENAME
exit;
END
)
echo "Current Target table count in server: $TARGETCOUNT"
#
# COUNTER TABLE COUNT FOR server
#
S1=`echo "SELECT COUNT(*) FROM COUNTER WHERE SERVERID=1;" | sqlplus $DB_USER/$DB_PASS | sed -n '/COUNT(\*)/{n;n;p}'`
S2=`echo "SELECT COUNT(*) FROM COUNTER WHERE SERVERID=2;" | sqlplus $DB_USER/$DB_PASS | sed -n '/COUNT(\*)/{n;n;p}'`
#
echo "Current Counter table count with SERVERID '1' in server:$S1"
echo "Current Counter table count with SERVERID '2' in server:$S2"
#
below is the cronjob for this script
31 01 * * * DS=$(date +\%Y-\%m-\%d); /path/Databasecount.sh >> /path/test.out.$DS.txt 2>&1
And i wanted to send the output of the script to mail and could you someone please help me on this.
I'm trying to return a sqlplus output to a shell script. This may sound simple enough but I've searched online for some time and cannot get my script to work.
Here is my pl/sql script:
SET SERVEROUTPUT ON
DECLARE
X_RETURN_MSG VARCHAR2(32767);
X_RETURN_CODE NUMBER;
BEGIN
X_RETURN_MSG := NULL;
X_RETURN_CODE := 5;
COMMIT;
END;
EXIT X_RETURN_CODE;
Here is my shell script:
sqlplus -s user/pwd <<EOF
#../sql/tester.sql
EOF
RETVAL=$?
echo $RETVAL
$RETVAL always returns 0 even when I have X_RETURN_CODE := 5
X_RETURN_CODE has no meaning outside of the scope of the PL/SQL block where it is declared. You need to use a SQLPlus bind variable.
SQL> VARIABLE return_code NUMBER
SQL> BEGIN
2 :return_code := 5;
3 END;
4 /
PL/SQL procedure successfully completed.
SQL> EXIT :return_code
Disconnected from Oracle Database 10g Release 10.2.0.4.0 - Production
> echo $?
5
My guess is END marks the end of the block and X_RETURN_CODE goes out of scope so it defaults to 0. Or maybe you should look into using the RETURN statement instead of EXIT.
$ sqlplus -s <<!
> / as sysdba
> #tester
> !
PL/SQL procedure successfully completed.
$ echo $?
5
$ cat tester.sql
SET SERVEROUTPUT ON
var X_RETURN_CODE number
DECLARE
X_RETURN_MSG VARCHAR2(32767);
BEGIN
X_RETURN_MSG := NULL;
:X_RETURN_CODE := 5;
COMMIT;
END;
/
EXIT :X_RETURN_CODE;
I have o read values returned by sql stored proc to variables in shell script. I was able to achieve this with single variable but not for two variables.
Oracle stored proc
PROCEDURE get_values (ip_var IN NUMBER,
op_var1 OUT VARCHAR2,
op_var2 OUT VARCHAR2)
IS
BEGIN
SELECT col1, col2
INTO op_var1, op_var2
FROM emp
WHERE emp_id = ip_var;
END;
Calling this proc in unix bash as
sql_status=`sqlplus -silent /nolog << END
whenever sqlerror exit sql.sqlcode
whenever oserror exit -2
set pagesize 0 feedback off verify off heading off echo off scan off serveroutput on
connect $DATABASE
declare
var1 VARCHAR2(20);
var2 VARCHAR2(20);
begin
get_values($input_val, var1, var2);
end;
/
exit;
END`
I need to assign var1 and var2 further in my program. So how can I achieve this?
I know not how to do this interface between PL/SQL (Oracle Server side language) and Unix. You may want to have a jdbc connector for more advanced use.
A solution for your problem is to build an output string directly from the query (or you could use a procedure, and output the result with dbms_output), and process the string in your shell.
Here is how (without procedure):
COL_SEP="%"
RETURN_STRING=`sqlplus -silent /nolog << END
whenever sqlerror exit sql.sqlcode
whenever oserror exit -2
set pagesize 0 feedback off verify off heading off echo off scan off serveroutput on
connect $DATABASE
SELECT col1 ||'${COL_SEP}'|| col2
FROM emp
WHERE emp_id = ip_var;
exit;
END`
echo "RETURN CODE IS: $? "
echo "RETURN STRING : ${RETURN_STRING} "
v1=`echo ${RETURN_STRING} | cut -d${COL_SEP} -f1 `
v2=`echo ${RETURN_STRING} | cut -d${COL_SEP} -f2 `
echo "Variables set: V2:${v2} and V1:${v1}"
And you can do it with dbms_output.put_line in a pl/sql block:
declare
v varchar2(100) := '00';
begin
select 'a'||'${COL_SEP}'||'b' into v from dual;
dbms_output.put_line(v);
end;
/
Hope it helps