Skip to Main Content

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Sudhakara.

Asked: January 21, 2016 - 10:42 am UTC

Last updated: January 21, 2016 - 11:25 am UTC

Version: 10.0

Viewed 1000+ times

You Asked

1)What is the use of plsql function?
2)Advantages and disadvantages of function?
3)can we use DML operations in function?
4)can function support OUT parameter?
5)when we will use functions in real time?Explain with a small example?
6)we have already procedures,then what is the necessity of using functions in oracle?
7)How many Return statements can we place in function?
8)can we return multiple values by using functions?

and Chris said...

Please avoid multi-part questions. It makes the answers harder to follow and takes us longer write them. Limit number of points you ask to 3 at most.

1. To take a number of inputs and return a value based on these.

2. You can call functions from SQL. You can't do this with procedures.

If you want to return multiple variables, this is best done with out parameters in a procedure.

You can create indexes on the result of functions, but not procedures. There is also the result cache available for functions.

3. Yes. But not if you call it from SQL (ignoring autonomous transactions).

4. It does. But this defeats the point of functions. If you're doing this, then you should use a procedure.

5. I don't understand what you mean by "real time". You're always calling functions in "real time".

6. See 2.

7. As many as you want. It's not really a good idea though. It makes the logic harder to follow.

8. You can return arrays, records and arrays of records. If you mean multiple different variables, see 4.

If you want more details, I suggest you read the documentation on PL/SQL subprograms:

http://docs.oracle.com/database/121/LNPLS/subprograms.htm#LNPLS008

Is this answer out of date? If it is, please let us know via a Comment

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library