Call proc from a package
I had a package with several procedures. Now, the requirement is to include a call to a new standalone procedure not a part of the package.
The proc in the package has the cursor and I need to use this data into the proc I called from main, but out of the package.
This is a sample. Please, do not correct if there's a the syntax gap. I need the principle how to call proc1, proc2, with the same cursor data gathered from main which is still in the package.
Here is the sample:
create package body my_package as
procedure main as
cursor abc
select * from my_table where date > sysdate-1;
begin
v_rec_type := rec;
--( v_rec_type is declared in the packade header as my_table rowtype variable)
for rec in... loop
If rec.type = 1 then
proc1;
elsif rec.type = 2
proc2;
else
null;
end if;
end loop;
end main;
end;
create procedure proc1 as
v_rec_type my_table%rowtype;
begin
if v_rec_type.data_1 = 'INS' then
do this;
else
do that;
end if;
--do some stuff
end;
Thanks a lot for the help.mj
Well, I also see the discussion on OraFAQ, but your original question said:
--v_rec_type is declared in the packade header as my_table rowtype variable)
If you have this variable declared in the spec, you can access it from the other procedure since you are populating it in the procedure in the package. It doesn't matter that the cursor declaration is not in the spec - the variable is based on the table%rowtype, not the cursor%rowtype. Based on what you have said, there is no need to pass a parameter to the procedure.
Similar Messages
-
NetBeans: Calling code from other packages?
Normally, when I would call code from eclipse, I would type something like:
import +<package name>.<class name>+But somehow, this approach doesn't seem to work in NetBeans, how can I import code from another package? I can seem to import from the same package, but not a different one.
Edited by: px7659 on Jun 15, 2010 6:21 PMpx7659 wrote:
Normally, when I would call code from eclipse, I would type something like:
import +<package name>.<class name>+But somehow, this approach doesn't seem to work in NetBeans, how can I import code from another package? I can seem to import from the same package, but not a different one.Then the package is not part of the project. Did you perhaps forget to add the jar library in question? -
Calleing dbms_job from a package owned by someone else.
I have a package, called database_job, which acts as a api to dbms_job. I have created a public synonym and granted execute to public.
Problem is whan I call this procedure from a user trying to alter one of there jobs I get the error ora-23421: Job x is noy in the job queue.
Basicaly database_job is owned by app_user and the user who owned the job is bob. My quess is that dbms_job is being run as app_user, not bob, even though the user calling database_job is bob.
does this make sence and has anybody got a way round this problem.
Regards,
BenIs your database_job package defined as an invoker's rights package? Or as a definer's rights package? The default is definer's rights, but if you specify AUTHID CURRENT_USER you'll get invoker's rights. If (and only if) the invoker has privileges to do something will the procedure be able to do it.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
Call Function from SSIS package
Hello. I have a field pulled from an Access database that I need to manipulate before processing. I need to strip out illegal characters. What's the best way to use a function to process the data in the table. I was hoping to do this
within the package if possible.
From within Access, a query passed values to a function defined within a code module and returned the new value. The SSIS package needs to be able to do this as well.Hi,
You can can remove the illegal characters in the package. On your Data Flow Task drag a script component in the script component input columns only check the field you will process.
private string NewCharacter(string character)
string replacestr= System.Text.RegularExpressions.Regex.Replace(character, "[^a-zA-Z0-9.]+", " ");
return replacestr.Trim();
public override void Input0_ProcessInputRow(Input0Buffer Row)
if(Row.FieldName_IsNull == false)
{//Assign the new value
Row.FieldName = NewCharacter(Row.FieldName); -
ORA-02074 when calling proc from VB
Anyone have any idea why a stored procedure that sets a savepoint will fail with
[Oracle][ODBC][Ora]ORA-02074: cannot ROLLBACK in a distributed transaction
ORA-02074: cannot SET SAVEPOINT in a distributed transaction
ORA-06512: at "PIPS_ADMIN.PKG_ACAS_COMMON", line 1098
ORA-06512: at line 1
when called from Visual Basic via an ADO connection through ODBC BUT
will succeed when called from SQL*Plus or TOAD or other tool.
Any ideas appreciated.
MikeThe change was only made to a local variable in a function that was called from the original function that got the parameters from the java client.
I changed it from localtimestamp to systimestamp and it works fine.
Do i have to make any settings about the time zone in the jdbc thin client ? -
Can we call a Java Stored Proc from a PL/SQL stored Proc?
Hello!
Do you know how to call a Java Stored Proc from a PL/SQL stored Proc? is it possible? Could you give me an exemple?
If yes, in that java stored proc, can we do a call to an EJB running in a remote iAS ?
Thank you!For the java stored proc called from pl/sql, the example above that uses dynamic sql should word :
CREATE OR REPLACE PACKAGE MyPackage AS
TYPE Ref_Cursor_t IS REF CURSOR;
FUNCTION get_good_ids RETURN VARCHAR2 ;
FUNCTION get_plsql_table_A RETURN Ref_Cursor_t;
END MyPackage;
CREATE OR REPLACE PACKAGE BODY MyPackage AS
FUNCTION get_good_ids RETURN VARCHAR2
AS LANGUAGE JAVA
NAME 'MyServer.getGoodIds() return java.lang.String';
FUNCTION get_plsql_table_A RETURN Ref_Cursor_t
IS table_cursor Ref_Cursor_t;
good_ids VARCHAR2(100);
BEGIN
good_ids := get_good_ids();
OPEN table_cursor FOR 'SELECT id, name FROM TableA WHERE id IN ( ' | | good_ids | | ')';
RETURN table_cursor;
END;
END MyPackage;
public class MyServer{
public static String getGoodIds() throws SQLException {
return "1, 3, 6 ";
null -
Calling a COBOL stored proc from Java Servlet
I am trying to call a COBOL stored proc from a Java Servlet. The stored proc is stored on a DB2 database. I need to send 6 inputs to the COBOL stored proc and the output will be the return code of the stored proc. I'm not sure if I'm going about this the right way. This is how my code looks...
public int callStoredProc(CallableStatement cstmt,
Connection con,
String sYear,
String sReportNbr,
String sSystemCode,
String sUserId,
String sModuleNbr,
String sFormId){
int iParm1 = 0;
try{
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
catch(ClassNotFoundException ex){
System.out.println("Failed to locate database driver: "
+ ex.toString());
return iParm1;
try{
cstmt = con.prepareCall("{? = CALL MKTPZ90C
cstmt.registerOutParameter(1, Types.INTEGER);
cstmt.setString(2, sYear);
cstmt.setString(3, sReportNbr);
cstmt.setString(4, sSystemCode);
cstmt.setString(5, sUserId);
cstmt.setString(6, sModuleNbr);
cstmt.setString(7, sFormId);
cstmt.execute();
iParm1 = cstmt.getInt(1);
CloseSQLStatement(cstmt);
catch(SQLException ex) {
CloseSQLStatement(cstmt);
System.out.println("SQL exception occurred:" +
ex.toString());
return iParm1;
return iParm1;
Could someone tell me if this is the right way to go about doing this?
Thanks!!!!!!I didn't see the code where you create the database connection (variable "con"). However, the answer to your question "Is this the right way...", for me, is "Anything that works is the right way." So try it. That's a first approximation, but once you have something that works you can start on improving it, if that becomes necessary.
-
Calling a procedure from a package or another procedure
Hi all,
I am trying to call a couple of procedures defined in a package using the 'call' method without any success.
i tried to create a third procedure and call the other two procedures from there, still without success. Can some one tell me the right method? also i've been trying to research a lot, but havent found any helpful documentation. where would i look for good help material on PL/SQL?
Purvi.All Oracle's documentation is available online at http://tahiti.oracle.com. In particular, the PL/SQL User's Guide would probably be the most helpful to you.
"call" is something that is generally used on client applications (ODBC and JDBC based). It is not used when calling stored procedures in PL/SQL. If you have procedures proc1 and proc2, you can call them from a third stored procedure proc3 like this
CREATE OR REPLACE PROCEDURE proc1
AS
BEGIN
dbms_output.put_line( 'proc1' );
END;
CREATE OR REPLACE PROCEDURE proc2
AS
BEGIN
dbms_output.put_line( 'proc2' );
END;
CREATE OR REPLACE PROCEDURE proc3
AS
BEGIN
proc1();
proc2();
END;If both proc1 and proc2 were in a package called myPkg, and proc3 was a standalone procedure, you would need to modify it to reference the package name
CREATE OR REPLACE PROCEDURE proc3
AS
BEGIN
myPkg.proc1();
myPkg.proc2();
END;Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
How to call proc in package having input as accociative array
Hi,
I want to call a proc inside a package having input paramter as accociative array.How can it be called.?
The signature of package is as follows
TYPE ar_line_details_rec IS RECORD (
mfg_part_num VARCHAR2 (100),
description VARCHAR2 (1000),
line_amount NUMBER (14, 2)
TYPE ar_line_dtls_tab IS TABLE OF ar_line_details_rec
INDEX BY BINARY_INTEGER;
PROCEDURE dca_saf_feedback_pr (
p_dca_id IN dca_header.dca_id%TYPE,
p_memo_number IN dca_header.memo_number%TYPE,
p_memo_amt IN dca_header.memo_amt%TYPE,
p_memo_created_date IN dca_header.memo_created_date%TYPE,
p_ar_line_dtls IN ar_line_dtls_tab,
p_code IN NUMBER,
p_mesg IN VARCHAR2,
p_rtncode OUT NUMBER,
p_rtnmessage OUT VARCHAR2
I want to calls the proc dca_saf_feedback_pr .So can it be done?
Thanks,
TanmoyYes, %TYPE is not required here.
-- If your package name is DCA_SAF_FEEDBACK_PKG & you want to pass associative array as assoc
DECLARE
-- declare associative array
assoc dca_saf_feedback_pkg.ar_line_dtls_tab;
retcode VARCHAR2(200);
remsg VARCHAR2(200);
BEGIN
-- initialize associative array
assoc(1).mfg_part_num:=10;
assoc(1).description :='assoc';
assoc(1).line_amount :=1000;
--pass associative array
dca_saf_feedback_pkg.dca_saf_feedback_pr (
p_dca_id =>1,
p_memo_number => 2,
p_memo_amt => 200,
p_memo_created_date=> SYSDATE,
p_ar_line_dtls =>assoc,
p_code=> 100,
p_mesg =>'assoc',
p_rtncode => retcode,
p_rtnmessage =>rmsg);
END;Regards,
Ankit Rathi
http://theoraclelog.blogspot.in -
Calling a pl\sql package main precedure from a SHL script
If I run this procedure from TOAD suppl_load_main MY package is executed,
I need to be able to handle this to the user, so they can run it from our application, I am using a shl script to call this precedure, I done this before and it works, I never done using the main precedure from a package where the main call other precedures, I know I am doing the right stuff in the application registering the
jobs, creating the links for the shl etc...
I guess the question is, it is possible to call the Main precedure(that call other precedures) from the shl script, or what I am doing wrong
Thank you
PROCEDURE suppl_load_main (
p_one_up_number IN NUMBER,
p_process_name IN VARCHAR2,
p_audit_or_update IN VARCHAR2,
p_user IN VARCHAR2 DEFAULT NULL
IS
Modification History
08/11/2009 Creator:
This is the precedure that will execute the all package, there are not parameters,
the package just need to be executed from this precedure.
Changes:
p_applicant_main_err_code VARCHAR2 (2000);
p_main_err_code NUMBER;
p_ora_err_msg VARCHAR2 (2000);
p_insert_err_code VARCHAR2 (2000);
p_ora_err_code VARCHAR2 (2000);
p_srtpers_err_code VARCHAR2 (2000);
p_gurmail_err_code VARCHAR2 (2000);
v_out_path VARCHAR2 (2000) := 'MIDD_LOG';
v_out_file VARCHAR2 (2000)
:= 'common_app_supl_load_pkg'
|| '_'
|| TO_CHAR (SYSDATE, 'YYYYMMDDHH');
v_file_handle UTL_FILE.file_type;
p_refresh_err_code VARCHAR2 (20000);
v_email saturn_midd.mail.email_con;
v_mailto saturn_midd.mail.email_address;
v_mailfrom saturn_midd.mail.email_address;
v_mailsubject VARCHAR2 (65) := '';
v_mailmessage VARCHAR2 (32000) := '';
v_database_name VARCHAR2 (10);
BEGIN
SELECT ora_database_name
INTO v_database_name
FROM DUAL;
v_database_name :=
SUBSTR (ora_database_name, 1, INSTR (ora_database_name, '.') - 1);
-- isolate instance name
v_file_handle := UTL_FILE.fopen (v_out_path, v_out_file, 'w');
UTL_FILE.put_line (v_file_handle, v_database_name);
UTL_FILE.put_line (v_file_handle,
' ' || TO_CHAR (SYSDATE, 'DD-MON-YYYY HH:MI:SS')
UTL_FILE.put_line (v_file_handle, 'Starting the stuu_MISS_LOAD_main...');
srtiden_insert (p_insert_err_code, p_ora_err_code, p_ora_err_msg);
srtaddr_insert (p_insert_err_code, p_ora_err_code, p_ora_err_msg);
srtpers_insert (p_insert_err_code, p_ora_err_code, p_ora_err_msg);
upd_srtpers_day_mon_yr (p_srtpers_err_code,
p_ora_err_code,
p_ora_err_msg
srttele_home (p_insert_err_code, p_ora_err_code, p_ora_err_msg);
appl_gurmail_insert (p_gurmail_err_code, p_ora_err_code, p_ora_err_msg);
p_main_err_code := '0';
UTL_FILE.put_line (v_file_handle,
CHR (10) || 'All procedures ended successfully.'
IF p_applicant_main_err_code = 0
THEN
UTL_FILE.fremove (v_out_path, v_out_file);
END IF;
v_mailto.email := '[email protected]';
v_mailfrom.email := '[email protected]';
v_mailsubject :=
v_database_name || ': common_app_supl_load_pkg,testing email_1 ';
saturn_midd.mail.MESSAGE
(v_email,
v_mailto,
v_mailfrom,
v_mailsubject,
v_database_name
|| ': *common_app_supl_load_pkg testing email* '
|| CHR (100)
|| 'All procedures ended successfully: '
|| v_out_path
|| '/'
|| v_out_file
EXCEPTION
WHEN OTHERS
THEN
p_applicant_main_err_code := '1';
p_ora_err_msg := SUBSTR (SQLERRM, 1, 2000);
p_ora_err_code := SQLCODE;
v_mailto.email := '[email protected]';
v_mailfrom.email := '[email protected]';
v_mailsubject := v_database_name || ': commonapp_supl_load_pkg';
saturn_midd.mail.MESSAGE
(v_email,
v_mailto,
v_mailfrom,
v_mailsubject,
v_database_name
|| ': *commonapp_supl_load_pkg ended testing email_2* '
|| CHR (100)
|| 'Output log is on the server MIDD_LOG: '
|| v_out_path
|| '/'
|| v_out_file
saturn_midd.mail.message_end (v_email);
END suppl_load_main;
END commonapp_supl_load_pkg;here is the shl
v_audit_or_update VARCHAR (1) := 'A';
The application needs this parameter...
/* Formatted on 2009/02/06 15:17 (Formatter Plus v4.8.8) */
-- Author:
-- Date Written: August 2009
-- Purpose: This script calls the PROCEDURE saturn_midd. suppl_load_main
-- Version Control:
SET serveroutput ON SIZE 1000000
DECLARE
v_audit_or_update VARCHAR (1) := 'A';
job_num NUMBER := NULL;
process_name VARCHAR2 (8) := NULL;
v_user VARCHAR2 (30) := NULL;
BEGIN
job_num := TO_NUMBER (&1);
process_name := '&2';
v_user := UPPER ('&3');
-- Retrieve the parameters for this job submission, so they can be passed to
-- the stored procedure.
SELECT UPPER (gjbprun_value)
INTO v_audit_or_update
FROM general.gjbprun
WHERE gjbprun_job = UPPER (process_name)
AND gjbprun_one_up_no = TO_NUMBER (job_num)
AND gjbprun_number = '01';
-- Now call the stored procedure to do the work.
saturn_midd.commonapp_supl_load_pkg.suppl_load_main( job_num,
process_name,
v_audit_or_update,
v_user);
EXCEPTION
WHEN NO_DATA_FOUND
THEN
-- Put a message in the job log
DBMS_OUTPUT.put_line
('No parameters in Process Run Parameter Table (GJBPRUN)');
END;
EXIT;
/what I am doing wrong supl_load_main invokes a whole bunch of commands that could each potentially fail, but it has one generic exception handler that sends an email (or that's what it looks like, maybe it desn't even do that - what do saturn_midd.mail.MESSAGE and saturn_midd.mail.message_end do?) and doesn't re-raise the exception, so anything could be failing and you wouldn't know.
There seems to be some confusion between "p_" variables (normally parameters) and "v_" (normally local variables) which suggests that some wholesale copying and pasting might have gone on and therefore that some of the assignments might not be doing what they were originally intended for. For example, after assigning SUBSTR (SQLERRM, 1, 2000) to p_ora_err_msg, it is not used again. Perhaps originally p_ora_err_msg was returned to the caller, written to a logfile etc.
I'm not a fan of including the word "main" in procedure names or the assumption that one procedure in a package should be more important than any others, but I do see it a lot so I guess you're not alone in that approach. -
Calling a PL/SQL Package from a controller
Hi ,
I have to add some busines funtionality to the standard existing oco page .
i have extened the standard controller and add the validation logic there , now if the validation is true i have to call a pl/sql package to do some functions . now i am facing few issues here
a) can i call a pl/sql package from a controller ?
b) should i extend the standard AM and call the pl/sql package from the extended am . is extending am allowed ?
please let me know the best sol to achieve thisa) can i call a pl/sql package from a controller ?<b>Yes</b> you can call a pl/sql procedure from controller through <b>OracleCallableStatement</b> object.
<br>
b) should i extend the standard AM and call the pl/sql package from the extended am . is extending am allowed ?Extending AM is <b>allowed</b>, but as can achieve your goal through the CO extension, why bother to touch AM :)
--saroj -
Call stored proc from inside sp
I am trying to call a stored proc from inside a stored proc and the stored proc needs to return a ref_cursor. I am trying to loop over the returned ref_cursor, but my problem is that when I compile the sp it says the ref_cursor is not a procedure or is undefined. Can anyone please tell me why I am getting this error? Refer to the code below!
create or replace
PROCEDURE TCS_GetPartReferenceData
contracts IN VARCHAR2
, showInWork IN INTEGER
, userClock IN VARCHAR2
, intMaxResults IN INTEGER
, ret_cursor OUT SYS_REFCURSOR
) AS
p_cursor SYS_REFCURSOR;
BEGIN
TCS_GETDRNSFORCONTRACTS(contracts
, showinwork
, userClock
, intmaxresults
, p_cursor);
for r in p_cursor loop
dbms_output.put_line(r.puid);
end loop;
END TCS_GetPartReferenceData;Probably you want sth. like
CREATE OR REPLACE PROCEDURE tcs_getpartreferencedata (contracts IN VARCHAR2,
showinwork IN INTEGER,
userclock IN VARCHAR2,
intmaxresults IN INTEGER,
ret_cursor OUT sys_refcursor)
AS
BEGIN
tcs_getdrnsforcontracts (contracts,
showinwork,
userclock,
intmaxresults,
ret_cursor);
END tcs_getpartreferencedata;
var cur refcursor
exec tcs_getpartreferencedata(contracts_value,showinwork_value,userclock_value,intmaxresults_value, :cur)
print curfill in appropriate values for the parameters _value .... -
Can i call stored proc from VOImpl, not from AM?
Hi,
i know how to invoke proc from bb defined in AM...
in VOImpl i have a method getSelectedRows()
which gets me rows selected in table by user.
how can i invoke stored proc from there?
Edited by: grodno on Jan 31, 2013 3:35 AMHi,
its exactly the same code. The only missing link you have is the access to the transaction. In a Viewimpl file just call this.getApplicationModule() to get access to an application module.
The method can also be exposed on a client interface (same as for AM)
Frank -
SQL Exception: Invalid column index while calling stored proc from CO.java
Hello all,
I am getting a "SQL Exception: Invalid column index" error while calling stored proc from CO.java
# I am trying to call this proc from controller instead of AM
# PL/SQL Proc has 4 IN params and 1 Out param.
Code I am using is pasted below
==============================================
OAApplicationModule am = (OAApplicationModule)oapagecontext.getApplicationModule(oawebbean);
OADBTransaction txn = (OADBTransaction)am.getOADBTransaction();
OracleCallableStatement cs = null;
cs = (OracleCallableStatement)txn.createCallableStatement("begin MY_PACKAGE.SEND_EMAIL_ON_PASSWORD_CHANGE(:1, :2, :3, :4, :5); end;", 1);
try
cs.registerOutParameter(5, Types.VARCHAR, 0, 2000);
cs.setString(1, "[email protected]");
cs.setString(2, s10);
//Debug
System.out.println(s10);
cs.setString (3, "p_subject " );
cs.setString (4, "clob_html_message - WPTEST" );
outParamValue = cs.getString(1);
cs.executeQuery();
txn.commit();
catch(SQLException ex)
throw new OAException("SQL Exception: "+ex.getMessage());
=========================================
Can you help please.
Thanks,
VinodYou may refer below URL
http://oracleanil.blogspot.com/2009/04/itemqueryvoxml.html
Thanks
AJ -
Calling package from another package
Hi gurus,
Quick question
Say i m in user1 schema.
I want to call package from another package in the same schema. So do i need to grant permission to the calling package to call.Thank you!!Why don't you test it?
create or replace package pack2
is
procedure t2;
end;
Package created.
create or replace package body pack2
is
procedure t2
is
begin
dbms_output.put_line('Inside Pack2 And t2');
end;
end;
Package Body created.
create or replace package pack1
is
procedure t1;
end;
Package created.
create or replace package body pack1
is
procedure t1
is
begin
pack2.t2;
dbms_output.put_line('Inside Pack1 And t1');
end;
end;
Package Body created.
begin
pack1.t1;
end;
Inside Pack2 And t2
Inside Pack1 And t1
Statement processed.
0.11 secondsRegards.
Satyaki De
Maybe you are looking for
-
Best way to edit out a white background and make a transparent gif
I have an image I purchased but need to make it into a gif. It already has a white background but when I use the magic wand it chops little bits of the edge of the images up. Is there an easier way of editing the white out of this background and maki
-
Access controll Logs and DNS entries
Hello there, We have upgraded from Border Manager 3.5 to Border Manager 3.8 SP4 on new hardware. Everything runs fine except a little niggle. When we view the Access Control logs now all we see is IP addresses there are no host names. In real time mo
-
Please help! Video Problem.
Hey im doing a video project, I uploaded it from a camera onto iMovie at home, then when I saved i made a .mov file. I sent that .mov file to my home, but when I try to do anything with it, it says im missing "Clip 1" or "Clip 2" and wont play. Anyon
-
Cascading menu stopped working in Firefox 4.
I am a web developer. On one of my sites there is a cascading drop menu to select State / City. This was working as of Firefox 3.6.13 and when I updated to FF4 it no longer works. It still works in Safari and IE. I do not even know where to start loo
-
Convert 48000 to 44100 without change in pitch?
I am trying to import a WAV into Logic that is 48000. Logic converts the sample rate to 44100, what I normally use, but the pitch changes which is impossible to work with. Is there a way to change this 48000 to 44100 while maintaining the same pitch?