Calling an Oracle stored procedure in Informatica Cloud postprocessing command - oracle

I have an Informatica data synchronization task that creates a table in Oracle. I am trying to include a call to an Oracle stored procedure in the postprocessing command of Informatica Cloud that will update a variety of tables at the completion of the task. The procedure that I am trying to call is in the same schema as the target of the synchronization task. The procedure runs correctly when I run it directly in Oracle SQL Developer, but I can't get it to run via Informatica Cloud. I know I'm not using the right syntax to make the call, but these are some examples that I have tried so far:
BEGIN
(PROCEDURE_NAME)
END;
CALL(PROCEDURE_NAME);
EXEC(PROCEDURE_NAME);
PROCEDURE_NAME;
Would designing a mapping in Informatica Cloud help me with this? Or is there a prefix that I should be appending to the stored procedure call, even though the procedure is in the same schema as the target of the task?

None of these options will work in Synchronisation task. Call (procedure_name); will work in Mappings which is the easiest way to do it
In Synchronisation task you need to create a batch file to run a SQL script. The script has to contain the connection details.
Example:
connect user/password#
exec (procedure_name);
disconnect;
exit SQL.SQLCODE
SQL.SQLCODE is used so that it will commit all the transactions.
After that, it will be necessary to use a .bat to run the above sql script using sqlplus client.
Example:
cd \bin
call cmd.exe /C "sqlplus /nolog < {path to sql script created in step
2}\filename.sql"
exit /b 0;

Related

Run batch oracle queries in multiple database

I have 4 Database connection in SQL developer(oracle). At evening I have to regularly run some scripts in all the 4 connection on same server. Is there is any shortcut that I run script only once and is reflected in all connection which is connected to some DB.
(NOTE: All the 4 connection will hold exactly same info.)
Can anyone suggest how to do this?
Here's how I do that: using the command prompt capabilities, not GUI. The only prerequisite is to have SQL*Plus installed on your computer.
For example, create SQL script you're about to run and save it into C:\Temp directory; let's name it "my_script.sql". It can contain both SQL and PL/SQL (don't forget to terminate it with a slash in that case!).
Here's how it should look like:
connect &2
spool &1
set echo on
set define off
-- Your SQL statements go here:
select to_char(sysdate, 'dd.mm.yyyy hh24:mi') vrijeme from dual;
begin
pkg_payments.p_gimme_my_money;
commit;
end;
/
-- End of your SQL statements
spool off
exit
Then create a DOS batch script, let's name it "run_my_script.bat" and put such a code in there:
#echo on
set SCRIPT=C:\Temp\my_script.sql
set SCRIPT_LOG=C:\Temp\my_script
if not exist %SCRIPT% goto END
start sqlplus.exe /nolog #%SCRIPT% %SCRIPT_LOG%.site_1.log "username_1"/"password_1"#(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=host_1_name)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=service_name_1)))
start sqlplus.exe /nolog #%SCRIPT% %SCRIPT_LOG%.site_2.log "username_2"/"password_2"#(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=host_2_name)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=service_name_2)))
start sqlplus.exe /nolog #%SCRIPT% %SCRIPT_LOG%.site_3.log "username_3"/"password_3"#(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=host_3_name)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=service_name_3)))
start sqlplus.exe /nolog #%SCRIPT% %SCRIPT_LOG%.site_4.log "username_4"/"password_4"#(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=host_4_name)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=service_name_4)))
:END
As you can see, it
sets local variables (SCRIPT, which points to a .SQL file you
created) and SCRIPT_LOG which contains log information about script's
execution)
invokes SQL*Plus (in parallel; if you want them to execute
serially, just remove the START keyword), connecting to each database
and running the script
The simplest way to test it is to double-click the .BAT file; it'll open 4 "black" command prompt windows and terminate them once the SQL script finishes its job. Check the LOG files!
When you're satisfied with the outcome, schedule .BAT file's execution in Task Scheduler so that they are executed regularly & automatically.
That would be all, I presume.

Oracle OCI API RMAN Commands

