I would like to use strace to debug a strange behaviour I have with db2. I have a SQL function myFoo() implemented in C that doesn't get called for some reason (some code access path not existing or not authorized see here). My Sql Function call a function Fooin shared library in /usr/local/lib/libmyfoo (so in db2 term /usr/local/lib/libmyfoo!Foo).
If I use strace directly with db2 and the query I have an error saying
A database connection does not exist
so i created a script call debug.sh with the following. The idea is to have a shell with the db2 connection active and trace it.
db2 "connect to MYDB"
db2 "select * from table(myFoo())" # this calls /usr/local/lib/libmyfoo!Foo
db2 "disconnect MYDB"
It doesn't work cos I realized that strace works with binary so I have the error
Exec Format Error
Probably you are calling each DB2 command in different subshells.
You can fix that problem by executing everything in just one subshell, for example
VALUE=$(. /home/db2inst1/sqllib/db2profile ; db2 connect to MYDB ; db2 "select * from table(myFoo())")
My Sql Function call a function Foo in shared library in /usr/local/lib/libmyfoo (so in db2 term libmyfoo!Foo).
Is this really how you defined your function? libmyfoo!Foo will point to the library $INSTANCE_HOME/sqllib/function/libmyfoo. If your library is elsewhere you need to provide the absolute path to it.
Related
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;
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")
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.
32-bit mongo 2.0.1 on a windows XP machine
//script filename: test.js (one line shell script file to store a person)
db.cTest.save({Name: "Fred", Age:21});
run against database dbTest by entering the following 2 shell commands:
> use dbTest
switched to dbTest
> load("test.js")
So far, so good.
But if I try and include the "use" statement in the script it fails:
//script filename: test.js (including "use" statement)
use dbTest;
db.cTest.save({Name: "Fred", Age:21});
fails with error msg as follows:
> load("test.js")
SyntaxError: missing ; before statement
Mon Dec 19 11:56:31: Error: error loading js file temp.js (shell):1
Adding or removing semicolons to test.js doesn't seem to matter.
So how do you put a "use" directive into a mongo shell script?
In a mongo script you can use the db.getSiblingDB('new_db_name') to get a reference of a new database. So, it it not mandatory to give the database name in the command line. You can use the script.js:
db = db.getSiblingDB('new_db_name');
print(db);
// the rest of your code for database "new_db_name"
and the output of this script is (invoked with mongo script.js):
MongoDB shell version: 2.2.2
connecting to: test
sag
http://www.mongodb.org/display/DOCS/Scripting+the+shell
use dbname
This command does not work in scripted mode. Instead you will need to explicitly define the database in the connection (/dbname in the example above).
Alternately, you can also create a connection within the script:
db2 = connect("server:27017/otherdbname")
Well, it still is unfortunate that "load('file.js')" and "mongo file.js" don't actually use the same script interpreter as the interactive mongo shell. Opening the connection explicitly in the script is potentially a violation of the DRY principle because mongo already knows that information. What does work, though, is piping the file into mongo rather than passing its name on the command line:
mongo <file.js
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