pl/sql to java shell script
This issue crosses many boundaries, but it begins with PL/SQL, and I hope that there is sufficient expertise here in order to cover the basics.System: Oracle 11.2.0.1.0 on Oracle 5, 64 - bit Linux
I have a PL/SQL, java appeal procedure, which in turn calls a shell script. I put a few diagnostic output in the shell script, the redirection of stdout to a file in / tmp. running the script from the command line works perfectly. When it is called by procedures, no output.
Here is the 'chain of traceability', somehow...
In the PL/SQL:
Host_Command (p_command => v_command||v_control_file||v_orasid);
where the variable v_command = /opt/u01/app/oracle/admin/control/sqlldr3_test.scriptSo this is 'Host_command', the whole procedure procedure:
CREATE OR REPLACE PROCEDURE "DW"."HOST_COMMAND" (p_command IN
VARCHAR2)
AS LANGUAGE JAVA
NAME 'Host.executeCommand (java.lang.String)';
And the shell script /opt/u01/app/oracle/admin/control/sqlldr3_test.script:#!/bin/ksh
export trcfle=/tmp/edstest.$$
export ORACLE_SID=$2
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dwdev
export PATH=$PATH:/u01/app/oracle/product/11.2.0/dwdev/bin
export ORACLE_BASE=/u01/app/oracle
export SQLLDR_CONTROLFILE=$1
#
echo input parms are $* >> $trcfle
echo environment is: >> $trcfle
env|grep -i ORACLE|grep -v grep|sort >> $trcfle
#
exit
but in the end, there is no /tmp/edstest.* fileoracle$ ls -ltr /tmp/eds*
ls: /tmp/eds*: No such file or directory
oracle$
open to all ideas.I cut things down to their bases, but with the exception of the line of the high level process, the code above is finished... is that my test cut original scripts to exactly what is show. Requriement of business is to take existing scripts and remove some of the stuff that is hard coded, allowing procedures move from dev to qa to prod without hardcoded values unique to each environment.
I'm very comfortable with PL/SQL and more with shell scripts, but the java link is a black hole for me.
When the proc of Java runs the external command, a child process of Unix/Linux is created for it. This process inherits the environment settings of the parent process - that would be a dedicated server process, a work process or shared in the pool of the MTS server process.
These processes have parameters of environment of bare bones and something fundamental that + $PATH + should not be approved as being valid and usable.
If the Java code should fully qualify the path to the executable file to run.
Java code should do 2 things - stdout (and stderr if possible) back to the appellant to PL/SQL as vacrhar2 of the parameters out. And return the exit code of the child process.
They help a lot in troubleshooting why an outgoing external call failed.
We use these external calls widely enough (through a number of interfaces, treatments to distance running and pulling on the release of data by the latter in the database). All driven from PL/SQL using the proc of Java to make an outgoing call. If the basics are working-, but there seems to be a constant learning and troubleshooting curve to follow to get this working in a robust way.
Tags: Database
Similar Questions
-
will not appear sql statemnt in shell script
Hello
I have a shell script with an unfavourable sql she calls another script where I connect to dabase.
In the journal of the script, I see the sql statement and I wish that that do not show me anything. How I make these?
Thank you
Hello
2650697 wrote:
Hello
I have a shell script with an unfavourable sql she calls another script where I connect to dabase.
In the journal of the script, I see the sql statement and I wish that that do not show me anything. How I make these?
Thank you
Your postal code. It is very difficult to tell what you're doing wrong without knowing what you are doing.
You can have SQL statements directly in your shell script. They must be in a script by themselves, said fubar.sql, and shell script must contain
@fubar
instead of real SQL statements.
-
Need an example of loop with sql statement in shell script values
Hello
I have to present a simultaneous program to each line of the table through script shell (only).
The table has all the parameters required to pass to the concurrent program.
I have trouble in a loop with the lines of sql statement results.
Could someone give me an example of a shell script with a loop with the sql statement values.
appreciate your time and your help.
Thank you
Ganesh
Hello
Here is a guide using 3 parameters:
{
sqlplus-s $OA_USR / $OA_PWD<>
SET THE OFF POSITION;
SET FEEDBACK OFF;
SET LINESIZE 300;
SELECT param1, param2, param3
Of your_param_table;
ENDOFSQL
} | while reading line
do
If ['$line'] # line non-NULL
then
set $line
param1 = "$1."
param2 = "$2."
param3 = "$3."
# Pass parameters to a script, sql more
sqlplus-s $apps_usr / $apps_pwd @SUBMIT_CONC_PROG.sql $param1 $param2 $param3
FI
fact
}
In your SQL * more script you run 3 parameters into variables:
declare
VARCHAR2 (10) param1: = ' & &1';
VARCHAR2 (10) param2: = ' & &2';
param3 varchar2 (10): = ' & &3';
.....
-
Component sql through shell script
How to call a sql through UNIX shell script file?Rahul India wrote:
export ORACLE_HOME=$ORACLE_BASE/product/10g cd $ORACLE_HOME set `sqlplus -s
/ < THIS SCRIPT IS OK?
You will also need to set ORACLE_SID
And I don't know why everyone puts the reference to sqlplus context of a 'set' assessment, nor why they put the reference to Scripture in a redirected input stream. What you need is
sqlplus -s user/password @r_100.sql
And to make sure the environment is set correctly:
export ORACLE_SID=whatever export ORAENV_ASK=NO . oraenv unset ORAENV_ASK=NO sqlplus -s user/password @r_100.sql
-
Coil PL/SQL parameter value using shell script
Hello
I execute PL/SQL procedure using shell script. I want the value of parameter in a coil OUTPUT text file. to_msg is the IN OUT parameter in the script below. Is this possible?
sqlplus test/***@db < < EOFSQL
COIL Status.txt
HEAD off SET
SET SERVEROUTPUT ON
declare
to_msg varchar2 (8000): = 'status ';
EXEC P_Status (to_msg);
SPOOL off
"exit";
EOFSQLAravindhK wrote:
Thanks for your reply. When I roll the result, sql statements is also copied to the text file. How can I eliminate the sql statements.What are the results when you do as below
sqlplus-s
-
Call the PL/SQL shell script
Hi all
I've seen several links and options for calling a PL/SQL shell script. I was wondering if there is something like DBMS_SCHEDULER. CREATE_PROGRAM-> executable that calls an external program in 11 GR 2.
Here's what I have to. I have 11 GR 2 database with Dataguard. I have START triggering who begins a DBMS_SERVICE when the role becomes PRIMARY. In the same instance, I would stop the VIP on the former primary database and start the VIP on the new primary database.
Thanks for the advice and assistance.
Jan S.The URL below links to ask Tom. Inside, he talks about creating a Java procedure in your database that allows you to execute commands from the host OS (PL/SQL calls the proc of Java that runs the host command). There are several ways to run the OS commands, but this one is very flexible. I needed to use it for a task that I have who didn't fit one of the other methods very well.
http://asktom.Oracle.com/pls/Apex/f?p=100:11:0:no:P11_QUESTION_ID:3069633370832
-
How to execute the pl/sql shell script
Hi Experts
I need to be able to call a pl/sql procedure shell script
Linux and 11g
I am new to java and followed the solution below
The appeal of OS in Plsql commands
After following the solution on top of link
Declare
x Varchar2 (2000);
Begin
x: = OSCommand_Run ('ls - the);
-print x;
DBMS_OUTPUT. Put_line (x);
End;
/
give me output of 0 but the command is not executed.
What must be changed or is there another solution?
Thank you
ArchanaSee if that helps...
[http://www.oracle-base.com/articles/8i/ShellCommandsFromPLSQL.php]
-
Call Shell Script from within PL/SQL - using DBMS_PIPE
Hi all
I'm trying to run a shell script inside my PL/SQL using DBMS_PIPE block (not sure if this is the right way or not)
Pl Sql script
==========
Set serveroutput size 100000
declare
cursor c1 is select * from mag_images
where nom_image like '% comp2.
v_path varchar2 (100): = ' / home/maguzzi/DOCUMENTS_DIR / ";
v_result number: = 0;
v_in_filename varchar2 (100): = v_path | ' test_file.jpg';
v_out_filename varchar2 (100): = v_path | ' test_file_out.jpg';
v_script varchar2 (100): = "tst_convert.sh";
v_command varchar2 (200): = 'sh'. v_path | v_script | » '|| v_in_filename | » '|| v_out_filename;
Start
A1 to c1 loop
dbms_output.put_line ('v_command: ' | v_command);
write_to_file ('test_file.jpg', 'DOCUMENTS_DIR', a1. Content);
dbms_output.put_line (' file write result: ' | v_result);
v_result: = exec_host_command (v_command);
dbms_output.put_line (' resize result :'|| file v_result);
end loop;
end;
Result DBMS_OUTPUT
====================
v_command: /home/maguzzi/DOCUMENTS_DIR/tst_convert.sh test_file.jpg test_file_out.jpg
Result of the entry of the file: 0
Result of resizing the file: 0
PL/SQL procedure successfully completed.
Function exec_host_command
=======================
FUNCTION to CREATE or REPLACE exec_host_command (lc_cmd IN VARCHAR2)
RETURN INTEGER IS
ln_status NUMBER;
lc_errormsg VARCHAR2 (80);
lc_pipe_name VARCHAR2 (30);
BEGIN
lc_pipe_name: = 'Maguzzi_PIPE ';
DBMS_PIPE. PACK_MESSAGE (lc_cmd);
ln_status: = dbms_pipe.send_message (lc_pipe_name);
RETURN ln_status;
END;
/
The Image of the BLOB is written to the correct location on the server "test_file.jpg", and although the exec_host_command function returns a value of 0, the shell script (tst_convert.sh) is not executed (i.e. no output file is created - outfile.txt and the image is not copied/converted to a new file name "" test_file_out.jpg" )
Shell script
========
tst_convert.sh
echo 'Here' > outfile.txt
Echo $1 > > outfile.txt
Echo $2 > > outfile.txt
resizing to convert $1 - $200 2
Could this be problems with permissions on files?
test_file1.jpg has permission - rw-rw-r-
test_convert.sh a permission rwxrwxrwx
When I run the script manually and pass in 2 parameters ($1 = infilename and $2 = outfilename), it works...
I'd appreciate if someone can point out my mistake or suggest another method that works.
Thanks in advance
How long does it take to create the converted file? Remember that the external Scheduler is running asynchronously, so it is possible that the converted file does not exist yet when the PL/SQL block subsequently tries to open it.
Try to add some delay seconds to the routine to ensure that the external task is completed:
begin dbms_scheduler.create_job( job_name => 'MAG_IMAGE_CONVERT2' , job_type => 'EXECUTABLE' , job_action => '/home/oracle/DOCUMENTS_DIR/tst_convert2.sh' );-- '/home/oracle/DOCUMENTS_DIR/tst_convert.sh'); dbms_scheduler.enable('MAG_IMAGE_CONVERT2'); dbms_lock.sleep(3); end;
This probably isn't really a viable solution in the long term if it turns out that this is really the problem.
-
Using the shell script sql variable
OS: Oracle Linux 5.10
DB Oracle 11.2.0
I have need to query the database and assign the return value to a variable of shell, but it does not work.
create table imr_env (key varchar2(1000), value varchar2(1000) ; insert into imr_env values('TblspcUsagePct','90'); commit;
Here is the shell script:
#!/bin/bash echo "in script" ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1 ; export ORACLE_HOME ORACLE_SID=IMR1 ; export ORACLE_SID export PATH=$PATH:$ORACLE_HOME/bin pct=`sqlplus -S app/manager <<END set serveroutput on declare output_val number ; BEGIN select value into output_val from imr_env where key = 'TblspcUsagePct' ; dbms_output.put_line('output_val: ' || to_char(output_val)) ; END ; / exit; END` ## another sqlplus connection, use $pct in the where clause echo "var value is $pct"
Here is the result:
SQL> ./test.sh in script var value is output_val: 90
Why isn't the shell variable is populated with the value retrieved from the database?
I need to use $pct in another query that will be storage spaces that are at least 90% full.
I had to change to a korn shell - I couldn't get the "READ" command in shell or bash.
But it is not only "READ" command:
SQL > select * from IMR_ENV;
THE KEY VALUE
------------------------- -----
TblspcWarningLimit 90
TblspcUsagePct 50
SQL > exit
Disconnected from the database to Oracle 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
With partitioning, OLAP, Data Mining and Real Application Testing options
$ cat test.sh
VAL = $(sqlplus-S test/test)<>
Set feedback off
set the position
Select (value) from imr_env, including the key to_number = "TblspcUsagePct";
Select (value) from imr_env, including the key to_number = "TblspcWarningLimit";
"exit";
EXPRESSIONS OF FOLKLORE
)
set $VAL
Echo $1
Echo $2
$./test.sh
50
90
$ echo $SHELL
/ bin/bash
$
-
How to validate SQL * MORE connection in Unix shell script
I wrote the following function in unix shell script to validate SQL * MORE connection and throw a user-defined message.
function check_db_conn
{
output | sqlplus-s-L $User/$Password@$SID >/dev/null
If [[$?-no 0]]; then
echo 'credentials incorrect DB.
FI
}
However, I would like to change this feature so that the user has entered a good connection and that there is a problem with TNS listener must display the appropriate message.
Hello
Try adding:
lsnrctl status $listener_name > /dev/null if [[ $? -ne 0 ]]; then echo "Issue with Listener" fi
-
Hi people
I have this code in my shell script, but I get the below error please check
Please help me on thissqlplus -s scott@xyz/tiger @1.sql > 1.log and oracle home is /oracle/app/oracle/product/11.2.0/dbhome_1 error thrown is Error 6 initializing SQL*Plus SP2-0667: Message file sp1<lang>.msb not found SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory i have checked i have sp1us.msb
Newbie says:
Mr President, I gave my oracle home.How to check if she properly o?
No, you said that you believe that oracle_home should be. But you have NOT proven that it was properly defined in the session that threw the error and the error itself is almost certain evidence that it was NOT set correctly. And your assertion that the referenced file exists (again, your assertion, not proof) gives more weight to the evidence that ORACLE_HOME is not set correctly.
Run the following commands, and then copy and paste the whole session (complete order, full power) to your next assignment
env |grep ORA|sort echo $PATH sqlplus -s scott@xyz/tiger @1.sql > 1.log
-
Why the sql statement was extucted twice in shell script?
I tried to test the rac load balancing using the shell script depending on suse 10 + oracle 10g rac.
After run the shell script, I got the result to follow.oracle@SZDB:~> more load_balance.sh #!/bin/bash for i in {1..20} do echo $i sqlplus -S system/oracle@ORA10G <<EOF select instance_name from v\$instance; / EOF sleep 1 done exit 0
Seem that the sql statement was run twice in each loop. If you help please take a look. Thanks in advance.oracle@SZDB:~> ./load_balance.sh 1 INSTANCE_NAME ---------------- ora10g2 INSTANCE_NAME ---------------- ora10g2 2 INSTANCE_NAME ---------------- ora10g1 INSTANCE_NAME ---------------- ora10g1 3 INSTANCE_NAME ---------------- ora10g1 INSTANCE_NAME ---------------- ora10g1
RobinsonBecause you have one; and one.
-
Need to call the Shell script that uses SQL loader in APex4.1 / 11g
Hello!
I have a requirement in which I need to call a shell script that connects to an external server, FTP to a file and then use sqlloader to load data into our table. We have now the ftp script that accomplishes this task to another program, but is a scheduled task. I wanted to call the script ftp in the APEX. Any suggestions on how this can be done, what is the logic of PL/SQL can we use? I saw online some people using DBMS Scheduler for this?
Thank you
SunHello
Create some sh script on your computer host oracle where you can join in the external server and run the process.
something like:run_external_sh.sh
#!/bin/sh ssh ext_user@ext_host ./sqlloader/import/import.sh
Then create an external TASK to call it via ORACLE (PL/SQL)
-Shell Script call.
BEGIN DBMS_SCHEDULER.create_program ( program_name => 'external_call_sh', program_type => 'EXECUTABLE', program_action => '/local_host/call_external/sh/run_external_sh.sh', number_of_arguments => 0, enabled => TRUE, comments => 'Call external SH script'); END; /
You can now create a regular / or unplanned WORK
-Job defined by the calendar and an existing program.BEGIN DBMS_SCHEDULER.create_job ( job_name => 'jb_external_call_sh', program_name => 'external_call_sh', schedule_name => 'external_call_scheduler', -- created scheduler enabled => TRUE, comments => 'Job defined by an existing external_call_sh program and schedule.'); END; /
You can now call the WORK in the APEX in the process of PL/SQL.
BEGIN -- Run job synchronously. DBMS_SCHEDULER.run_job (job_name => 'jb_external_call_sh'); END;
Concerning
J :D -
Unable to see the serveroutput sql shell script
Hello experts,
I have a shell script that I use to call a pl/sql procedure.
This proc write dbms_output.
I would like the dbms_output in a capture file when calling sqlplus to my shell script.
Here is the code:
===============================
ECHO '.
sqlplus apps / $APPS_PWD < < ENDOFSQL
Set serveroutput ON
Set feedback off
set verify off
set linesize 250
set pagesize 250
Start
jdr_utils.listcustomizations('$I');
end;
/
output
ENDOFSQL
"> > new.log"
===============================
What I get in the "new.log" is given below:
===============================
sqlplus apps/prj08app < < ENDOFSQL
Set serveroutput ON
Set feedback off
set verify off
set linesize 250
set pagesize 250
Start
jdr_utils.listcustomizations('/Oracle/Apps/IRC/candidateSelfService/WebUI/VisVacDispPG');
end;
/
output
===============================
ENDOFSQL
I want to get is the given procedure dbms_output.
Please suggest.
Thank you
VinodShell?
Your call to sqlplus is between double quotes. (In ksh, at least) who gets taken literally (after substitution of the variables). To run the chain and echo its output use a backtick (') instead of a double quotation mark ("")
Published by: Brian Bontrager Sep 29, 2011 15:51
-
Capture to users running sql in shell script after every 10 minutes
Hi all
We have a strange problem. crash of database, so decided to check that users make when OS/DB crashes.
I need your RACE/SCHEDULING of entry into such a script, which includes all active users with SQL running and add to a log file so that we are aware of what has past when DB/OS crashed.
I can run this race a query V$ SESSION, V$ SQL and V$ PROCESS but I need your ideas in writing a SHELL Script and scheduling can work via CRON.
Kind regards.Or better yet
sqlplus /some_report_file. 'date + %m-%d - hour %M %Y'
Maybe you are looking for
-
Recent calls from contacts with multiple numbers
Gents If I for example XYZ contact with several numbers with the same name (for example: 123 mobile, mobile 456) When I call or receive a call missed this contact, if I open recent tab and selected information from the record, he mentions just all th
-
Write table 1 d to drop at specific sampling frequency
Hey everybody! I'm back to ask what probably is another simple question. I have 6 cells of custom load that are read in a sub - VI. The Subvi is inside a loop for, which is inside a structure of the case, which is inside a while loop. Here's what it
-
How to access the BIOS on an Acer Aspire V3 - 571 G-9636
How to access the BIOS on an Acer Aspire V3 - 571 G-9636. I want to disable UEFI and secure boot. I tried pressing F2, from switching on the laptop of a closed state. I tried to hit once, several times he spamming on boot to the top. The laptop still
-
We have 1 pool with 3 membersI want to delete 1 member of a group.Is it wisely in production time? or wil this slows down the performance on my group?
-
It lacks a computer on my new USB mass storage device.
When I plug my two sticks of SanDisk U3 into my computer, my brand new computer does not recognize them. I passed to the Device Manager and looked under controller universal serial bus, while it is in my USB and the mass storage deivce is not display