Scripting pl/sql from unix
I am wondering if there is a way to do this with certain restrictions. If not, I can do it another way.
1. I have a list of values in a unix .txt file of the form
VALUEA
VALUEB
VALUEC
I know how to read a list in unix using a loop.
2. I want to call a pl/sql anonymous block that I have in a .sql file 1 time for every value in this script and pass the value.
I do know how to read a value and then pass it to a pl/sql parameter and then call the pl/sql parameter.
What I don't know how to do is
Do this with only logging into sqlplus one time. I dont want to do the following
unix runs in a loop
reads 1 record from file
logs into sqlplus
runs the procedure and passes the value
log out of sqlplus
end loop
I want to
1. read all the values from the file
2. store it somehow in memory (variable of some sort)
3. pass this value to the pl/sql procedure
I do not want to make any objects in the database such as a global temporary table.
Yes I can actually do this, but wondering if it is possible to avoid. Makes it easier to deploy to alot of different databases. If I have to make a database object, then i have to make an object in alot of databases. If I can run it all from unix, all I have to do is change the target and the password. So it is easier to deploy.
I don't need to put this in an Oracle Directory. I am not calling anything from pl/sql stored in the database. It is going to all be done with unix scripts and anonymous block sql in .sql statements in the OS. This allows me to take advantage of clustered storage (I can have alot of databases servers mounted on 1 directory). So the unix script will log into oracle and call the .sql script.
I can build the pl/sql dynamically. I'd rather not do that. The thing is I have alot of databases I want to deploy code to. So I am trying to come up with a pattern I can follow. So if I add a new database or what to deploy somewhere else, I can just use add a line to a file.
Adding database objects every time I need to deploy to a new database is a pain. It is far more scaleable to handle all of this in unix.
Edited by: Guess2 on Jan 12, 2010 7:43 AM
Similar Messages
-
Can anybody tell me how to run PL/SQL Procedure from unix prompt.
You can start a sqlplus script from unix prompt, e.g.
sqlplus <youruser>/<yourpassword>@<yourdb> @yourscript.sqlEdited by: hm on 01.01.2011 02:33 -
Shell scripts to migrate from Unix to Linux
Hi All, Can any one let me know what are common issues will face while migrating the shell scripts from Unix to Linux. Thanks in Advance..!
Hi There is windows batch script which uses local variable %DATE% Date format behaves differently across environment In Preproduction : Powercenter9.5.1hotfix2 Windows NT 2008 date format for all users in server machine dd/mm/yyyy (checked regedit/allusers/default/international) Integration service data format day dd/mm/yyyy environment variable INFATOOL_DATEFORMAT is not set The format of this variable is dd/mm/yyyy when batch file is run directly. The format of this variable is dd/mm/yyyy when batch file is run from Informatica. Production : Powercenter9.6 Windows NT 2012 date format for all users in server machinedd/mm/yyyy Integration service data format day dd/mm/yyyy environment variable INFATOOL_DATEFORMAT is not set The format of this variable is dd/mm/yyyy when batch file is run directly. The format of this variable is day dd/mm/yyyy when batch file is run from Informatica. If environment variable INFATOOL_DATEFORMAT is set in production,even then date format is not set to dd/mm/yyyy Where could the issue be? Thanks Kani
-
How could I run sqlplus from an Unix machine?
If want to Install
1. Need to Install Oracle Client
2. Use SQL *PLUS
or
If dont want to install
1. Use iSQLPLUS -
Script fails when passing values from pl/sql to unix variable
Script fails when passing values from pl/sql to unix variable
Dear All,
I am Automating STATSPACK reporting by modifying the sprepins.sql script.
Using DBMS_JOB I take the snap of the database and at the end of the day the cron job creates the statspack report and emails it to me.
I am storing the snapshot ids in the database and when running the report picking up the recent ids(begin snap and end snap).
From the sprepins.sql script
variable bid number;
variable eid number;
begin
select begin_snap into :bid from db_snap;
select end_snap into :eid from db_snap;
end;
This fails with the following error:
DB Name DB Id Instance Inst Num Release Cluster Host
RDMDEVL 3576140228 RDMDEVL 1 9.2.0.4.0 NO ibm-rdm
:ela := ;
ERROR at line 4:
ORA-06550: line 4, column 17:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
( - + case mod new not null <an identifier>
<a double-quoted delimited-identifier> <a bind variable> avg
count current exists max min prior sql stddev sum variance
execute forall merge time timestamp interval date
<a string literal with character set specification>
<a number> <a single-quoted SQL string> pipe
The symbol "null" was substituted for ";" to continue.
ORA-06550: line 6, column 16:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
( - + case mod new not null <an identifier>
<a double-quoted delimited-identifier> <a bind variable> avg
count current exists max min prior sql stddev su
But when I change the select statements below the report runs successfully.
variable bid number;
variable eid number;
begin
select '46' into :bid from db_snap;
select '47' into :eid from db_snap;
end;
Even changing the select statements to:
select TO_CHAR(begin_snap) into :bid from db_snap;
select TO_CHAR(end_snap) into :eid from db_snap;
Does not help.
Please Help.
TIA,
NischalHi,
could it be the begin_ and end_ Colums of your query?
Seems SQL*PLUS hs parsing problems?
try to fetch another column from that table
and see if the error raises again.
Karl -
Run SQL Loader script from Unix env
Hi,
We are using HP-UNIX server. The control file of SQL Loader is placed in oracle home\bin folder in the unix server. I created Executable for this SQL Loader control file in concurrent program and attached into a request group.
Then I ran it from a responsibility, I am getting the below error.
+-----------------------------
| Starting concurrent program execution...
+-----------------------------
SQL*Loader-350: Syntax error at line 16.
Expecting "," or ")", found "TIMESTAMP".
GL_DATE TIMESTAMP 'yyyy MM dd hh:MI:SS:AM',
^
SQL*Loader: Release 8.0.6.3.0 - Production on Sun Sep 5 15:28:45 2010
(c) Copyright 1999 Oracle Corporation. All rights reserved.
SQL*Loader-350: Syntax error at line 16.
Expecting "," or ")", found "TIMESTAMP".
GL_DATE TIMESTAMP 'yyyy MM dd hh:MI:SS:AM',
^
My Actual Control file is,
LOAD DATA
INFILE '/usr/........xyz.txt'
BADFILE '/usr/........xyz.bad'
DISCARDFILE '/usr/........xyz.dsc
APPEND
INTO TABLE gl_interface_stg
FIELDS TERMINATED BY "|" TRAILING NULLCOLS
GL_DATE TIMESTAMP 'yyyy MM dd hh:MI:SS:AM',
CATEGORY_NAME,
JOURNAL_DESCRIPTION,
JOURNAL_NAME,
BATCH_NAME,
BATCH_DESCRIPTION,
ACCOUNT_CODE,
PROCESSING_STATUS CONSTANT 'N'
If I run the above control file from my local machine (windows) using SQLLDR username/pwd @servername control='c:/abc.ctl' from the command prompt, then all the records from xyz.txt file pushed into staging table.
Where as, If I schedule the above control file and trying to run from a GL responsibility, I am getting the above error message.
Do I need to modify the control file scripts in order to run from UNIX environment?
Pls advice how to do it from UNIX environment.
Thanks in advance.Hi,
SQL*Loader-350: Syntax error at line 16.Please see if these docs help.
SQL*LOADER-350 SYNTAX ERROR [ID 1019271.102]
LDR-00350 TOKEN LONGER THAN MAX ALLOWABLE LENGTH ERROR WHEN LOADING ASCII FILE [ID 1020091.6]
Do I need to modify the control file scripts in order to run from UNIX environment?
Pls advice how to do it from UNIX environment.See these docs.
How to Use 9i or 10g Features in SQL*Loader for Apps? [ID 423035.1]
11i FND:How to specify Record Terminator In Sql*Loader type of concurrent program [ID 252850.1]
Thanks,
Hussein -
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 -
Passing params from SQL file to Shell Script and then from Shell to SQL Fil
Afternoon guys,
Have a fun question for all you gurus in shell scripting out there. I have a shell script that is calling 2
different SQL programs. My objective is to pass a variable called request_number from one sql program
to the shell script and then from the shell script back to another SQL program. I will explain why I
need this to happen.
Here is what the shell script looks like which calls sql programs student_load_a.sql and
student_load_b.sql. Student_load_a.sql basically creates the control file (.ctl) which is needed for the
SQL*Loader and then student_load_b.sql reads the table that was just loaded and does the main
processing. My main objective here is to be passing the request_number which is being generated
using an Oracle Sequence in student_load_a.sql and using this generated number in my main
processing in student_load_b.sql to select records from the table based on request_number.
Any ideas ?Any help or recommendations is welcome and appreciated.
*1. Shell Script*
# Accept system input parameters
p_user_id=$1
p_job_id=$2
# Create control files for sqlload
sqlplus.exe -s $p_user_id @$STUDENT_PATH/student_load_a.sql $p_job_id
exit_status=$?
# Do sqlloads
sdesqlldr.exe userid=$p_user_id control=student_load-$p_job_id.ctl \
log=student_load-$p_job_id.log \
bad=student_load-$p_job_id.bad
exit_status=$?
# Main processing
# sqlplus.exe -s $p_user_id @$STUDENT_PATH/student_load_b.sql $p_user_id $p_job_id $p_request_number
sqlplus.exe -s $p_user_id @$STUDENT_PATH/student_load_b.sql $p_user_id $p_job_id
exit_status=$?
exit 0*2. student_load_a.sql (Would like to pass back the Sequence Number back to shell script and then use in student_load_b.sql*
-- Accept system input parameters
define p_job_id = &1
spool student_load-$p_job_id.ctl
select
'append into table TMP_STUDENT_LOAD
FIELDS TERMINATED BY '','' optionally enclosed by ''"''
trailing nullcols
(request_number CONSTANT ' || '''' || request_number_seq.nextval || ''',
student_id)'
from dual
spool off;
exit 0;
{code}
*3. student_load_b.sql (This is a big file so I am only adding code that is relevant for the SQL)*
{code}
declare
v_request_number number(6);
v_student_id number(7);
cursor cur_student_load is
select student_id
from TMP_STUDENT_LOAD
where request_number = v_request_number
order by 1;
begin
v_user_id := '&1';
v_job_id := &2;
-- This is the variable I would like to be be passing from shell script to student_load_b.sql
-- v_request_number = '&3';
open cur_student_load;
fetch cur_student_load into v_student_id;
exit when cur_student_load%notfound;
.... more logic of if then else in here
close cur_student_load;
end;
{code}
Edited by: RDonASnowyDay on Jan 29, 2010 4:03 PMHow come you are mixing WinDoze script (*.exe) with Unix?
You are aware that you will be passing the password along with the user id to the second sql script?
I will assume Unix ksh:
# Accept system input parameters
p_user_id=$1
p_job_id=$2
# Create control files for sqlload
p_seqno=`sqlplus -s $p_user_id @$STUDENT_PATH/student_load_a.sql $p_job_id`
exit_status=$?
# Do sqlloads
sqlldr userid=$p_user_id control=student_load-$p_job_id.ctl \
log=student_load-$p_job_id.log \
bad=student_load-$p_job_id.bad
exit_status=$?
# Main processing
# sqlplus -s $p_user_id @$STUDENT_PATH/student_load_b.sql $p_user_id $p_job_id $p_request_number
sqlplus -s $p_user_id @$STUDENT_PATH/student_load_b.sql \
$p_user_id $p_job_id $p_seqno
exit_status=$?
exit 0And the first sql script would look like this:
-- student_load_a.sql
-- Accept system input parameters
set echo off pages 0 feed off lin 80 trims on ver off
def p_job_id = &1
col seqno NEW_VALUE seqno
select request_number_seq.nextval seqno from dual;
set term off
spool student_load-$p_job_id.ctl
select
'append into table TMP_STUDENT_LOAD
FIELDS TERMINATED BY '','' optionally enclosed by ''"''
trailing nullcols
(request_number CONSTANT ''&&seqno'',
student_id)'
from dual
spool off;
exit 0;
{code}
:p -
Unix script output sql result to terminal
Hi,
I run the script below within a unix script. the query runs but only outputs the first line. I need the whole results output to the terminal.. please let me know if I am doing something wrong. thanks
ORACLE_SID=orcl
export ORACLE_SID
SHELL=/bin/sh
db="username/password"
sqlplus -s $db <<xxx
set serveroutput on
define yy=100
whenever sqlerror exit yy
begin
declare
Dyn_table_name VARCHAR2(100);
Dyn_query_string VARCHAR2(4000);
Type csr_dyn IS REF CURSOR;
csr_dyn1 csr_dyn;
col1 varchar2(200);
col2 varchar2(200);
col3 varchar2(200);
col4 varchar2(200);
col5 varchar2(200);
begin
Dyn_table_name :='''my_table''';
Dyn_query_string :='SELECT b.session_id ,s.serial#,NVL(b.oracle_username,''(oracle)'') AS username,'
||'a.object_name,b.os_user_name FROM dba_objects a,v\$locked_object b,v\$session s'
||' WHERE a.object_id =Upper(b.object_id)and b.session_id=s.sid and a.object_name='||Dyn_table_name;
/*dbms_output.put_line(Dyn_query_string);*/
dbms_output.put_line('SID'||' '|| 'serial#' || ' '||'USERNAME'||' '||'OBJECT_NAME'||' '||'OS_USER_NAME');
dbms_output.put_line('------------------------------------------------------------------------------------');
OPEN csr_dyn1 FOR dyn_query_string;
LOOP
FETCH csr_dyn1 INTO col1,col2,col3,col4,col5;
EXIT WHEN csr_dyn1%NOTFOUND;
dbms_output.put_line(col1||' '|| col2||' '|| col3 || ' ' || col4 ||' '|| col5);
END LOOP;
EXCEPTION WHEN OTHERS THEN
dbms_output.put_line(to_char(sqlcode)|| ' '|| sqlerrm);
end;
end;
set serveroutput off
exit
xxxSorry all your suggestion did not work ( the log file had this error message
Usage 1: sqlplus -H | -V
-H Displays the SQL*Plus version and the
usage help.
-V Displays the SQL*Plus version.
Usage 2: sqlplus [ [<option>] [<logon>] [<start>] ]
<option> is: [-C <version>] [-L] [-M "<options>"] [-R <level>] [-S]
... I know its possible to login into sqlplus and run the querry, but I want it as a script which would output this kind of result to the screen
SESSION_ID SERIAL# USERNAME OBJECT_NAME OS_USER_NAME
251 30330 PRD my table oracle
335 11624 PRD my table oracle
469 2592 PRD my table oracle
849 8619 PRD my table oracle
934 40211 PRD my table oracle
955 15043 PRD my table oracle
is it possible or am I asking for the impossible...!!! I appreciate your suggestion... you can alter the script I put up and paste the correction so that I can see cleary how you made it work for you. -
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 ... -
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? -
Calling a report from unix shell script
Hi,
I had to call a report from unix shell script.
May i know the procedure to accomplish this
Thanks in Advance
A.GopalFirst you should not include the whole path to your report in the call ...
Use like this:
/ora/u01/oracle/v101/as2/bin/rwrun.sh report=an_stati destype=file desname=/ora/u01/oracle/v101/as2/test.pdf desformat=pdf
In $ORACLE_HOME/bin/reports.sh:
1) Verify that you have updated the REPORTS_PATH variable to include your folder where you have the report in question
REPORTS_PATH=/ora/u20/app/qits/env1/run:$ORACLE_HOME/reports/templates:$ORACLE_HOME/reports/samples/demo: ....
2) Verify that the REPORTS_TMP variable is pointing to a valid location and that the oracle user has access to write on it.
After that, post the content of the tracefile located at $ORACLE_HOME/reports/logs/{in-process report server name folder}/rwserver.trc
If no file is present then it means that you need to enable trace in your reports's conf file.... go to the $ORACLE_HOME/reports/conf folder and and locate the .conf file that correspond to your in-process reports server name (as specified in the rwservelet.properties file)... open/edit the file to enable trace logs ..
i.e.
Change the following line:
<!--trace traceOpts="trace_all"/-->
to <trace traceOpts="trace_all"/>
Bounce the reports server and try to run the report again, this time the .trc file should be generated, post the content so that we can take a look. -
Have you moved from Unix/Oracle to Windows/SQL Server
I am looking for people that have moved from Unix/Oracle to Windows/SQL Server...
Would you do it again ?
Did you save money ?
Were you using Zones to virutalize on Unix ?
Did you gain or loose overall Performance ?
Have you had to perform a recovery on SQL Server ?
Have you done a recovery in Oracle ?
Were you using Rman ?
Which worked better ?
We are going through an analysis of does it really make sense, save money and effect performance to move from a strong unix/oracle environment to a MS/SQL environment.
THanks Rob
[email protected]Hi,
All our R/3 legacy systems are Windows/Oracle.
All the new systems (BW, SRM, CRM, XI) are Windows/MSSQL.
It was an order from the management to make the switch because of the high prices of Oracle licences.
The official motto is now Oracle on Unix only and SQL server on Windows only.
We get the same level of performance as with Oracle, but we, old SAP Oracle grumpy admins, are much more comfortable with Oracle admin than SQL server admin.
imho, SQL server may seem simplier but it is much easier to look under the hood whith Oracle.
We have to reinvent the wheel and it's kind of frustrating but we will cope with it...
I would say that SQL server is not a good choice for BW usage because there is a lot more litterature on BW database optimisation for Oracle than MSSQL.
The official SAP class does not speak at all about SQL server but has several chapters on Oracle...
Regards,
Olivier -
Triggering background job event from Unix script
Hi all,
I am having one question regarding triggering of background job in SAP using Events from Unix script. Is this possible? If so, can anyboy provide some sample code related to Unix script and how do we communicate to SAP from Unix system. Actually, here the backend of R/3 system is MSSQL. I am having a program in R/3 system which is scheduled as a background job based upon event trigger. I want to trigger that even from the unix script.
Appreciate for your help in advance.
Thanks,
Adithya KHi,
Check if this can help you
http://help.sap.com/saphelp_sm32/helpdata/en/fa/096e6b543b11d1898e0000e8322d00/content.htm
Regards,
Atish -
Connecting to Windows SQL server from Unix Oracle Server
How can I connect to Windows MS SQL server from Unix Oracle Server? What installation or package will I need?
Two options:
1) Do a search on "Oracle Transparent Gateways" and/or "Heterogenous Services". These are products that are designed solely to connect to other databases from Oracle.
2) Use a type-4 JDBC driver for SQL Server, installed and running in the JVM of your Oracle server. I'm assuming your Oracle database is sufficiently recent to be java-enabled here.
Justin
Maybe you are looking for
-
Getting links and its names from a html file
Hi everyone My problem about the a getting links with name from a html file. For example İn a web page in this site ?SUN? when use click SUN the browser open http://java.sun.com İ want both of them, so the links and name. I can succeeded the get link
-
Error message : hpqwutils.exe no disk device\harddisk1\dr1
Hi, Have been getting this message repeatedly since shortly after starting to use my new HP g6 notebook. Comes up everytime I boot up, have to log back in after time out, and sometimes at launch of a program - drives me crazy! Does anyone know what t
-
Hello! I created a pattern in illustrator, and then I created an object, and I wanted to fill half of the object with the pattern, so I used a clipping mask to do this.. however, now when i try to group everything together, the clipping mask in relea
-
-------Media Center Problem fixing-------
This is work on my system: Control Panel ->Languages -> Special ->Select :English(US) Sorry, if my translating is wrong, but I use hungarian WinXp. The Force be with YOU!
-
ACL rights assignment in new user script
I've been tasked with converting an old new-user script that runs at least once a day written in VB to PowerShell. This script takes as input a CSV file we get from HR that has all necessary info and creates a user, adds them to specific groups based