When I try to execute the "delete noprompt archivelog until time ‘SYSDATE-1’;" command using "OCIStmtExecute" function ,
I am getting an error like "ORA-00933: SQL command not properly ended"
Is this the correct command to delete ARCHIVE logs? Whether it is possible to execute RMAN commands using OCI API ? Are there any OCI functions to delete ARCHIVELOGS (log truncation) ?

Executing an sql script vi an OCI8 connection object

I have a locally running oracle thin client and have successfully created a ruby script to connect to a remote oracle database. I successfully make a call (select * from table_name) to the database to get the content of a table:
begin
con = OCI8.new('<user>', <password>, '<host>:<port>/XE')
con.exec('select name from actor') do |records|
puts records
end
rescue OCIError
puts "Database Connection Error"
end
I also want to run an sql script that resides in the oracle directory on the remote host.
Usually I perform the following:
su - oracle
sqlplus <user>/<password>
<SQL> #<script_name>
and this will run the script
In the ruby script I try the following:
con.exec('#<script_name>')
Yet, I get the following error:
stmt.c:230:in oci8lib_200.bundle: ORA-00900: invalid SQL statement (OCIError)
#<script_name> is an sqlplus command.
When sqlplus find #<script_name>, it opens <script_name>, divides its contents to SQL statements and executes them.
If you want to run SQL statements in a script by ruby, you need to write code which opens the script, divides its contents and pass SQL statements to con.exec one by one.
I also want to run an sql script that resides in the oracle directory on the remote host. Usually I perform the following:
No, it can't. sqlplus reads the sql script that resides on the local host.
You can put this script in a function (function_name) and execute
con.exec("select function_name from dual")

Does SQLPlus exit after running a script?

We are using CA Workload Control Center (Autosys) to run a windows batch file which calls another batch file which calls SQLPlus with the following:
sqlplus username/password %1 %2 %3
Since this is all being done remotely I cannot see what is actually happening on the server.
I am wondering if the sqlplus file exists but has invalid syntax (like referring to non-existent table) will the sqlplus prompt exit and return back to the batch file?
The reason I ask is because I am looking at the log file from Autosys and it shows that SQLPlus call was made, it prints out ERROR AT LINE 2: Invalid Table, but then it does not show any other activity with the batch script after that where there are multiple echoes and file copies etc. It seems as though it is not exiting SQLPlus perhaps?
Is there a parm I need to pass to SQLPlus to tell it to exit SQLPlus and return back to the calling script after running a SQL script if it fails?
Edit: We are using "WHENEVER SQL ERROR" inside of our SQL files as well and the log file does show this:
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
But I am still expecting that it should continue with the rest of the Batch script but its not, above is the last that Autosys shows in the log
See SQLPlus instruction WHENEVER SQLERROR, it describes in Oracle docs:
http://docs.oracle.com/cd/B19306_01/server.102/b14357/ch12052.htm
Found the solution SO Post:
You can do sqlplus -l test/Test#mydatabase #script.sql; the -l flag means it will only try to connect once, and if it fails for any reason will exit instead of prompting. Look at the output of sqlplus -?, or see the documentation.

How to make a sqlplus quit when database is not available?

i have a problem with sqlplus on windows batch.
I have SQLPLUS 10.2
i'm trying to connect to a database through a windows script.cmd
script.cmd only launches : sqlplus test/Test#mydatabase #script.sql
The problem is when the database is not available, the sqlplus says
ERROR:
ORA-12541: TNS:no listener
Enter user-name :
and waits for input .. and blocks the .cmd
How can i adapt the script to stop immediately when the database is not avaliable or just to avoid waiting for user prompts ?
Thanks
You can do sqlplus -l test/Test#mydatabase #script.sql; the -l flag means it will only try to connect once, and if it fails for any reason will exit instead of prompting. Look at the output of sqlplus -?, or see the documentation.
may be you should think about using TNSPING utility. You can use it within CMD script before trying to connect to db with sqlplus. In this case you should analyse its output.
You can try with 2 connects.
First one will spool result to a file.
In the second one check what is in that file. If you don't encounter ORA-12541 or any other error messages then call the second script.
You can make all these commands inside one batch script and call it with
SQLPLUS #script.sql
and inside use
connect test/Test#mydatabase

Resources