Exforsys.com
 
Home Tutorials Oracle 9i
 

Tutorial 13: Oracle 9i : Procedures and Functions

 

Tutorial 13: Oracle 9i : Procedures and Functions - Page 2

Page 2 of 2



Functions:


A function is a PL/SQL subprogram, which is used to compute a value. Function is same like a procedure except for the difference that it have RETURN clause.

Syntax for Function



Examples



Function without arguments



Function with arguments. Different ways of executing the function.



Privileges for creation and execution of procedures


To create a procedure in current user schema we use the syntax

CREATE OR REPLACE PROCEDURE (<argslist) IS
-------
-------



To create procedure in any schema we use



CREATE OR REPLACE ANY PROCEDURE (<argslist) IS
-------
-------



To grant EXECUTE privilege to some user on a procedure we write


GRANT EXECUTE ON <procedure-name> TO <user-name>

SQL> SELECT * FROM USER_PROCEDURES;
Lists all the procedures, functions in current user.


SQL> SELECT * FROM USER_PROCEDURES;
Lists all the procedures, functions in all users.


SQL> DROP PROCEDURE <procedure-name> ;
Drops or Removes a procedure from database


SQL> DROP FUNCTION <function-name> ; 
Drops or Removes a function from database





First Page: Tutorial 13: Oracle 9i : Procedures and Functions


Read Next: Tutorial 14: Oracle 9i : Database Triggers



 

 

Comments


todeardennnis said:

  [EMAIL]psdchak@yahoo.com[/EMAIL]
March 26, 2005, 12:52 pm

ambuj_shukla said:

  hi all,
please send me anser what is difference b/w truncate and delete command and exaMPLE
August 18, 2005, 6:37 am

Raghvendra Pratap Singh said:

  HI ambuj
1. Delete is DML command. after which u can rollback.But Truncate is DDL command after which it do commit.
2.In delete u can give some condition so it will delete not all row. But in truncate there is no such option.
eg delete from emp where eno=134
it will delete that row which have eno 134. To delete all row u can write
delete from emp // But it is not permanent
truncate from emp;// it delete all rows and its deletion is permanent
August 16, 2006, 8:53 am

raj soni said:

  truncate is a ddl and delete is a dml command
tru delete always segment,not a record so that u can't rollback
while delete deletes row and u can rollback
because after trun autocommit occur
October 11, 2006, 2:04 am

jayshree said:

  can a function return more than one value at a time?
September 21, 2007, 4:55 am

TR said:

  'NO'........FUNCTION CANT RETURN MORE THAN ONE VALUE AT A TIME.
BY USING "OUT PARAMETER" IN THE PROCEDURE WE CAN RETURN MORE THAN ONE VALUE AT A TIME.
October 4, 2007, 12:13 am

rajeshk said:

  how can i fetch a value from an already existing table, and execute an operation in my procedure using select statement
December 6, 2007, 2:17 am

srikanth said:

  what is the use of p-code?where we can use please give me any example for easy understan?
October 23, 2008, 4:57 am

srikanth said:

  what is difference between IS/AS in procedure and function in oracle9i
October 23, 2008, 5:02 am

kulbhushan said:

  difine diff b/w in out inout parmeters with example and also return type , boc students are not able to understand wht is basic diff b/w them
November 5, 2008, 12:56 am

prasan said:

  please tell me how to execute pl sql block....

declare
a number;
b number;
c number;
begin
a:=&a;
b:=&b;
c:=a+b;
dbms_output.put_line('Sum of ' || a || ' and ' || b || ' is ' || c);

Here to take user input at runtime.....but its giving error...
November 26, 2008, 5:23 am

Ajay said:

  how can i call a parameterised procedure in program?plz explain with example.
December 3, 2008, 8:56 am

Ashok Kumar said:

  can any one help me to rectify errors in this package


create or replace package pack1 as
FUNCTION fun1(dno number) return number;
PROCEDURE PR1(eno number);
end;






CREATE OR REPLACE package body pack1 as
FUNCTION fun1(dno number) return number as
lag ask_employees.department_id%type;
begin
select department_id into lag from ask_employees where department_id=dno;
return lag;
end;

