Executing Stored proc from UDF - oracle

is it possible to execute a stored procedure inside a user defined function in Oracle 10g database?
If yes, could you please give en example?
Thanks.

Sure you can. See for example The last example in Oracle® Database SQL Reference
10g Release 1 (10.1) Create function
The example uses a package but can also be a stored procedure. No problems.
What is your problem?

Related

calling oracle stored procedure using custom data types in perl

I have a stored procedure defined in oracle whose parameters are objects defined in oracle.
I need to invoke it through perl. I have looked but couldnt find any reference about it.
Could anyone help me out for the same ?
Thanks,
Why don't you write another Oracle procedure in which you can use your oracle-objects and call your target procedure? You could then call this new procedure by perl with standard parameters.
Bad architecture but should work...
(Sorry can't just comment)

call a sql function stored in a separate db server from a stored procedure

I have a SQL function stored in a db server and want to call it from a stored procedure in a separate sever.Is that possible? In case it is possible, please provide an example.
To call stored procedures/functions or simply call some sql queries from remote database you can use DATABASE LINKS. To create such database link you can call:
CREATE DATABASE LINK database.name.com
CONNECT TO scheme_you_want_to_connect_to IDENTIFIED BY password_to_the_scheme
USING service_name;
When you create database link, you should be able to call the procedures like this (assuming you have sufficient grants):
mySchema.myPackage.myProcedure('some', 'params', 'you', 'want', 'to', 'pass')#database.name.com
I'm sure you will find lots of other examples in the web.

NHibernate calling Oracle stored procedure with schema prefix, how?

I have NHibernate calling stored procedure in Oracle working currently. However, how do I specify a schema prefix in the {call} syntax in the tag?
I tried
<sql-query name="my_sproc">
<return class="my_sproc_class" />
{call schema2.my_sproc (:p1)}
</sql-query>
But NHibernate run-time came back with 'schema2' not defined while 'schema2' is a definitely defined schema on my Oracle db.
thanks.
Could it be privileges ? The procedure may exist in that schema but you may not have privileges to execute it, or you may have privileges through a role that isn't enabled.
Could be parameters. If the procedure expects two parameters (or is a function) then trying to call it with one can get a "Doesn't exist" error when it really means "There isn't one I can call with just one parameter".
Final option is if you have a package in your schema with the same name as the other schema. Can happen with something generic like 'UTILS'. If you ask Oracle to execute UTILS.PROC and you have a UTILS package, then it will look in the package and throw an error if it doesn't find it, even if there is a UTILS schema with a procedure PROC.
Edited to add
In that case, I'm leaning towards a parameters issue
The example here seems to use ? as the parameter placeholder.
I could be mistaken here, but I thought that NHibernate requires all UDFs/SPROCS to be prefixed with "dbo"; does {call dbo.schema2.my_sproc (:p1)} work?

cfquery oracle stored procedure

I had to change the SQL stored procedure to ORacle stored procddure.I am able to successfully execute my modified stored procedure in oracle.
But unable to obtain the query result in CF for the Oracle stored-Procedure.I have used <cfquery>.
Any suggestions or tips to for using an Oracle stored proc/CF-8?
Think you need cfstoredproc, not cfquery.
See manual page for more details.
It does really depend on how it reacts, i'd test your stored proc in oracle sql+plus first, to make sure it returns data, then try it via cfquery or stored procedure...

Oracle sql types over dblink

I have two schemas: A and B (Oracle 9). At the A there is a dblink to B. At the B there is a package, that i calls from A. Procedures in B package can returns varying count results and i think that returning a collection is a better way for this reason.
create type B.tr_rad as object (
name varchar2(64)
,code number
,vendor number
,val varchar2(255)
,num number
);
create type B.tt_rad as varray(256) of B.tr_rad;
But from A scheme I cannot use tt_rad type because using SQL-types by dblink is not supported. DBMS_SQL is not supported cursors. Create types with same OID is impossible.
I think to use temporary tables. But firstly it is not that good (after the remote function returns the value, calling side must select collection from remote table). And there are fears of a slowdown of work with temporary tables.
Maybe who knows the alternative interaction?
I've had similar problems in the past. Then I came to the conclusion that fundamentally Oracle's db links are "broken" for anything but simple SQL types (especially UDT's, CLOBS may have problems, XMLType may as well). If you can get the OID solution working then good luck to you.
The solution I resorted to was to use a Java Stored procedure, instead of the DB Link.
Characteristics of the Java Stored Procedure:
Can return a "rich set of types", just about all of the complex types (UDT's, tables/arrays/varrays) see Oracle online documentation for details. Oracle does a much better job of marshalling complex (or rich) types from java, than from a DBLink.
Stored Java can acquire the "default connection" (runs in the same session as the SQL connection to the db - no authentication issues).
Stored Java calls the PL/SQL proc on the remote DB, and the java JDBC layer does the marshaling from the remote DB.
Stored Java packages up the result and returns the results to the SQL or PL/SQL layer.
It's a bit of work, but if you have a bit of java, you should be able to "cut and paste" a solution together from the Oracle documentation and sample.
I hope this helps.
See this existing discussion
referencing oracle user defined types over dblink
An alternative interaction is to have one database with schemas A and B instead of two databases with a database link.
My solution.
On the side B i create temporary table like the collection record. At the A side i have a DBMS_SQL wrapper that calls procedure over dblink. This procedure writes result collection in the temporary table. After successful completion remote procedure i select results from remote temporary table and transform it to local collection type.
Limitations
1. the need for permanent object synchronization.
2. impossibility use A-side procedure (that call remote procedure) in SQL query.
3. the complexity of using.

Resources