PL/SQL function - unix shell script
Hello,
I have an application that calls a unix shell script This unix shell script calls a oracle function in the PL/SQL package. For example,
In package pkg_test, there is function f_test. This function returns pls_interger.
How can I write a unix shell script to return the value from the oracle function, so that the application can get the value from the unix shell script?
Many thanks.
Thank you for your response.
The Oracle functuion pkg_name.proc_name will return different values, 0, 1, 2, 3 in diffefrent conditions.
The unix script, myscript.ksh calls pkg_name.proc_name.
The other application will call myscript.ksh and this application will need to get the values 0, 1, 2, 3 from myscript.ksh.
Can we make it without using the unix shelll function?
Thanks.
Edited by: slsam01 on Jun 2, 2009 9:21 PM
Similar Messages
-
Unix shell script run from pl/sql procedure
Hi Guru
I want to run unix shell script from pl/sql procedure. Actual I want to run it from developer 10g form.
Please guide me in this regards
Regards
JewelLook at the host or client_host builtins in the help
-
How to prepare for Converting UNIX shell scripts to PL/SQL
Hi All
I was said, that i may have to convert a lot of unix shell script to PL/SQL, what are the concepts i need to know to do it efficently,
what are the options PL/SQL is having to best do that.
I know the question is little unclear, but I too dont have much inputs about that i'm sorry for that, just its a question of how
to prepare myself to do it the best way. What are the concepts i have to be familiar with.
Many Thanks
MJJust how much work is involved, is hard to say. Many years ago I also wrote (more than once) a complete ETL system using a combination of shell scripts, SQL*Plus and PL/SQL.
If the PL/SQL code is fairly clean, uses bind variables and not substitution variables, then it should be relatively easy to convert that PL/SQL code in the script to a formal stored procedure in the database.
There is however bits and pieces that will be difficult to move into the PL/SQL layer as it requires new software - like for example FTP'ing a file from the production server to the ETL server. This can be done using external o/s calls from within PL/SQL. Or, you can install a FTP API library in PL/SQL and FTP that file directly into a CLOB and parse and process the CLOB.
Think of Oracle as an o/s in its own right. In Oracle we have a mail client, a web browser, IPC methods like pipes and messages queues, cron, file systems, web servers and services, etc. And PL/SQL is the "shell scripting" (times a thousand) language of this Oracle o/s .
In some cases you will find it fairly easy to map a Unix o/s feature or command to one in Oracle. For example, a Unix wget to fetch a HTML CSV file can easily be replaced in Oracle using a UTL_HTTP call.
On the other hand, techniques used in Unix like creating a pipe to process data, grep for certain stuff and awk certain tokens for sed to process further... in Oracle this will look and work a lot different and use SQL. -
Unix Shell Script -- ORA-00905 error in pl/sql
Below is my unix shell script .... in which i am trying to caluclate difference between time stamps ..... i am getting a severe error when i run --- ORA-00905: missing keyword ( included it bottom of this post )
please look into this and let me know where to correct ....
much appreciated in adv
~~~~~~~~~~~~~~~~~~~~~START of Script~~~~~~~~~~~~~~~~~~~~
#!/bin/ksh
export readTime checkTime timeDiff
# Get initial Time
readTime=`sqlplus -s scott/tiger@database <<EOF
whenever sqlerror exit 1
set escape off
set head off
set verify off
select SYSTIMESTAMP from dual;
EOF
`
echo "readTime value is : $readTime"
# Get end of time
checkTime=`sqlplus -s scott/tiger@database <<EOF
whenever sqlerror exit 1
set escape off
set head off
set verify off
select SYSTIMESTAMP from dual;
EOF
`
echo "value of checkTime : $checkTime"
# calculate time diff
timeDiff=`sqlplus -s scott/tiger@database <<EOF
whenever sqlerror exit 1
set escape off
set head off
set verify off
select CAST(TO_DATE('$time2','''YYYY\/MM\/DD:HH24:MI:SS'''))-CAST(TO_DATE('$VAR1','YYYY-MM-DD:HH24:MI:SS')) from dual;
EOF
`
echo "value of timeDiff : $timeDiff"
~~~~~~~~~~~~~~~~~OUTPUT here ~~~~~~~~~~~~~~~~~~~~~~~
readTime value is :
02-DEC-05 12.07.53.779328 AM -06:00
value of checkTime :
02-DEC-05 12.07.54.013613 AM -06:00
value of timeDiff : 02-DEC-05 12.07.54.013613 AM -06:00','''YYYY\/MM\/DD:HH24:MI:SS'''))-CAST(TO_DATE('
ERROR at line 2:
ORA-00905: missing keywordYou didn't specify if you want a total time for a portion of a shell script, or the whole script in general. If you only want to know the time of the whole shell script, just reference the linux/unix built-in variable ${SECONDS}. This variable is reset for each PID.
I usually add these lines to the bottom of long running shell scripts (just before an exit code):
~~~~~~~~~~~~~~~~~~~~~~~~~
((TIME = ${SECONDS} / 60))
echo "Script ran for ${TIME} minutes. (${SECONDS} seconds total.)
~~~~~~~~~~~~~~~~~~~~~~~~~
Like I said, ${SECONDS} starts ticking from 0 when you start the script, so no need to export the variable, just reference it. The nice part is that you don't have to bother getting into sqlplus and hit the database. -
How can i call a Stored Procedure procedure from Unix shell script
Hi All,
I want to call a Strored PL-SQL Procedure through Unix shell script.
Can any body help me with this.
Regards,
SaurabhI prefer a seperate script like the other poster mentioned. However, most shells can use a 'here' document as well ...
sqlplus uid/pwd <<END
exec myproc
exit
ENDRichard -
Sending email attachments using unix shell script
hi
I want to send report generated my spooled file as attachment using unix shell script.
Can somebody help me out ?
many thanksthanks a tonn it worked.
but i have another issue is it possible to add names in CC also ?
Also here is my code which spools the output of SP to a txt file. the File name is generated dynamically.
as shown below:
I need to send this generated file as attachement.
how do I do this? Here the shell script
=========================================================
#!/bin/sh
ORA_USER=scott
ORA_PWD=tiger
#Get the input parameter
if [ ! "$1" ]; then
STR="NULL"
else
STR="'"$1"'"
fi
#echo "exec pkg1($STR);"
#Connecting to oracle
sqlplus -s <<EOF
$ORA_USER/$[email protected]
---sql plus enviornment settings
set linesize 160
set pagesize 60
set serveroutput on size 1000000 for wra
set feedback off
set termout off
column dcol new_value mydate noprint
select to_char(sysdate,'YYYYMMDDHH24MISS') dcol from dual;
spool &mydate.report.txt
exec pkg1($STR);
spool off
EOF
exit
=========================================================
the file name will take sysdate as name so that every time a new file will be generated.
this file I need to send as attachment.
null -
Calling stored procedure from unix shell script
Hello,
I am facing a problem while calling a stored procedure from UNIX shell script. I want to return a output variable from the stored procedure to the UNIX environment.
Here is the code-
#!/bin/sh
OUTPUT=`sqlplus cmag/magnum@dw <<ENDOFSQL
set serveroutput on;
var prd_out varchar2(100);
exec create_pm_window(:prd_out);
exit;
ENDOFSQL`
echo " output is - $OUTPUT"
The problem is :prd_out is not getting copied to shell variable OUTPUT.
I have a dbms_output.put_line in the stored proc create_pm_window and I can see that prd_out is getting populated.
Any help is really appreciated.
Thanks'
RakheeFirst step :
make sure the PL/SQL works as expected.
Does the following display the expected output executed from SQL*Plus ?
set serverout on
declare
prd_out varchar2(100);
begin
create_pm_window(prd_out);
dbms_output.put_line('output is '||prd_out);
end;
I don't have your procedure, but using a dummy procedure like :
Scott@my10g SQL>create procedure foo(p_out in out varchar2)
2 is
3 begin
4 select 'Hello '||instance_name into p_out from v$instance;
5 end;
6 /
Procedure created. and a toto.sh script as :OUTPUT=`sqlplus -s scott/tiger <<EOF
set pages 0 lines 120 trimout on trimspool on tab off echo off verify off feed off serverout on
var mavar varchar2(100);
exec foo(:mavar);
print mavar;
exit;
EOF`
echo "OUT = ${OUTPUT}"
exitIt works fine :[oracle@Nicosa-oel ~]$ ./toto.sh
OUT = Hello my10g -
Unable to pass parameter in oracle procedure through unix shell script
Hi Experts,
I have oracle procedure where in I have to pass the value of procedure parameter through unix script.
Follwoing is the sample procedure which i tried to exceute from the unix.
Procedure:
create or replace procedure OWNER.PRC_TESTING_OWNER(OWNER IN VARCHAR2) AS
sql_stmt varchar2(1000) := NULL;
v_count number := 0;
v_owner varchar2(100) := owner;
begin
sql_stmt:='select count(1) from '||v_owner||'.EMP@infodb where rownum<=10';
execute immediate sql_stmt into v_count;
DBMS_OUTPUT.PUT_LINE(sql_stmt);
DBMS_OUTPUT.PUT_LINE(v_count);
END;The script which I used is:
Unix
#!/bin/ksh
parm=$1
echo start
sqlplus -s scott@DEV/tiger <<EOF >>result_1.txt
set serveroutput on;
select '$parm' from dual;
exec owner.PRC_TESTING_OWNER('$parm');
EOFThe script is working fine that is i am able to pass to parameter value through unix shell script. :)
But if I want to pass the value of the owner in cursor , I am unable to pass this value through unix.
Following the procedure which i am trying to implement.
create or replace procedure OWNER.PRC_TESTING_OWNER(OWNER IN VARCHAR2) IS
v_owner varchar2(100) := owner;
CURSOR main_cur IS
select
i.ROWID rid ,
emp_name,
deptid
from v_owner.employee;
CURSOR subset_cur(c_deptid NUMBER ) IS
SELECT *
FROM v_owner.DEPT d
where d.dept_id=c_deptid;
--##main loop
FOR i IN main_cur LOOP
FOR j IN subset_cur(i.deptid) LOOP
BEGIN
insert into v_owner.RESULT_TABLE
END;
END LOOP;
END LOOP;How can i pass parameter value of the stored procedure through unix script(that is "owner" in this case), when these parameter value is
used in cursor? :(
Can anybody help me regarding the same?
Thanks in Advance !! :DIt's not the parameter in the cursor that is the problem, it's that you are trying to use static SQL for something that won't be known until run time (the owner of the table).
You would need to use something like ...
declare
l_owner varchar2(30) := 'SCOTT';
l_ref_cursor sys_refcursor;
type l_ename_tab is table of scott.emp.ename%type;
l_ename_array l_ename_tab;
begin
open l_ref_cursor for
'select ename
from ' || l_owner || '.emp';
loop
fetch l_ref_cursor bulk collect into l_ename_array limit 10;
exit when l_ename_array.COUNT = 0;
for x in 1 .. l_ename_array.count
loop
dbms_output.put_line(l_ename_array(x));
end loop;
end loop;
close l_ref_cursor;
end;
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.01 -
Call Unix Shell Script From OBIEE
Hi All,
Is it possible to do a call to a Unix Shell Script with the Action Framework from OBIEE.
Thanks in AdvanceI dont think so but we can go for it instead of BI side. Try to port the same functionality on shell script side, so that the script can identify your report using tail of nqquery log and execute the rest of your lines in shell script.
This can doable and works as expected. If at all you are going with my suggestion you can go for a small key word to identify your report instead of that lengthy logical query.
Pls mark if helps -
RFC_REMOTE_PIPE is Returning 1 alwasys and not able to execute Unix shell script
Hello All,
I am trying to execute a simple unix shell script from ABAP.
What I did so far..
1. created a test.sh file with single command echo "Hello".
2. placed this file on application server /Usr/sap/test.sh
3. executing ABAP program which as FM RFC_REMOTE_PIPE
CODE:
CALL FUNCTION 'RFC_REMOTE_PIPE'
DESTINATION 'SERVER_EXEC'
EXPORTING
command = lv_command
read = 'X'
TABLES
pipedate = lt_stdout
EXCEPTIONS
system_failure = 1
communication_failure = 2.
if i populate lv_command = echo "hello" it works fine
if i give .sh file path in lv_command it is not working. it returns 1.
Please help...
I was searching SDN i found that rfcexec service should be enabled... how do i check that..
i checked t code \SMGW , i don't see any output...
i checked FM GWY_READ_CONNECTED_SYSTEMS, i don't hsee anyting related to unix...
Please suggest.I resolved the issue.
It was issue with permission.
Script file should have full permission ( Mode 777)..
Thanks everyone. -
R/3 to other oracle system Unix Shell scripts Execute
Hi,
Here SAP 4.7 version, is it any possibility to run/execute other oracle system Unix shell scripts from sap program?
With Regards,
Anil...yes,
1.define own external command (sm69)
2. run this command from your ABAP code by callig function module SXPG_COMMAND_EXECUTE
regards,darek -
Return codes from sqlldr command from unix shell script
I am trying to capture error code from sql loader from unix shell script and display proper messages.
sqlldr parfile=sdb.par control=$cntlfile data=$infile bad=$badFile log=$logFile rows=10000
rows=10000
retcode=`echo $?`
case "$retcode" in
0) echo "SQL*Loader execution successful" ;;
1) echo "SQL*Loader execution exited with EX_FAIL, see logfile" ;;
2) echo "SQL*Loader execution exited with EX_WARN, see logfile" ;;
3) echo "SQL*Loader execution encountered a fatal error" ;;
*) echo "unknown return code";;
esac
Eventhough, there are errors while executing sqlldr, it is always returing recode zero. What could be the possible reason
Please adviceIs there a typo in your code ?
sqlldr parfile=sdb.par control=$cntlfile data=$infile bad=$badFile log=$logFile rows=10000
rows=10000
retcode=`echo $?` In this code, you get the return code of the statement in bold which is not the sqlldr statement ... -
Calling linux / unix shell scripts from APEX
Hi -- I'm doing some prototyping, and would like to try calling a unix shell script on the server from within APEX.
Is this possible? Maybe thru Javascript? Other ways? Not sure if it's possible thru pl/sql.
FYI, I'm attempting to check username/password specified at login to see if it's a valid login
to another database (also specified at login). If there's an easier way to do this, I'd love to hear it!
We're highly motivated to have a single apex app work on multiple databases -- largely because of a lack of
administration resources on the other databases. All databases are accessible via database links from
the apex server (the links are necessary to implement other business rules), and I know I can get
the DML working. Powers that be prefer that Database Account authentication (or a facsimile thereof)
be used. I suspect I'm opening myself up to lots of criticism by disclosing this ... :)
Thanks for any ideas,
CarolR -- If I understand you correctly, a pl/sql process in APEX could invoke a java program on the server. Is that correct?
If so, is there any reason it couldn't just call a unix shell script? Seems they're both just executables recognized by the OS....
I know I called unix scripts from embedded sql a billion years ago, but don't recall the method for doing that. What is
the syntax I'd use in apex / pl/sql?
thanks,
Carol -
Execute stored procedure from Unix shell script
My current method of executing stored procedures (wpl_1 and wpl_2) from a unix shell script is as follows:
<<wpl.sh>>
sqlplus user/password @/home/oracle/scripts/wpl.sql
<<wpl.sql>>
set serveroutput on size 1000000
set timing on
execute wpl_1('0000010676','~')
execute wpl_2('0000010676','~')
execute wpl_1('0000010236','FIX')
execute wpl_2('0000010236','FIX')
exit
Question: Is it possible to combine the two scripts (unix and oracle) together?A little rusty on this, but this may work:
My current method of executing stored procedures
(wpl_1 and wpl_2) from a unix shell script is as
follows:
<<wpl.sh>>sqlplus user/password @/home/oracle/scripts/wpl.sql << EOF
set serveroutput on size 1000000
set timing on
execute wpl_1('0000010676','~')
execute wpl_2('0000010676','~')
execute wpl_1('0000010236','FIX')
execute wpl_2('0000010236','FIX')
exit
EOF
>
Question: Is it possible to combine the two scripts
(unix and oracle) together? -
Execute a unix shell script from forms9i
Hi ,
I would like to execute a unix shell script form a form when they pressed a button. The forms server is on Linux machine. I tried but when I pressed the button nothings happen. Could some one please help me how I could get working.
Is there is a way I could execute the unix shell script from PL/SQL proceudre or package.
Please some one help me.
BainYou would not expect to see anything happening because the
script cannot directly send output to the web form. However, you can get it to write output to a file and use web.show_document in the form after the host command to display the file and see the output.
Maybe you are looking for
-
Sender JDBC support the stored procedure in SQL Server 2005
Dear All, My question here is , Sender is JDBC adpter support to call the Stored procedure in Microsoft SQL Server 2005? I followed the below thread before posting this question Sender JDBC Adapter Supports Stored Procedures???? In the thread Suraj r
-
Missing text in Slideshow version of a Classic book?
I ordered three copies of a Classic book last night. I played the iPhoto book as a slideshow this morning and some critical text is missing from two pages in the slideshow version (the book still looks complete in my iPhoto 6). All of the pages with
-
Create folder with multiple files (was: folders)
Can you create a folder with multiple files and direct the page to go to the folder and then the reader can select the file they wish to choose? Example Council Mintes Folder with a file for each set of minutes. The hyperlink would open the folder
-
Ipod touch and new computer!
I had installed itunes on my old computer, the hard drive failed and I had to insall a new hard drive, having done so when I plug in my Ipod touch it indicates that I have to resync my ipod to the new machine, but this will mean I lose all my music.
-
hello everyone, I have SGE2010 switches and I want to implement Multiple VLAN's. Im a newbie and starting to study VLANS's I want to implement 5 VLAN's on my test lab network and here as follows: 192.168.1.x default 192.168.2.x 192.168.3.x 192.168