PROCEDURE PR1(eno number)as
begin
insert into eem values(eno);
dbms_output.PUT_LINE('Data Inserted');
end if;
end;
end;

declare
empno ask_employees.employee_id%type:=&no;
depno ask_employees.department_id%type:=&deno;
sag ask_employees.department_id%type;
begin
sag:=pack1.fun1(depno);
if sag is null then
dbms_output.PUT_LINE('not a valid department number');
else
pack1.PR1(empno)
end if;
end;
December 16, 2008, 2:34 am

Rakesh arya said:

  can i use select statment in procdure if yes plzzzzzz give me ex.
January 17, 2009, 8:22 am

Prajeesh said:

  Good one.. It will be more useful if add function explanation, procedure vs function and some more examples. :)
January 19, 2009, 10:01 pm

vinay_kewalrama said:

  Can you me Tell me How to alter Procedure In Oracle ?
Cause i don't want to Replace it..
January 22, 2009, 3:47 am

shantha murthy s said:

  what is shared sql and dyanamic sql?
February 3, 2009, 1:28 pm

0 said:

  all DDL cmds are internally commit cmds. There is no need to execute commit cmd after execution of DDL cmds.
February 10, 2009, 1:03 am

lakshmi said:

  hi prasan u didn't end u r pl/sql block
February 10, 2009, 1:11 am

lakshmi said:

  hi ajay u can call the parameterised procedure
exec procedurename(parameterlist);
February 10, 2009, 1:15 am

Srikanth said:

  SQL> desc emp_test;
Name Null? Type
----------------------------------------- -------- ----------------------------
EMPNO NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(2)

SQL> CREATE OR REPLACE PROCEDURE pro_delete_rows (
2 p_table_name IN VARCHAR2,
3 p_deleted_rows OUT NUMBER
4 )
5 IS
6 BEGIN
7 EXECUTE IMMEDIATE 'delete from' || p_table_name;
8
9 p_deleted_rows := SQL%ROWCOUNT;
10 END ;
11 /

Procedure created.

SQL> variable deleted number
SQL> execute pro_delete_rows('EMP_TEST',:deleted)
BEGIN pro_delete_rows('EMP_TEST',:deleted); END;

*
ERROR at line 1:
ORA-00942: table or view does not exist
ORA-06512: at "SCOTT.PRO_DELETE_ROWS", line 7
ORA-06512: at line 1


SQL> print deleted

DELETED
----------
February 11, 2009, 2:45 am

Ajmalkhan said:

  i created one procedure and execute result will come.

i want change in procedure, how will i get procedure view and edit?
February 21, 2009, 12:55 am

kamleshwar kumar said:

  How can we see the all database in Oracle?
May 8, 2009, 5:48 am

Dr. Mohd Sharjish Iqbal said:

  hi Ambuj
Delete is a DML command while truncate is DDL command
Delete Command Can be Rollback while Truncate command cannot be rollback
Delete command delete the whole record but not free the table space while truncate free the table storage place.
May 28, 2009, 11:33 am

sabu said:

  How to schedule a procedure?
June 5, 2009, 3:56 am

a.hari said:

  How to create procedure and funtions at a time
June 19, 2009, 5:18 am

Sunil Kr Pandey said:

  Generally DDL Statements are those whose implementation affects the strcuture of database objects like Create, Alter, Drop. But TRUNCATE only operates on Data Values i.e. Tuples will be unconditionally deleted permanently from a Table. Then how TRUNCATE can be DDL statement? can I get some logical explanantion on it from those who have written that TRUNCATE is a DDL Statement?

Regards to all.
September 7, 2009, 9:37 pm

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 

Subscribe via RSS


Get Daily Updates via Subscribe to Exforsys Free Training via email


Get Latest Free Training Updates delivered directly to your Inbox...

Enter your email address:


 

Subscribe to Exforsys Free Training via RSS
 

 
Partners -  Privacy and Legal Policy -  Site News -  Contact   Sitemap  

Copyright © 2000 - 2009 exforsys.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape