Calling a function in a stored procedure
How to call a function in a stored procedure
Oracle 11g
Declare
varname DATATYPE ;
BEGIN
varname:= <Function Name> ;
END;
You have to understand the other bits by yourself.
Read more details at http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/overview.htm#sthref192
Similar Messages
-
Can is call store function similar to stored procedures
iam trying to call a stored function written in database similar to stored procedures .Is it possible to call funtion if yes can anybody tell me how to call ,please yar.its urgent
I believe I already answered your question [url http://forum.java.sun.com/thread.jspa?threadID=645317&messageID=3801352#3801352]here
-
Wrapped in a function and/or stored procedure, recursive CTE stops working
This query builds an hierarchical tree from a single table with the typical
value/reports_to_value columns.
When running in SQL manager returns like 7 records (note i'm avoiding infinite
loop by blocking top level value)
WITH c
AS
SELECT deptid, reports_to_dept
FROM glo_tree
WHERE deptid = '18538'
UNION ALL
SELECT t.deptid, t.reports_to_dept
FROM glo_tree T
INNER JOIN c
ON t.deptid = c.reports_to_dept
where t.deptid <> '00001'
SELECT deptid
FROM c
However, the exact same query, if wrapped in a function and/or stored procedure,
returns 0 records (no error message whatsoever)
CREATE FUNCTION [dbo].[checkDept] (@deptid varchar(16))
RETURNS TABLE
AS
RETURN
WITH c
AS
SELECT deptid, reports_to_dept
FROM glo_tree
WHERE deptid = @deptid
UNION ALL
SELECT t.deptid, t.reports_to_dept
FROM glo_tree T
INNER JOIN c
ON t.deptid = c.reports_to_dept
SELECT deptid
FROM c
GO
CREATE PROCEDURE [dbo].[getDept] (@deptid varchar(16))
AS
SELECT deptid
FROM dbo.checkDept(@deptid)
Then call them like:
select * FROM checkDept('18538')exec getDept @deptid='18538'
Both return nothingThanks Patrick, i don't think it can do that, i call it like:
select * FROM checkDept('18538')exec getDept @deptid='18538'Just to make sure, i've changed the function like:WHERE ltrim(rtrim(deptid)) = @deptidStill the same thing -
How to convert REFCursor functions to REFCursor Stored Procedure
Is it possible or not.How to want convert REFCursor functions to REFCursor Stored Procedure.For Example
function QR_1RefCurDS return pkg_sa_reprts_ref_cursr.pa_mis_sa_disp_cursr is
data_cursr pkg_sa_reprts_ref_cursr.pa_mis_sa_disp_cursr;
begin
data_cursr:= sf_sa_dispatch_reprt(:P_USER,:P_USER_TYPE,:P_AREA_CD,:P_RPT_LEVEL,:P_PARNT_GROP,:P_LOCTN_CD,:P_DATE);
return data_cursr;
end;
how to convert it.Its possible. But you need to analyse the requirement well. Post conevrsion, you need to take care of places in the code where the function call is made to invoke the new procedure.
create procedure QR_1RefCurDS_pr (out pkg_sa_reprts_ref_cursr.pa_mis_sa_disp_cursr) is
data_cursr pkg_sa_reprts_ref_cursr.pa_mis_sa_disp_cursr;
begin
data_cursr:= sf_sa_dispatch_reprt(:P_USER,:P_USER_TYPE,:P_AREA_CD,:P_RPT_LEVEL,:P_PARNT_GROP,:P_LOCTN_CD,:P_DATE);
end; -
Call a Vbscript from a stored procedure
Hi,
I wonder is it possible to call a Vbscript from a stored procedure, any good reference for this.
thanksWell here is quick and dirty example I just created.
Step 1. Create a test_batch.bat file that creates a folder "c:\test_dir" and copy "c:emp.lst" into it.
C:\oracle102\examples\test_batch.bat
md c:\test_dir
copy c:\emp.lst c:\test_dir
Step2. From SQLPLUS, spool scott.emp into c:\emp.lst and call the batch from the dbms_scheduler that kicks off right away,
set echo off
set feedback off
spool c:\emp.lst;
select * from scott.emp;
spool off;
begin
dbms_scheduler.create_job(job_name => 'run_batch',
job_type => 'EXECUTABLE',
job_action => 'C:\oracle102\examples\test_batch.bat',
start_date => sysdate,
enabled => true,
comments => 'Run VB Script');
end;
Check if the directory is created and if the file is copied over. Task is to kick off the executable and test is the VBscript within the batch. Challenge is how long the script runs before the next statement in the PL/SQL runs. May be you have to introduce sleep in between.
Note: You must have at least "CREATE JOB" privilege.
Happy coding!
Prakash
Message was edited by:
Prakash Rai -
How to call javascript function from PL/SQL procedure
Can anybody advice me how to call javascript function from PL/SQL procedure in APEX?
Hi,
I have a requirement to call Javascript function inside a After Submit Process.
clear requirement below:
1. User selects set of check boxes [ say user want to save 10 files and ticks 10 checkboxes]
2. user clicks on "save files" button
3. Inside a After submit process, in a loop, i want to call a javascript function for each of the file user want to save with the filename as a parameter.
Hope this clarify U.
Krishna. -
Executing a Function in a Stored Procedure to Return Cursor
I have a function named f_CPCRBPBR who base on the following types
CREATE Or Replace TYPE RecType_fAC
AS OBJECT ( << Structure >>);
CREATE Or Replace TYPE Tbl_fAC
AS TABLE OF RecType_fAC;
Create Or Replace
Function f_CPCRBPBR (
i_Vtp Varchar2,
i_Mnth Varchar2,
i_Location Varchar2,
i_vno integer,
i_vnoTo integer,
St_Date Varchar2,
En_Date Varchar2
Return TBL_fAC
Pipelined
Is
RetVal RecType_fAC;
Begin
Now the problem is that I want to Call this Function from Within a Procedure who would return the Recordset..
can any body suggest..
I want to use the Record Type used for the Said Function..
Please Help..This is Excellent .. This is great.. actually this is marvellous.. can u please defined a bit about Sys_RefCursor...
this is an excellent thing..
I finally Concluded the procedure as follows who not only called but also returned the cursor..
Create Or Replace Procedure p_CPCRBPBR (TstCrsr In Out Sys_RefCursor,
i_Vtp Varchar2,
i_Mnth Varchar2,
i_Location Varchar2,
i_vno integer,
i_vnoTo integer,
St_Date Varchar2,
En_Date Varchar2
as
Begin
Open TstCrsr FOr
Select * from Table(f_CPCRBPBR (i_VTP, i_Mnth, i_Location, i_VNo, i_VNoTo, '', ''));
End;
Can u please help me what will be the exact syntax to call / test this procedure in SQL Developer..
as if i try this procedure as
Execute p_CPCRBPBR null, 'CP', '01', 'L', 1, 1, null, null
it give error Invalid SQL Statement ..
2. Can u please check this code and refer me a solution for Calling this function
create or replace function NewTest (iEN Integer)
return sys_refcursor
as
rc sys_refcursor;
begin
open rc for select * from Scott.Emp Where EmpNo=iEN;
return rc;
end;
This function easily created but when i tried to execute this with the following statement
Select * from Table(NewTest (7369))
It gives error
Cannot Access Rows From a Non-Nested Table Item..
.. Thanx for ur patience... -
Calling JPA from a Java Stored Procedure
Is it possible to call JPA from a java stored procedure? If so, does anyone have example? How do you setup the persistence.xml?
How does the peformance compare with straight JDBC in a java stored procedure?
Thanks for any help!
JohnnyHi Johnny:
Basically you can run any JDK 1.5 framework inside your Oracle 11g JVM, I have experience integrating Lucene IR library as a new [Domain Index for Oracle 11g/10g|http://docs.google.com/View?id=ddgw7sjp_54fgj9kg] .
I am not familiar with JPA internals but my advice is howto handle the connection inside the OJVM and the configuration files.
Some time ago I took a look to SpringFramework integration and I found that writing a new ApplicationContext class which handles the loading of beans.xml from XMLDB repository instead a file should be enough to work.
Another important point is the life cycle of the [Oracle internal JVM|http://download.oracle.com/docs/cd/E11882_01/java.112/e10588/chtwo.htm#BABHGJFI]. Unlike an standard JVM the OJVM is created once you first connect from the middle tier at OCI level and remains in execution during the connection pool existence.
I mean, if you connect using a JDBC pool the JVM will remains running across multiple soft open/close connections of your middle tier application. This is good because you can read your persistence.xml file using a Singleton class and this expensive operation will be re-used by multiple open/close operation done from the middle tier.
I suggest you do a simple Proof of Concept with a Hello World application and check if it works.
Remember that any security issues will be notified to the .trc files, security issues are related to the strong security layer configured by default inside the OJVM, for example you can not read any files from the OS file system without an specific grant, you need another grant to access to the class loader and so on, but you can simply grant this specific needs to a database role and then grant this role to the user which connect to the OJVM.
Another important point is related to the [End-of-Call Optimization|http://download.oracle.com/docs/cd/E11882_01/java.112/e10588/chtwo.htm#BABIFAAI] this can be useful if you want to perform some clean up in your Singleton class at the level of per-statement execution.
Best regards, Marcelo -
How to execute a procedure or function from Java Stored procedure
Hi,
I am new to Java Stored Procedures. I am working on Oracle 8i and JVM 1.3.1. I want to call a PL/SQL procedure from within Java. I have tried looking at severa; cources but they are quite high level for me. Can someone provide a simple example including the Source Code for .java file and also the calling function's code?
Heres a sample of what I have been working on: I an including Java code, and Function code and how I call the function. Instead of doing "select sysdate from dual" I want to do like "create table temp1(var1 varchar2(10))" or similar... like "exec procname(var1)" etc.
Thanks in advance.
PS. The variable passed in function is just a dummy variable.
-----Begin Java code-------
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.ResultSet;
//Oracle Extensions to JDBC
import oracle.jdbc.driver.OracleDriver;
public class Test2{
public static String Testing(String d) {
Connection connection = null; // Database connection object
try {
// Get a Default Database Connection using Server Side JDBC Driver.
// Note : This class will be loaded on the Database Server and hence use a
// Se[i]Long postings are being truncated to ~1 kB at this time.what your after is
Connection conn = DriverManager.getConnection
("jdbc:oracle:oci:@<hoststring>", "scott", "tiger");
CallableStatement cs = conn.prepareCall ("begin ? := foo(?); end;");
cs.registerOutParameter(1,Types.CHAR);
cs.setString(2, "aa");
cs.executeUpdate();
String result = cs.getString(1);
a more complete description can be found in the documentation at
http://download-west.oracle.com/docs/cd/B10501_01/java.920/a96654/basic.htm#1001934
Dom -
Calling Java programs from Oracle Stored Procedure
Is it possible to call Java programs from Oracle stored procs? If possible Can this be used to exchange data from other applications? Is there a better method/feature in oracle for doing data exchange with other apps?
If what you mean by Oracle stored procedures is pl/sql then yes.
You can create a "wrapper" this way:
CREATE OR REPLACE FUNCTION xmlXform
in_mapUrl IN VARCHAR2,
in_inputUrl IN VARCHAR2
RETURN VARCHAR2
AS
LANGUAGE JAVA NAME
'com.yourcompany.xml2any.xform(java.lang.String,java.lang.String)
RETURN java.lang.String';
Then load the java as:
loadjava -user youruser/youruserpasswd -resolve -verbose lib/xmlparserv2.jar classes/com/yourcompany/xform.class classes/com/yourcompany/xml2any.class
The java, given the correct permissions, can do anything java can do including communicate with outside applications.
Is this the "best" way... depends on what you are trying to accomplish. -
Calling a report from a Stored Procedure
Is it possible to call a Oracle Report from a Stored Procedure or a Packaged Stored Procedure. If Yes, please provide some details.
Thanks
ShaluShalu,
there's an API available to do this.The feature is called "event driven publishing" (because you can use this even from a trigger) and you can find the documentation here:
http://download-uk.oracle.com/docs/cd/B14099_17/bi.1012/b14048/pbr_evnt.htm#sthref1870
Regards
Rainer -
Hello,
I am trying to execute a SSIS package from SQL Server 2008 R2 stored procedure but getting error code 1 (as per my knowledge, error code description is as below:
0 The package executed successfully.
1 The package failed.
3 The package was canceled by the user.
4 The utility was unable to locate the requested package. The package could not be found.
5 The utility was unable to load the requested package. The package could not be loaded.
6 The utility encountered an internal error of syntactic or semantic errors in the command line.
Details:
I have a stored procedure named "Execute_SSIS_Package" (see below sp) which executes 'Import_EMS_Response' SSIS package (when I execute this package directly from SQL Server BID it works fine it means package itself is correct) and calling
it from SQL as:- EXEC Execute_SSIS_Package 'Import_EMS_Response'.
Here I receives error code 1.
Can anyone help me to resolve this issue please?
Thanks in advance!
CREATE PROCEDURE [dbo].[Execute_SSIS_Package]
@strPackage nvarchar(100)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @cmd VARCHAR(8000)
DECLARE @Result int
DECLARE @Environment VARCHAR(100)
SELECT @Environment = Waarde
FROM Sys_Settings
WHERE Optie = 'Omgeving'
--print @Environment
SET @strPackage = '"\W2250_NGSQLSERVER\BVT\' + @Environment + '\' + @strPackage + '"'
SET @cmd = 'dtexec /SQL ' + @strPackage + ' /SERVER "w2250\NGSQLSERVER" /Decrypt "BVT_SSIS" /CHECKPOINTING OFF /REPORTING E'
--print @cmd
EXECUTE @Result = master..xp_cmdshell @cmd, NO_OUTPUT
--print @Result
ENDIt has something to do with the security.
E.g. cmdshell is not enabled or the caller has not rights over the package.
There could be a syntax error, too.
I suggest you make the package runnable off a SQL Agent job then trigger the job from the stored proc with
sp_start_job <job name>
Arthur
MyBlog
Twitter -
Using writetext function in a stored procedure for Sybase 11.5
Hello,
I need to execute the writetext function inside a Sybase stored procedure to insert varchar data of approximately 4k size.
how to specify data parameter in writetext fot that?The split function Scott used is some variant on one of the solutions posted in the Ask Tom link I posted. More specifically, it is probably a variant on either one of the pipelined function solutions, or one based on splitting the string into a SQL table of objects.
Look at Tom's original response to the question for a working solution. If you have a reasonably new version of Oracle, then you may also want to look at the modificataion/modernization later in the thread which can be found here
HTH
John -
Calling external servlet from java stored procedure
Hello,
I need to call an external servlet which is in 9iAS server ( unix box) from Java Stored procedure in oracle database.
Can anybody give me an idea? is it possible?
Thanks,
ViswaI am trying the same. Here is URL which will help u.
http://otn.oracle.com/sample_code/tech/java/jsp/samples/wsclient/Readme.html
Let me know when you run servlet successfully.
Regards
Satish -
Problem while calling webservice from a plsql stored procedure
Hi everybody,
I need to call a webservice from a plsql stored procedure.
I was following documentation published in the otn at the following link.
"http://www.oracle.com/technology/tech/webservices/htdocs/samples/dbwebservice/DBWebServices_PLSQL.html"
I am encountering the following error on my sql prompt-
SQL> exec dbms_output.put_line(time_service.get_local_time('94065'));
BEGIN dbms_output.put_line(time_service.get_local_time('94065')); END;
ERROR at line 1:
ORA-29273: HTTP request failed
ORA-06512: at "SYS.UTL_HTTP", line 1022
ORA-12545: Connect failed because target host or object does not exist
ORA-06512: at "APPS.DEMO_SOAP", line 65
ORA-06512: at "APPS.TIME_SERVICE", line 13
ORA-06512: at line 1
Has anybody worked on the same example. Please direct me.
Thanks & Regards
Kiran KumarKiran, were you able to solve this?
I am facing the same error.
Oracle Server is Unix and webservice is .NET.
I am able to connect to Java web service.
Maybe you are looking for
-
Issue in 'SO_NEW_DOCUMENT_SEND_API1' Function Module
Hi All, I have a problem when using the Function Module 'SO_NEW_DOCUMENT_SEND_API1'. I am able to send data to SAP Users Email ID's using this function module, but the issue here is when i am sending the content and receivers lists all are working fi
-
CR, Documents and Links, delete file from room
Dear collegues, I'm using Collaboration Room template, which uses standard page "Documents and Links", extention "Documents". My problem: We can add files or folders to room, but we cannot delete them (even with admin role) in the same interface. The
-
WLS 5.1 SP8 clustered machines do not acknowledge each other on startup
I have made this posting in In-Memory-replication group also. We are trying to setup a cluster with two machines A & B. These are Solaris boxes with WLS 5.1 and SP8. The servers are multi-homed. When the two We
-
Start up problem: goes to console prompt, can't get to GUI (ADVANCED ISSUE)
Running 10.4.7 on a Mac mini with PPC. When I boot, I see the progress bar complete, then the screen goes blue and I see the spinning cog and it goes to the black screen with a text darwin console prompt asking for login. Once I login at this prompt
-
I've seen related posts but I can't get a clear answer. My daughter's current flat-panel iMac runs Sims very slowly. For that, and other reasons it's time for a new iMac for her. The 20 inch, 2GH seems to meet the requirement from Aspyr, but some pos