Call a procedure within a Procedure
hi
How can i call a procedure within a procedure
Thanks in advance
SQL> create procedure b as
2 begin
3 null;
4 end;
5 /
Procedure created.
SQL> create procedure a as
2 begin
3 b;
4 end;
5 /
Procedure created.
SQL>
Similar Messages
-
Calling a oracle procedure within a procedure - Urgent
Hi
Can some one tell me, how to call a oracle procedure within a procedure ?
Thanks
MuraliYou could always try looking in the manuals.
-
Executing procedure within same procedure
Hi all,
Can any one tell me what would be happen if execute procedure within same procedure.
Example :
create or replace procedure print(str in varchar2)
is
begin
print(str);
dbms_output.put_line(str);
exception
when others then
null;
end print ;
Regards,
P PrakashBut, you could call the same procedure in recursion procedure.
This kind of procedure has :
1) action of the recursion procedure
2) condition to go out from the same recursive procedure
SQL> create or replace procedure print(str in varchar2) is
2 num_letters natural;
3 string_tmp varchar2(50);
4 begin
5 -- recursion action
6 dbms_output.put_line(str);
7
8 -- recursion condition
9 num_letters := nvl(length(str), 0);
10 if num_letters > 0 then
11 print(substr(str, 1, num_letters - 1));
12 end if;
13 end print;
14 /
Procedure created
SQL> exec print('abcdefghijkl');
abcdefghijkl
abcdefghijk
abcdefghij
abcdefghi
abcdefgh
abcdefg
abcdef
abcde
abcd
abc
ab
a
PL/SQL procedure successfully completed
SQL> -
How to call fn form within a procedure? - pl help
Hello
I have a procedure which has a set of statements that is called repeatedly.i would like to put them inside a function, passing an IN parameter as well. How to do that? and how do u call the fn from within the procedure?
Pl help.
rgdsSQL> create or replace package calls is
2 procedure proc ;
3 end ;
4 /
Package created.
SQL> create or replace package body calls is
2 function func(p_param in number) return number is
3 begin
4 dbms_output.put_line('param is:'||p_param) ;
5 return(p_param * 2) ;
6 end ;
7 procedure proc is
8 ret_val number ;
9 begin
10 ret_val := func(100) ;
11 dbms_output.put_line('ret_val='||ret_val) ;
12 end ;
13 end ;
14 /
Package body created.
SQL> exec calls.proc ;
param is:100
ret_val=200
PL/SQL procedure successfully completed.
SQL>Message was edited by:
Kamal Kishore -
Calling package procedure within another procedure ???
Hello ,
I have package called import_pack, within this i have procedure called import_proc. I have another separate procedure called main_proc.
Now i want to call import_proc in main_proc. how do i do this ???
Any example would be great. Thank you so much.Hi,
If the import_pack package is in the user_x schema, then the following will always work:
user_x.import_pack.import_proc (...);If main.proc is also in the user_x schema, then the owner name is optional, so this would be acceptable, too:
import_pack.import_proc (...);If main_proc is in the same package, then the package name is optional, so this would also work:
import_proc (...); -
Error in Compiling Procedure within a Procedure ?
I am currently using oracle 11g, and I am getting the error when compiling the following procedure.
Please adv, what am I missing?
If a remove the following lines, then procedure is compiled.
BEGIN
BEGIN my_ctx_procedure(MSHOLD_CODE);
END;
Thanks a lot.
Luqman
create or replace PROCEDURE TEST1
(FDATE1 DATE, FDATE2 DATE,MSHOLD_CODE IN VARCHAR)
IS
BEGIN
BEGIN my_ctx_procedure(MSHOLD_CODE);
END;
CURSOR c1 IS
SELECT * from sholders
where SHOLD_CODE IN
(select * from IN_LIST);
BEGIN
OPEN C1;
END TEST1;
ERROR
LINE/COL ERROR
7/8 PLS-00103: Encountered the symbol "C1" when expecting one of the
following:
:= . ( @ % ;What exactly are you trying to do?
run the my_ctx_procedure(MSHOLD_CODE) proc prior to opening the cursor?
If so:
create or replace PROCEDURE TEST1
(FDATE1 DATE, FDATE2 DATE,MSHOLD_CODE IN VARCHAR)
IS
CURSOR c1 IS
SELECT * from sholders
where SHOLD_CODE IN
(select * from IN_LIST);
BEGIN
my_ctx_procedure(MSHOLD_CODE);
OPEN C1;
END TEST1;
/Your error comes because you put BEGIN and then tried to declare a cursor. You can't declare an explicit cursor inside the main bit of the code; you have to do it in the declaration section (ie. the bit between DECLARE / CREATE Procedure ... IS and the BEGIN)
Edited by: Boneist on 10-Jul-2009 11:31
I suggest you read through this: http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/toc.htm to gain a better understanding of PL/SQL -
Procedure within procedure problem
Hi
I have a table of 5 different magazines and a table of purchases of those magazines. I have written a procedure to take the details of a given magazine and place the sales for a given month into a sales table as follows:
create or replace procedure monthly_sales(mag number, startdate date, enddate date) is
magtotal number(7,0);
magprice magazine.unitprice%type;
magsales number(7,2);
begin
select count(p.magid), m.unitprice into magtotal, magprice from purchase p, magazine m where p.datepurchased between startdate and enddate and p.magid = mag and m.magid=p.magid
group by m.unitprice;
magsales := magtotal*magprice;
insert into sales values(startdate, mag, magtotal, magsales);
end;
What I would like to do though is have a procedure that you just need to run once and it will enter the sales for a given month for all magazines into the sales table. My thought was to try to do this using procedures within a procedure as follows:
create or replace procedure monthly_sales(startdate date, enddate date) is
magtotal number(7,0);
magprice magazine.unitprice%type;
magsales number(7,2);
procedure mag1 is
begin
select count(p.magid), m.unitprice into magtotal, magprice from purchase p, magazine m where p.datepurchased between startdate and enddate and p.magid = 1 and m.magid=p.magid
group by m.unitprice;
magsales := magtotal*magprice;
insert into sales values(startdate, 1, magtotal, magsales);
end mag1;
procedure mag2 is
begin
select count(p.magid), m.unitprice into magtotal, magprice from purchase p, magazine m where p.datepurchased between startdate and enddate and p.magid = 2 and m.magid=p.magid
group by m.unitprice;
magsales := magtotal*magprice;
insert into sales values(startdate, 2, magtotal, magsales);
end mag2;
procedure mag3 is
begin
select count(p.magid), m.unitprice into magtotal, magprice from purchase p, magazine m where p.datepurchased between startdate and enddate and p.magid = 3 and m.magid=p.magid
group by m.unitprice;
magsales := magtotal*magprice;
insert into sales values(startdate, 3, magtotal, magsales);
end mag3;
procedure mag4 is
begin
select count(p.magid), m.unitprice into magtotal, magprice from purchase p, magazine m where p.datepurchased between startdate and enddate and p.magid = 4 and m.magid=p.magid
group by m.unitprice;
magsales := magtotal*magprice;
insert into sales values(startdate, 4, magtotal, magsales);
end mag4;
begin
select count(p.magid), m.unitprice into magtotal, magprice from purchase p, magazine m where p.datepurchased between startdate and enddate and p.magid = 5 and m.magid=p.magid
group by m.unitprice;
magsales := magtotal*magprice;
insert into sales values(startdate, 5, magtotal, magsales);
end;
However, when I run this it is ignoring all the procedures within the main procedure and just entering the results for magazine 5. I'm at a loss as to why this isn't working, is this even the correct way to go about it? any help would be greatly appreciated
thanksWhy doing it the hard way?
A single insert statement will do the trick.
I made a bit of a guess as to the structure of your tables:
create table magazine (magid number primary key, unitprice number);
create table purchase (magid number references magazine(magid), datepurchased date);
create table sales (startdate date, magid number references magazine(magid), magtotal number, magsales number);
insert into magazine(magid, unitprice) values (1, 3.95);
insert into magazine(magid, unitprice) values (2, 4.95);
insert into magazine(magid, unitprice) values (3, 3.50);
insert into magazine(magid, unitprice) values (4, 6.0);
insert into magazine(magid, unitprice) values (5, 5.50);
insert into purchase(magid, datepurchased) values (1, sysdate);
insert into purchase(magid, datepurchased) values (1, sysdate);
insert into purchase(magid, datepurchased) values (2, sysdate);
insert into purchase(magid, datepurchased) values (2, sysdate);
insert into purchase(magid, datepurchased) values (2, sysdate);
insert into purchase(magid, datepurchased) values (4, sysdate);
insert into purchase(magid, datepurchased) values (5, sysdate);
insert into purchase(magid, datepurchased) values (5, sysdate);
insert into purchase(magid, datepurchased) values (5, sysdate);
insert into purchase(magid, datepurchased) values (5, sysdate);
commit;
create or replace procedure monthly_sales(p_startdate in date, p_enddate in date)
is
begin
insert into sales (startdate, magid, magtotal, magsales)
select p_startdate
, p.magid
, count(p.magid)
, count(p.magid) * m.unitprice
from purchase p
join magazine m on m.magid = p.magid
where p.datepurchased between p_startdate and p_enddate
group by p.magid
, m.unitprice;
end;
begin
monthly_sales(trunc(sysdate,'MM'), last_day(trunc(sysdate,'MM')));
end;
select * from sales;
STARTDATE MAGID MAGTOTAL MAGSALES
01-JAN-11 1 2 7.9
01-JAN-11 2 3 14.85
01-JAN-11 4 1 6
01-JAN-11 5 4 22 -
Calling a stored procedure within a package
We have a number of packages containing stored procedures. In an existing production application, we used embedded SQL in C programs to call these stored procs
e.g.
EXEC SQL EXECUTE
BEGIN owner.fees_calc.some_fee(:parm1,...);
END;
END-EXEC;
Now, I am trying to use SQLJ to call this same stored proc in the package. However, I am getting a compilation error from sqlj saying that it cannot find a stored procedure or function of that name. It works fine if I use a stored proc that is not in a package.
So how do I call a stored procedure within a package? Or is this not currently possible with sqlj?
I am also getting a warning just before the error and I'm wondering if the error is being caused by this:
Warning: You are using an Oracle JDBC driver, but connecting to a non-Oracle database. SQLJ will perform JDBC-generic SQL checking.
I am connecting to an Oracle 7.3.3 database using an Oracle 7.3.4 JDBC driver. I also tried using the Oracle 8.0.5 JDBC driver for the same database but I get the same warning message.I used the following code to call a stored
procedure via SQLJ:
try {
#sql [iCtx] {
CALL ibs.cvs_validate.validate_port_id(:IN record_id ,:IN poe_pod_flag,:IN port_id,:OUT error_code,:OUT error_message) };
where
"ibs" is the schema
"cvs_validate" is the package
"validate_port_id" is the procedure
The code runs fine, but to get it to compile
in JDeveloper 2.0, I had to disable the "Check SQL semantics against database schema" option on the Project Properties (SQLJ) property sheet.
null -
Function call in procedure within Package Body
I am a novice in PL/SQL so that I can't find out where the problem is. I am testing a function call in procedure within a Package Body.
But the PL/SQL Complier doesn't compile the package body but I don't know what I do wrong. Plz let me know how to call a function in procedure within a Package Body?
Here are the Packaget test programs..
CREATE OR REPLACE PACKAGE manage_students
IS
PROCEDURE find_sname;
PROCEDURE find_test;
PROCEDURE find_test_called;
FUNCTION GET_LASTMT
RETURN SEQUENCE_TEST.SEQ_NO%TYPE;
END manage_students;
CREATE OR REPLACE PACKAGE BODY manage_students AS
v_max_nbr SEQUENCE_TEST.SEQ_NO%TYPE;
PROCEDURE find_sname
IS
BEGIN
BEGIN
SELECT MAX(SEQ_NO)
INTO v_max_nbr
from SEQUENCE_TEST;
DBMS_OUTPUT.PUT_LINE('MAX NUMBER is : '||v_max_nbr);
EXCEPTION
WHEN OTHERS
THEN DBMS_OUTPUT.PUT_LINE('Error in finding student_id: ');
RETURN;
END;
COMMIT;
EXCEPTION
WHEN OTHERS
THEN DBMS_OUTPUT.PUT_LINE('Error in finding student_id: ');
END find_sname;
PROCEDURE find_test
IS
BEGIN
BEGIN
DBMS_OUTPUT.PUT_LINE('MAX NUMBER Called from another procedure : '||v_max_nbr);
EXCEPTION
WHEN OTHERS
THEN DBMS_OUTPUT.PUT_LINE('Error in finding student_id: ');
RETURN;
END;
COMMIT;
EXCEPTION
WHEN OTHERS
THEN DBMS_OUTPUT.PUT_LINE('Error in finding student_id: ');
END find_test;
FUNCTION GET_LASTMT
RETURN SEQUENCE_TEST.SEQ_NO%TYPE
IS
v_max_nbr SEQUENCE_TEST.SEQ_NO%TYPE;
BEGIN
SELECT MAX(SEQ_NO)
INTO v_max_nbr
from SEQUENCE_TEST;
RETURN v_max_nbr;
EXCEPTION
WHEN OTHERS
THEN
DECLARE
v_sqlerrm VARCHAR2(250) :=
SUBSTR(SQLERRM,1,250);
BEGIN
RAISE_APPLICATION_ERROR(-20003,
'Error in instructor_id: '||v_sqlerrm);
END;
END GET_LASTMT;
PROCEDURE find_test_called
IS
BEGIN
BEGIN
V_max := Manage_students.GET_LASTMT;
DBMS_OUTPUT.PUT_LINE('MAX_NUMBER :'|| V_max);
EXCEPTION
WHEN OTHERS
THEN DBMS_OUTPUT.PUT_LINE('Error in finding student_id: ');
RETURN NULL;
END;
COMMIT;
EXCEPTION
WHEN OTHERS
THEN DBMS_OUTPUT.PUT_LINE('Error in finding student_id: ');
END find_test_called;
END manage_students;
DECLARE
v_max SEQUENCE_TEST.SEQ_NO%TYPE;
BEGIN
manage_students.find_sname;
DBMS_OUTPUT.PUT_LINE ('Student ID: Execute.');
manage_students.find_test;
manage_students.find_test_called;
END;
-----------------------------------------------------------------------------------------------Hi,
Welcome to the forum!
You'll find that there are a lot of people willing to help you.
Are you willing to help them? Whenever you have a problem, post enough for people to re-create the problem themselves. That includes CREATE TABLE and INSERT statements for all the tables you use.
Error messages are very helpful. Post the complete error message you're getting, including line number. (It looks like your EXCEPTION sections aren't doing much, except hiding the real errors. That's a bad programming practice, but probably not causing your present problem - just a future one.)
Never post unformatted code. Indent the code to show the extent of each procedure, and the blocks within each one.
When posting formatted text on this site, type these 6 characters:
\(all small letters, inside curly brackets) before and after each section of formatted test, to preserve the spacing.
For example, the procedure find_test_called would be a lot easier to read like this:PROCEDURE find_test_called
IS
BEGIN
BEGIN
V_max := Manage_students.GET_LASTMT;
DBMS_OUTPUT.PUT_LINE ('MAX_NUMBER :' || V_max);
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.PUT_LINE ('Error in finding student_id: ');
RETURN NULL;
END;
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.PUT_LINE ('Error in finding student_id: ');
END find_test_called;
It's much easier to tell from the code above that you're trying to return NULL from a procedure. Only functions can return anything (counting NULL); procedures can have RETURN statements, but that single word"RETURN;" is the entire statement. -
UTL_FILE in a trigger or calling a stored procedure within a trigger
Hello,
We are using Oracle 8i version where I need to either call a SP within a trigger or use UTL_FILE within a trigger.
1. SP runs fine by itself to write to a file but when I try calling SP within a trigger-> I get INVALID Path - is there some kind of restriction with DB triggers and UTL_FILE options
create or replace trigger testtrig
after insert on test_table
for each row when (new.stat_code = '99')
BEGIN
utl_file_test_write;
EXCEPTION
WHEN others THEN
raise_application_error(-20000, sqlerrm);
END;
2. use UTL_FILE with a trigger
create or replace trigger testtrig
after insert on test_table
for each row when (new.stat_code <> '99')
DECLARE
v_line varchar2(32767);
v_location varchar2(80) :='/u01/oraadmin/udump';
v_filename varchar2(80) := 'KC11.txt';
v_handle utl_file.file_type;
BEGIN
dbms_output.put_line('Location is'||v_location);
dbms_output.put_line('Location is'||v_filename);
v_filename := :new.emp_id;
v_handle := utl_file.fopen(v_location, v_filename,'W',32767);
v_line := :new.emp_id;
utl_file.put_line(v_handle,v_line);
utl_file.fclose(v_handle);
EXCEPTION
WHEN TOO_MANY_ROWS THEN
dbms_output.PUT_LINE('Too Many Rows');
WHEN NO_DATA_FOUND THEN
dbms_output.PUT_LINE('No Data Found');
--WHEN utl_file.invalid_path THEN
-- RAISE_APPLICATION_ERROR(-20000, 'utl_file.invalid_path');
WHEN utl_file.invalid_mode THEN
RAISE_APPLICATION_ERROR(-20000, 'utl_file.invalid_mode');
WHEN utl_file.invalid_filehandle THEN
RAISE_APPLICATION_ERROR(-20000, 'utl_file.invalid_filehandle');
WHEN utl_file.invalid_operation THEN
RAISE_APPLICATION_ERROR(-20000, 'utl_file.invalid_operation');
WHEN utl_file.read_error THEN
RAISE_APPLICATION_ERROR(-20001, 'utl_file.read_error');
WHEN utl_file.write_error THEN
RAISE_APPLICATION_ERROR(-20001, 'utl_file.write_error');
WHEN utl_file.internal_error THEN
RAISE_APPLICATION_ERROR(-20001, 'utl_file.internal_error');
End;
I still get INVALID_PATH. What am I missing?
Any help is greatly appreciated.
Thanks.Hi,
from docs on UTL_FIL.FOPEN:
location:
Directory location of file. This string is a directory object name and is case sensitive. The default is uppercase. Read privileges must be granted on this directory object for the UTL_FILE user to run FOPEN.This, '/u01/oraadmin/udump' does not look like the name of a DIRECTORY object.
Besides, the whole idea of having UTL_FILE commands directly in a trigger body sucks. At the least stay with a stored procedure.
And have you considered what should happen with that file in case the transaction is rolled back?
Regards
Peter -
Call procedure within procedure
Hai
I have some question
1)
This below procedure create user at run time
============================================
create or replace procedure new_u1( p_name in varchar2,
p_pw in varchar2,
p_def_tblspace in varchar2 default 'users' )
as
begin
execute immediate 'create user ' || P_name || ' identified by ' ||
p_pw || ' default tablespace ' || p_def_tblspace ||
' temporary tablespace temp';
execute immediate 'grant create session to ' || p_name;
end;
This below procedure create tables at run time
==============================================
create or replace procedure M2 (table_name varchar2) as
cursor1 integer;
begin
cursor1 := dbms_sql.open_cursor;
dbms_sql.parse(cursor1, 'DROP TABLE ' || table_name,
dbms_sql.v7);
dbms_sql.close_cursor(cursor1);
end;
I want ,when first procedure calls ,it calls second procedure and create tables in that schema (call procedure within procedure).How to do that?
2)What is diffrenece between row and statement level trigger?how many types of triggers?
3)what is mutating trigger or table?
4)dbms_stats.gather_table_stats package it collects the statistics about the tables .I want statistics to be collected at every day 9am and 7pm how to do that?
Thanks in advance
MohanYou could use an expression like this, to generate the run times:
SQL> create table times (dt date) ;
Table created.
SQL> BEGIN
2 FOR idx IN 1 .. 24
3 LOOP
4 INSERT INTO times VALUES (trunc(SYSDATE) + (idx / 24));
5 INSERT INTO times VALUES (trunc(SYSDATE) + (idx / 24) + (1 / (24 * 60)));
6 INSERT INTO times VALUES (trunc(SYSDATE) + (idx / 24) + (59 / (24 * 60)));
7 END LOOP;
8 END;
9 /
PL/SQL procedure successfully completed.
SQL>
SQL> SELECT to_char(dt,
2 'dd-mon-yyyy hh:mi:ss AM'),
3 to_char(decode(sign(to_number(to_char(dt,
4 'hh24MI')) - 900),
5 -1,
6 trunc(dt) + (9 / 24),
7 0,
8 trunc(dt) + (9 / 24),
9 decode(sign(to_number(to_char(dt,
10 'hh24MI')) - 1900),
11 -1,
12 trunc(dt) + (19 / 24),
13 0,
14 trunc(dt) + (19 / 24),
15 trunc(dt) + 1 + (9 / 24))),
16 'dd-mon-yyyy hh:mi:ss AM')
17 FROM times
18 ORDER BY dt
19 /
TO_CHAR(DT,'DD-MON-YYYY TO_CHAR(DECODE(SIGN(TO_
01-jan-2004 01:00:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 01:01:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 01:59:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 02:00:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 02:01:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 02:59:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 03:00:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 03:01:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 03:59:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 04:00:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 04:01:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 04:59:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 05:00:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 05:01:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 05:59:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 06:00:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 06:01:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 06:59:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 07:00:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 07:01:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 07:59:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 08:00:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 08:01:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 08:59:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 09:00:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 09:01:00 AM 01-jan-2004 07:00:00 PM
01-jan-2004 09:59:00 AM 01-jan-2004 07:00:00 PM
01-jan-2004 10:00:00 AM 01-jan-2004 07:00:00 PM
01-jan-2004 10:01:00 AM 01-jan-2004 07:00:00 PM
01-jan-2004 10:59:00 AM 01-jan-2004 07:00:00 PM
01-jan-2004 11:00:00 AM 01-jan-2004 07:00:00 PM
01-jan-2004 11:01:00 AM 01-jan-2004 07:00:00 PM
01-jan-2004 11:59:00 AM 01-jan-2004 07:00:00 PM
01-jan-2004 12:00:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 12:01:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 12:59:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 01:00:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 01:01:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 01:59:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 02:00:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 02:01:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 02:59:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 03:00:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 03:01:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 03:59:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 04:00:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 04:01:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 04:59:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 05:00:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 05:01:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 05:59:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 06:00:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 06:01:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 06:59:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 07:00:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 07:01:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 07:59:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 08:00:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 08:01:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 08:59:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 09:00:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 09:01:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 09:59:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 10:00:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 10:01:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 10:59:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 11:00:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 11:01:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 11:59:00 PM 02-jan-2004 09:00:00 AM
02-jan-2004 12:00:00 AM 02-jan-2004 09:00:00 AM
02-jan-2004 12:01:00 AM 02-jan-2004 09:00:00 AM
02-jan-2004 12:59:00 AM 02-jan-2004 09:00:00 AM
72 rows selected.
SQL> -
How to call a procedure from within another procedure?
What's the syntax to call a procedure from within a procedure.
I have a procedure z(user_id IN number, ....)
then
procedure a (user_id IN number, ....)
procedure b (user_id IN number, ....)
procedure c (user_id IN number, ....)
I want to call procedure a, b, c from inside procedure z.
How would I do that?Same way :
SCOTT@db102 SQL> create or replace procedure a (p1 in varchar2) is
2 begin
3 dbms_output.put_line (p1);
4* end;
SCOTT@db102 SQL> /
Procedure created.
SCOTT@db102 SQL> create or replace procedure z (par1 in number) is
2 begin
3 if par1 != 0 then
4 a ('This is proc a');
5 end if;
6* end;
SCOTT@db102 SQL> /
Procedure created.
SCOTT@db102 SQL> set serveroutput on
SCOTT@db102 SQL> exec z (1);
This is proc a
PL/SQL procedure successfully completed.
SCOTT@db102 SQL> -
Calling a procedure from within a procedure
Hi Guys,
I have created a package to base a form on. The package contains some procedures, one of which is an Update procedure which can be seen below. I have a procedure in another package that I am trying to call. Basically the second procedure is called to implement a constraint. However, I am unsure as to what I should pass into this procedure, as a package/procedure for basing a form on is different to what I have come across before.
CREATE OR REPLACE package staff_dml IS
TYPE staff_rec IS RECORD (staff_id NUMBER(7),
first_name VARCHAR2(20),
last_name VARCHAR2(20),
tel_no NUMBER(11),
manager_id NUMBER(7),
position VARCHAR2(20),
rest_id NUMBER(7),
grade VARCHAR2(1),
wage NUMBER(7,2));
TYPE staff_cursor IS REF CURSOR RETURN staff_rec;
TYPE staff_table IS TABLE OF staff_rec INDEX BY BINARY_INTEGER;
PROCEDURE staff_update (data IN OUT staff_table);
PROCEDURE staff_find (data IN OUT staff_cursor);
PROCEDURE staff_lock (data IN OUT staff_table);
END;
CREATE OR REPLACE PACKAGE BODY staff_dml IS
PROCEDURE staff_lock (data IN OUT staff_table)
IS
temp NUMBER;
BEGIN
SELECT staff_id into temp
FROM staff
WHERE staff_id = data(1).staff_id
FOR UPDATE;
END staff_lock;
PROCEDURE staff_find (data IN OUT staff_cursor)
IS
BEGIN
OPEN data FOR SELECT staff_id, first_name, last_name, tel_no, manager_id, position, rest_id, grade, wage
FROM staff;
END staff_find;
PROCEDURE staff_update
(data IN OUT staff_table)
IS
BEGIN
IF data(1).wage != data(1).wage THEN
special_pkg.staff_chk(data(1).wage,data(1).grade);
END IF;
IF data(1).grade != data(1).grade THEN
special_pkg.staff_chk(data(1).wage,data(1).grade);
END IF;
UPDATE staff
SET first_name = data(1).first_name, last_name = data(1).last_name, tel_no = data(1).tel_no, manager_id = data(1).manager_id,
position = data(1).position, rest_id = data(1).rest_id, grade = data(1).grade, wage = data(1).wage
WHERE staff_id = data(1).staff_id;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SQLCODE||' '||SQLERRM);
END staff_update;
END;
The area I an concerned about is:
IF data(1).wage != data(1).wage THEN
special_pkg.staff_chk(data(1).wage,data(1).grade);
END IF;
IF data(1).grade != data(1).grade THEN
special_pkg.staff_chk(data(1).wage,data(1).grade);
END IF;
I do not know what I should be passing into the special_pkg.staff_chk procedure which accepts two number inputs. I want to use this package to compare the new inputs on this to the existing ones (this is carried out by the procedure. I have tried using :new. but this is not accepted. If I leave in the EXCEPTION then i get no errors from the form, but it will not save any changes I make on the database. If I remove the EXCEPTION then I get an error from the form - FRM-40735 UPDATE-PROCEDURE trigger raised unhandled exception ORA-04098. I am pretty sure this is because I am not supplying the correct variables to the called procedure,
The called procedure is below (tested and working):
PROCEDURE staff_chk
(p_wage IN NUMBER,
p_grade IN NUMBER)
IS
BEGIN
IF p_wage BETWEEN 0 AND 7.00 AND p_grade != 'C' THEN
RAISE_APPLICATION_ERROR(-20002, 'The Incorrect grade has been applied to this employee');
ELSIF p_wage BETWEEN 7.01 AND 10 AND p_grade != 'B' THEN
RAISE_APPLICATION_ERROR(-20003, 'The Incorrect grade has been applied to this employee');
ELSIF p_wage BETWEEN 10.01 AND 20 AND p_grade != 'A' THEN
RAISE_APPLICATION_ERROR(-20004, 'The Incorrect grade has been applied to this employee');
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('Staff member does not exist');
END staff_chk;
END;
Any help would be greatly appreciated.
Thanks,
AntonSince this appears to be an Oracle Forms related question, you may want to pose it over in the Oracle Forms forum.
Forms
The folks over there are a lot more likely to be able to solve your problem.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
Calling a procedure from within a procedure - dif to post below
Hi Guys,
I have created a package to base a form on. The package contains some procedures, one of which is an Update procedure which can be seen below. I have a procedure in another package that I am trying to call. Basically the second procedure is called to implement a constraint. However, I am unsure as to what I should pass into this procedure, as a package/procedure for basing a form on is different to what I have come across before.
CREATE OR REPLACE package staff_dml IS
TYPE staff_rec IS RECORD (staff_id NUMBER(7),
first_name VARCHAR2(20),
last_name VARCHAR2(20),
tel_no NUMBER(11),
manager_id NUMBER(7),
position VARCHAR2(20),
rest_id NUMBER(7),
grade VARCHAR2(1),
wage NUMBER(7,2));
TYPE staff_cursor IS REF CURSOR RETURN staff_rec;
TYPE staff_table IS TABLE OF staff_rec INDEX BY BINARY_INTEGER;
PROCEDURE staff_update (data IN OUT staff_table);
PROCEDURE staff_find (data IN OUT staff_cursor);
PROCEDURE staff_lock (data IN OUT staff_table);
END;
CREATE OR REPLACE PACKAGE BODY staff_dml IS
PROCEDURE staff_lock (data IN OUT staff_table)
IS
temp NUMBER;
BEGIN
SELECT staff_id into temp
FROM staff
WHERE staff_id = data(1).staff_id
FOR UPDATE;
END staff_lock;
PROCEDURE staff_find (data IN OUT staff_cursor)
IS
BEGIN
OPEN data FOR SELECT staff_id, first_name, last_name, tel_no, manager_id, position, rest_id, grade, wage
FROM staff;
END staff_find;
PROCEDURE staff_update
(data IN OUT staff_table)
IS
BEGIN
IF data(1).wage != data(1).wage THEN
special_pkg.staff_chk(data(1).wage,data(1).grade);
END IF;
IF data(1).grade != data(1).grade THEN
special_pkg.staff_chk(data(1).wage,data(1).grade);
END IF;
UPDATE staff
SET first_name = data(1).first_name, last_name = data(1).last_name, tel_no = data(1).tel_no, manager_id = data(1).manager_id,
position = data(1).position, rest_id = data(1).rest_id, grade = data(1).grade, wage = data(1).wage
WHERE staff_id = data(1).staff_id;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SQLCODE||' '||SQLERRM);
END staff_update;
END;
The area I an concerned about is:
IF data(1).wage != data(1).wage THEN
special_pkg.staff_chk(data(1).wage,data(1).grade);
END IF;
IF data(1).grade != data(1).grade THEN
special_pkg.staff_chk(data(1).wage,data(1).grade);
END IF;
I do not know what I should be passing into the special_pkg.staff_chk procedure which accepts two number inputs. I want to use this package to compare the new inputs on this to the existing ones (this is carried out by the called procedure). I have tried using :new. but this is not accepted. If I leave in the EXCEPTION then i get no errors from the form, but it will not save any changes I make on the database. If I remove the EXCEPTION then I get an error from the form - FRM-40735 UPDATE-PROCEDURE trigger raised unhandled exception ORA-04098. I am pretty sure this is because I am not supplying the correct variables to the called procedure,
The called procedure is below (tested and working):
PROCEDURE staff_chk
(p_wage IN NUMBER,
p_grade IN NUMBER)
IS
BEGIN
IF p_wage BETWEEN 0 AND 7.00 AND p_grade != 'C' THEN
RAISE_APPLICATION_ERROR(-20002, 'The Incorrect grade has been applied to this employee');
ELSIF p_wage BETWEEN 7.01 AND 10 AND p_grade != 'B' THEN
RAISE_APPLICATION_ERROR(-20003, 'The Incorrect grade has been applied to this employee');
ELSIF p_wage BETWEEN 10.01 AND 20 AND p_grade != 'A' THEN
RAISE_APPLICATION_ERROR(-20004, 'The Incorrect grade has been applied to this employee');
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('Staff member does not exist');
END staff_chk;
END;
Any help would be greatly appreciated.
Thanks,
AntonHi,
You triggered in fired on table and you procedure in acting is on the same table which rasing the exception.
Go throw this link you will understand
http://asktom.oracle.com/tkyte/Mutate/
- Pavan Kumar N -
PL/SQL: Executing a procedure from within another procedure
Hello, I'm a newbie and I need help on how to execute procedures from within another procedure. The procedure that I call from within the procedure have return values that I want to check.
I tried: EXECUTE(user_get_forum_info(p_forumid, var_forum_exists, var_forum_access, var_forumname));
but I get the error message:
PLS-00103: Encountered the symbol "USER_GET_FORUM_INFO" when expecting one of the following::= . ( @ % ; immediate
The symbol ":=" was substituted for "USER_GET_FORUM_INFO" to continue.
And when I tried: EXECUTE(user_get_forum_info(p_forumid, var_forum_exists, var_forum_access, var_forumname));
I get the error message:
PLS-00222: no function with name 'USER_GET_FORUM_INFO' exists in this scope
PL/SQL: Statement ignored
The procedure USER_GET_FORUM_INFO exists. (don't understand why it says "no FUNCTION with name", it's a procedure I'm executing)
I'm stuck so thanks for any help...
Below is all the code. I'm using Oracle 9i on RedHat Linux 7.3.
================================================================================
CREATE OR REPLACE PROCEDURE user_forum_requestsaccess (
p_forumid IN NUMBER,
p_requestmessage IN VARCHAR2
AS
var_forumid NUMBER;
var_forum_exists NUMBER;
var_forum_access NUMBER;
request_exists NUMBER;
var_forumname VARCHAR2(30);
FORUM_DOESNT_EXIST EXCEPTION;
FORUM_USER_HAS_ACCESS EXCEPTION;
FORUM_REQUEST_EXIST EXCEPTION;
BEGIN
SELECT SIGN(NVL((SELECT request_id FROM forum.vw_all_forum_requests WHERE forum_id = p_forumid AND db_user = user),0)) INTO request_exists FROM DUAL;
EXECUTE(user_get_forum_info(p_forumid, var_forum_exists, var_forum_access, var_forumname));
IF var_forum_exists = 0 THEN
RAISE FORUM_DOESNT_EXIST;
ELSIF var_forum_access = 1 THEN
RAISE FORUM_USER_HAS_ACCESS;
ELSIF request_exists = 1 THEN
RAISE FORUM_REQUEST_EXIST;
ELSE
INSERT INTO tbl_forum_requests VALUES (SEQ_TBL_FORUM_REQ_REQ_ID.NEXTVAL, SYSDATE, p_requestmessage, p_forumid, user);
INSERT INTO tbl_forum_eventlog VALUES (SEQ_TBL_FORUM_EVNTLOG_EVNT_ID.NEXTVAL,SYSDATE,1,'User ' || user || ' requested access to forum ' || var_forumname || '.', p_forumid,user);
COMMIT;
END IF;
EXCEPTION
WHEN
FORUM_DOESNT_EXIST
THEN RAISE_APPLICATION_ERROR(-20003,'Forum doesnt exist.');
WHEN
FORUM_USER_HAS_ACCESS
THEN RAISE_APPLICATION_ERROR(-20004,'User already have access to this forum.');
WHEN
FORUM_REQUEST_EXIST
THEN RAISE_APPLICATION_ERROR(-20005,'A request to this forum already exist.');
END;
GRANT EXECUTE ON user_forum_requestsaccess TO forum_user;
================================================================================
Regards Goranyou don't have to use execute when you want to execute a procedure (only on sql*plus, you would use it)
just give the name of the funtion
create or replace procedure test
as
begin
dbms_output.put_line('this is the procedure test');
end test;
create or replace procedure call_test
as
begin
dbms_output.put_line('this is the procedure call_test going to execute the procedure test');
test;
end call_test;
begin
dbms_output.put_line('this is an anonymous block calling the procedure call_test');
call_test;
end;
/
Maybe you are looking for
-
HTML5 Video Works In Live and Preview But Not on My Website
I feel totally ripped off by Adobe, again, I talked to a sales representative who told me that if I bought CS6 I would be able to easily install html5 video because the new version had an insert function that did most of the coding for you and gave y
-
Hi, I want to give mutiple parameters in report e.g. my query is select * from dept where departname in (Mutiple Values). When the report will run, user can enter either one OR mutiple departments.... Thanks John
-
How to avoid starting a page with line breaks?
Hello. I've just started to refine my Master's thesis and some of the topics moved up and down as I edited their contents. The problem is that in some cases the topic breaks right after the title, and the rest of the contents just move away to anothe
-
hi all, i do need to add a classpath entry of a jar file in manifest.mf file of a jar. i know what should i include for this as Class-Path:myjar.jar but i have a little problem to understand that, where should i write this line if i have a jar file s
-
Adventure Works - Financial Reporting - Amount - Currency Conversion
Hi all, I was looking into currency conversion in the Adventure Works cube (SQL2008R2). For each measure that need to be converted, a measure expression is used (e.g.: [Internet Sales Amount] / [Average Rate]), except for Amout in the measure group F