Ques >  What is difference between a procedure & function ?
Ans : Below is few differences between Function and Procedure:

1. Function is mainly used in the case where it must return a value. Where as a procedure may or may not return a value or may return more than one value using the OUT parameter.
2. Function can be called from SQL statements where as procedure can not be called from the sql statements 
3. Functions are normally used for computations where as procedures are normally used for executing business logic. 
4. You can have DML (insert,update, delete) statements in a function. But, you cannot call such a function in a SQL query.
5. Function returns 1 value only. Procedure can return multiple values (max 1024). 
6.Stored Procedure: supports deferred name resolution. Example while writing a stored procedure that uses table named tabl1 and tabl2 etc..but actually not exists in database is allowed only in during creation but runtime throws error Function wont support deferred name resolution. 
7.Stored procedure returns always integer value by default zero. where as function return type could be scalar or table or table values
8. Stored procedure is precompiled execution plan where as functions are not.
9.A procedure may modify an object where a function can only return a value The RETURN statement immediately completes the execution of a subprogram and returns control to the caller. 

Ques >  Why calculation part is performed within Functions?
Ans :  Procedure is Pre-compiler and function is not Pre-compiler, that's why we need function to perform calculation.


Ques :  can we create a sequence which start with 1 and next value will be 0 and then next value is 1 and then 0 .. and so on ... is this possible ? 
Ans :  

 SQL > 

Create Sequence Test_Seq_A
Start With 1
Minvalue 0
Maxvalue 1
Increment By -1
Nocache
Order
Cycle ;

SQL > INSERT INTO department(deptno) VALUES(test_seq_a.nextval);

SQL > SELECT * FROM department;

output :
1
0
1
0
1
0..


0 comments:

Popular Posts

Blogger templates

Blogger news

Blogroll

Powered by Blogger.

Labels

Followers

Follow us on FaceBook