Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Rasitha.

Asked: April 04, 2017 - 3:02 am UTC

Last updated: April 04, 2017 - 10:01 am UTC

Version: 11g

Viewed 1000+ times

You Asked

what are the disadvantages of using Inline Queries instead of using Store Procedure?
what is the performance impact on Inline Queries Vs. Store Procedure?

thanks

and Chris said...

This question doesn't really make any sense. These aren't mutually exclusive options!

You can have an inline query inside a stored procedure:

create or replace procedure p is
  var int;
begin
  select col
  into   var 
  from (
    select 1 col from dual
  );
  
  dbms_output.put_line(var);
end p;
/
      
exec p;

PL/SQL procedure successfully completed.
1


In fact, it's a good idea to place all your queries in stored procedures. For more details on why, read Bryn Llewellyn's "Why PL/SQL?" whitepaper:

https://blogs.oracle.com/plsql-and-ebr/entry/why_use_pl_sql

But calling PL/SQL from SQL is generally not a great idea for a couple of reasons:

- It can slow your query down
- If the PL/SQL runs SQL, you can get unexpected/incorrect results!

The slowdown is due to context switches from SQL -> PL/SQL and back again:

http://www.oracle.com/technetwork/issue-archive/2015/15-jul/o45plsql-2543984.html

Though the 12c "pragma udf" does mitigate this:

https://mwidlake.wordpress.com/2015/11/04/pragma-udf-speeding-up-your-plsql-functions-called-from-sql/

To see why SQL calling PL/SQL calling SQL may give unexpected results, see:

https://blogs.oracle.com/sql/the-problem-with-sql-calling-plsql-calling-sql

Rating

  (1 rating)

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

Comments

Rasitha Ariyasingha, April 04, 2017 - 10:43 am UTC


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