Exact difference between function and procedure

exact difference between function and procedure(real time diff.....not like return value, dml....) and function do some work at the same time that work also do procedure..why function

ranitB wrote:
1. Function is called Inline a query. A return value is must.
But, procedure may/may not contain a return value.Not true.
A function may be called in a query providing it meets certain limitations (no DDL, or transactional statements such as commit/rollback etc.).
A function does not have to be called from a query, it can be called from other PL/SQL code or from other external applications.
Regular functions must return a value, though pipelined functions do not...
SQL> CREATE OR REPLACE TYPE split_tbl IS TABLE OF VARCHAR2(32767);
  2  /
Type created.
SQL> CREATE OR REPLACE FUNCTION split (p_list VARCHAR2, p_delim VARCHAR2:=' ') RETURN SPLIT_TBL PIPELINED IS
  2      l_idx    PLS_INTEGER;
  3      l_list   VARCHAR2(32767) := p_list;
  4      l_value  VARCHAR2(32767);
  5    BEGIN
  6      LOOP
  7        l_idx := INSTR(l_list, p_delim);
  8        IF l_idx > 0 THEN
  9          PIPE ROW(SUBSTR(l_list, 1, l_idx-1));
10          l_list := SUBSTR(l_list, l_idx+LENGTH(p_delim));
11        ELSE
12          PIPE ROW(l_list);
13          EXIT;
14        END IF;
15      END LOOP;
16      RETURN;
17    END SPLIT;
18  /
Function created.
SQL> SELECT column_value
  2  FROM TABLE(split('FRED,JIM,BOB,TED,MARK',','));
COLUMN_VALUE
FRED
JIM
BOB
TED
MARK... whilst the definition of the function shows a return type, the return statement inside the function simply returns, without a value. That's because the data is passed back through a special "pipeline", and you can write code to show that the data is available to a query as soon as it's piped, and before the function has completed (reached the return statement) if you like.
A procedure does not return a value (And no an OUT parameter is not a "returned" value, it's a writeable parameter, there's a difference)
2. There are some limitations in functions which is possbl through procedures.
Like - Oracle doesn't support DML in functions called in Select queries (using PRAGMA AUTONOMOUS_TRANSACTION will help).Not strictly true. and SQL query is considered to be DML, so a function could perform a query and then be used inside another query...
SQL> ed
Wrote file afiedt.buf
  1  create or replace function f_dname(p_deptno in number) return varchar2 is
  2    v_dname varchar2(10);
  3  begin
  4    select dname into v_dname
  5    from   dept
  6    where  deptno = p_deptno;
  7    return v_dname;
  8* end;
SQL> /
Function created.
SQL> ed
Wrote file afiedt.buf
  1* select empno, ename, f_dname(deptno) as dname from emp
SQL> /
     EMPNO ENAME      DNAME
      7369 SMITH      RESEARCH
      7499 ALLEN      SALES
      7521 WARD       SALES
      7566 JONES      RESEARCH
      7654 MARTIN     SALES
      7698 BLAKE      SALES
      7782 CLARK      ACCOUNTING
      7788 SCOTT      RESEARCH
      7839 KING       ACCOUNTING
      7844 TURNER     SALES
      7876 ADAMS      RESEARCH
      7900 JAMES      SALES
      7902 FORD       RESEARCH
      7934 MILLER     ACCOUNTING
14 rows selected.It's been discussed many times on the forum... my favourite here...
{message:id=1668675}
Edited by: BluShadow on 17-Sep-2012 09:22

Similar Messages

  • Difference between function and procedure

    Hi all,
    Please send me the difference b/w functions and procedures.
    Regards
    dskumar

    A procedure may(1 or many) or may not return a
    value,I have yet to see a procedure returning a value. Whilst it can pass out values using OUT and IN OUT parameters, it doesn't RETURN values.
    A function always returns one value.A function may also include OUT and IN OUT parameters to pass back values but it's not recommended.

  • Re: Difference between function and procedure

    Hello Oracles Guru’s,
    I am learning Oracle and I am beginner. My question may be simple and not worth to ask but I am sorry
    Why we call Procedures as Stored Procedure but we call functions only functions.
    As per my understanding I think but the objects are stored as objects in the database.
    Please clarify.

    HIJACKED THREAD!
    Please don't hijack another user's thread.
    If you have a question or issue create a new thread and ask it.

  • What is the difference between function and method

    Hey I need help I dont know which is the difference between function and method ?
    Does anybody can ask me this question.
    Thanks

    jverd wrote:
    The first two answers were also correct.Also the blocked message, quoted here for posterity:
    "Tinkerbell" wrote:
    Methods are defined by Java whereas functions are not. ~

  • Exact  difference between se09 and se10

    Hi all,
    i want to know the exact difference  between se09 and se10  .
    i know
    SE09 is the workbench transport requests transaction - here the developers can track changes to all ABAP workbench objects (dictionary, reports, module pools, etc). This is a developer-specific transaction and mostly all developers have access to this transaction.
    SE10 is the customizing request display transaction - this displays all the customizing requests in the system. Again, this could be restricted to Business analysts if required, since they would be doing most of the customizing changes in the system.
    but i think this is not the correct answer which is  already appear in the thread list
    recently sombady has answer like the one which i have mentioned above but the interviwer said that this is wrong.
    CAN ANYONE TELL ME THE EXACT ANSWER AND HELP ME OUT.
    Regards
    fareed

    Hi Fareed,
      First of all, i would say its a nice obsevation. As soon as i saw your post i started checking both transactions in seperate window and i found something interesting.
    My Observation is as follows:-
    <b>When we create a Transaction, apart from the Transaction Name, Program Name, Screen Number etc., we also can give someting called "AUTHORIZATION FOR CALLED TRANSACTIONS", under the menu: UTILITIES of the window.
    Also we can use TRANSACTION:SE97, Maintain Transaction call Authorization in CALL TRANSACTION. Here we maintain the list of TRANSACTION CALLED for our Calling Transaction.
    Now if you see, this list for Transaction SE09 and SE10, The Authorization for Called Transaction Differs a lot. Hence the difference bettween SE09 and SE10 is mainly the AUTHORIZATION Objects.</b>
    <b>NOTE:</b> This is my own observation, so there are chances of misinterpretation from my side, accounting to the human err. But this is something new to me too.
    Thanks and regards,
    RAVI :).
    PLEASE AWARD POINTS IF YOU FEEL MY SOLUTION TO YOUR QUESTION IS RIGHT $-).

  • Exact difference between VOimpl and VORowimpl and EO.

    Can anybody tell me whats the exact difference between
    VOimpl and VORowimpl and EO.
    Thanks

    Entity Object :BC4J entity objects encapsulate the business rules (validations, actions and so on) associated with a row in a database table, view, synonym or snapshot.
    View Object : (ViewImpl)
    In the simplest terms, a BC4J view object encapsulates a database query and provides iteration over and access to the view rows in its result set.
    View Row : ViewRowImpl :
    Represents a single row in a view object.
    For more Details see OA Developer Guide.
    Thanks

  • What is exact difference between table and template in script

    hello all
    what is exact difference between table and template in script

    Hi there.
    Tables alow you to achieve more complex flows with internal tables. You can use different types os lines, like footer, header, line items, and differente types of line items. Also, and most important, you have different processing blocks, again header block (processed before processing of first row), body block (rows) and footer block (after last row or page break).
    If you don't need any of this, use a template inside a loop to achieve something like a table. I personaly use templates only to draw lines, for example, before and after a loop, or to align some header in my documents.
    A table, is a loop and template mixed to become a very good tool.
    Regards.
    Valter Oliveira.
    Edited by: Valter Oliveira on Jun 5, 2008 5:10 PM

  • Difference between Function and Stored Procedure

    Hi guys, i don't understand the exact difference between a function and a stored procedure. I did lot of google but still. Can somebody explain in simple words. Thanks.

    Hi,
    Here's an example of a user-defined function:
    CREATE OR REPLACE FUNCTION     factorial
    (      in_num       IN     PLS_INTEGER
    RETURN     PLS_INTEGER
    DETERMINISTIC
    IS
    BEGIN
         IF  in_num IS NULL
         THEN
              RETURN     NULL;
         ELSIF in_num <= 1
         THEN
              RETURN  1;
         ELSE
              RETURN  in_num * factorial (in_num - 1);
         END IF;
    END     factorial;
    SHOW ERRORSThis function retruns an integer. You can use the function (or, more properly, the integer that it returns) anywhere an integer expression is allowed.
    For example
    SELECT     ROWNUM
    ,     factorial (ROWNUM)     AS f
    ,     loc
    ,     SUBSTR ( loc
                , 1
                , factorial (ROWNUM)
                )          AS s
    FROM     scott.dept;Output:
    `   ROWNUM          F LOC           S
             1          1 NEW YORK      N
             2          2 DALLAS        DA
             3          6 CHICAGO       CHICAG
             4         24 BOSTON        BOSTON

  • What is exact difference between PPM and PDS

    Hi,
    can any one prove details of Difference between PPM and PDS
    Thanks
    suresh

    Dear Suresh,
    please find below the detailed comparative account of PDS Vs PPM. You can copy and put it in an excel sheet in different columns and then read which is easy to understand.
    PDS:
    1. Production Data Structure (PDS) in APO 3.1 & Run Time Object (RTO) in 4.0 and above versions
    2. Master Data Object
    3. Useful for scenarios where the compoenent has got different validity periods
    4. Used as Master data Basis for Planning in SAP-APO
    5. Contains active Master data from iPPE (Integrated Product and Process Engineering) generated from a production version
    6. PPDS PDS & SNP PDS can be used as master data for planning
    7. Change Management, variant configuration & Phantom assemplies are supported in PDS
    8. Sub-contracting in SNP is fully integrated with R/3 is supported in PDS
    9. Direct transfer of SNP PDS from R/3 is possible
    10.Rapid Planning Matrix can be generated
    11. Not possible to maintain PDS directly in APO and can be used only in combination with R/3
    12. The transfer of data changes is simpler
    13. Not possible to create alternate SNP-PDS in std system for different mode combinations
    14. PDS can be automatically generated from two sources ie R/3 and iPPE
    PPM:
    1. Production Process Model
    2. Master Data Object
    3. Cannot be used for scenarios where the component has got different validity period
    4. Used as Master data Basis for Planning in SAP-APO
    5. Contains active Master data generated from the combination of routing (BoM & receipe) and production versions
    6. PPDS PPM & SNP PPM's can be used as master data for planning
    7. Not supported by PPM
    8. Not supported by PPM
    9. Not possible here. SNP PPMs will be generated via PPDS PPMs
    10. Not possible
    11. PPMs can be directly created in APO and can be modified without R/3 also.
    12. Little Complex when compared to PDS
    13. Alternate SNP-PPMs can be easily created
    14. PPM can be generated automatically generated only from R/3

  • Difference between Function and Automated Activity

    Hi All,
    After struggling with a few BPA Suite/JDev compatibility issues over the past few days, we've finally got a basic setup up and running (JDev 11.1.1.1 worked - 11.1.1.2 did not).
    I'm new to BPA and have 2 fairly basic questions - haven't found conclusive answers to these and hence, raising it on this forum...
    1. What is the difference between a "Function" and an "Automated activity" in the BPA Suite? I had expected the latter to translate to a BPEL invoke but what appears to happen is:
    - "Function" tranlsates to a BPEL Scope + Invoke.
    - "Automated activity" translates to a BPEL Scope + Empty Task.
    Based on this, I would not plan to use a "Function" for web service invocations but not sure where I would use the automated activities.
    2. Is there a BPMN construct that would translate to a BPEL "Assign"? I understand that an Assign is fairly low-level and would normally be expected to be filled in by the BPEL developer (and not by the Business Analyst specifying the BPMN model) but it would be quite handy to be able to specify this in BPMN in some cases..
    Thanks..
    TBKol
    Edited by: TBKol on Apr 23, 2010 4:58 AM

    Hi All,
    After struggling with a few BPA Suite/JDev compatibility issues over the past few days, we've finally got a basic setup up and running (JDev 11.1.1.1 worked - 11.1.1.2 did not).
    I'm new to BPA and have 2 fairly basic questions - haven't found conclusive answers to these and hence, raising it on this forum...
    1. What is the difference between a "Function" and an "Automated activity" in the BPA Suite? I had expected the latter to translate to a BPEL invoke but what appears to happen is:
    - "Function" tranlsates to a BPEL Scope + Invoke.
    - "Automated activity" translates to a BPEL Scope + Empty Task.
    Based on this, I would not plan to use a "Function" for web service invocations but not sure where I would use the automated activities.
    2. Is there a BPMN construct that would translate to a BPEL "Assign"? I understand that an Assign is fairly low-level and would normally be expected to be filled in by the BPEL developer (and not by the Business Analyst specifying the BPMN model) but it would be quite handy to be able to specify this in BPMN in some cases..
    Thanks..
    TBKol
    Edited by: TBKol on Apr 23, 2010 4:58 AM

  • Differnce between function and procedure....

    Hi Experts,
    I have query,When will use procedure or function..
    means:
    in what situation we will use fuction,
    and which scenario will use procedure?
    Can you please explain....?
    Thanks in advance....

    992368 wrote:
    Hi Experts,
    I have query,When will use procedure or function..
    means:
    in what situation we will use fuction,
    and which scenario will use procedure?
    Can you please explain....?
    Thanks in advance....Did you try to search this forum. This question has been asked lot of time. The search feature is not very good here may be use GOOGLE with the SITE tag to search. [url http://www.google.com/#safe=strict&output=search&sclient=psy-ab&q=site:forums.oracle.com+function+vs+procedure&oq=site:forums.oracle.com+function+vs+procedure&gs_l=hp.3...6856.24993.0.25236.54.43.6.0.0.0.428.9494.0j10j21j6j1.38.0...0.0...1c.1.15.psy-ab.eIfpP4zL0fM&pbx=1&bav=on.2,or.r_qf.&bvm=bv.47244034,d.cGE&fp=2bbc6037bd7feb17&biw=1024&bih=597]Something like this

  • Exact differences between Studio and Express, thinking of downgrading.

    Hi - I have a brand new copy of Logic Studio 9. I think Logic itself is wonderful, and I'm interested in some of the other tools such as the Apple loop Utility and the contents of the Jam Packs etc. What I found thought is that maybe I should have bought the Express edition instead since the likes of SoundTrack Pro, WaveBurner, Compressor and all the distributed cluster management software is way over powered for what I want to do, and I'll probably rarely use them. Mainstage I'm divided on - it might be useful but I could equally do without it.
    So what I'd like to know is, is the Logic in the Express edition exactly the same as in Studio, and does Express include the Loop Utility and the Jam Packs? If I sell my copy of Studio and downgrade to Express then will I lose any of these things?

    You ask about the loops utility - you don't get that. You do get 1000 or so loops (as opposed to 20K with Studio), no 40gigs of Jampacks. Full install of Express is 8gigs.
    Editing and whatnot is the same, flex, varispeed, etc. Amp designer stuff is the same.
    Can't say all the diffs, but you don't get Sculpture, Space Designer, or Delay designer.
    Not sure about ES2, the Clavinet, maybe things like Match EQ, AdLimit, LinPhase EQ, vocoder. I think at least a couple of those are not in Express.

  • Doubts in Functions and Procedures

    Hi Everybody,
    Can anybody tell the exact differences between function and the Procedure?
    My doubts are
    1. if procedure can return, and not necessary that it has to return a value,(that means if we want to return and doesnt also we can write procedure) then why do we need function?
    2. I tried to call a function which updates one table in the code,, i got an error saying that the function should not use DML.
    3. I want to know the combination that
    a. can procedure call a function and viceversa?
    b. can function (which uses DML statements)be called from sql statement ?
    and if any other combinations are there let me know with reasons.
    Thanks in advance,
    Vinay

    To elaborate on the already correct answers...
    user12281717 wrote:
    Can anybody tell the exact differences between function and the Procedure?
    My doubts are
    1. if procedure can return, and not necessary that it has to return a value,(that means if we want to return and doesnt also we can write procedure) then why do we need function?Procedures and Functions are self contained blocks of executable code. When that code completes it has to "return" to whatever called it, so both Procedures and Functions do return, however a procedure has an implicit return when it reaches the end of the code (or you can specify the keyword RETURN without any value if you like), whereas a function must contain a RETURN keyword before reaching the END keyword and a value of the correct datatype must be returned by that RETURN keyword.
    Functions must return a value, whereas Procedures do not return any value.
    If values need to be passed back from a procedure then OUT or IN OUT parameters are used, however if values are to be passed back then often it is something that should be considered for being a function rather than a procedure.
    Functions may also contain OUT or IN OUT parameters, but these types of parameters limit the function to use within PL/SQL code only and prevent them from being used in SQL, as the SQL engine will have no variable to pass back the OUT value into. Generally it is considered bad practice to use OUT or IN OUT parameters in functions.
    The underlying internal differences of Functions and Procedures comes down to how values are passed in and returned via the internal stack or via memory references where the parameter is specified as an OUT / IN OUT with NOCOPY. If you're not familiar with writing machine code / assembly language or low level C code, then this concept will probably be alien to you and it will take more than a simple post to explain it.
    2. I tried to call a function which updates one table in the code,, i got an error saying that the function should not use DML.Functions can contain DML, but those functions can only be used from a PL/SQL call to it, not from within a call from an SQL DML itself. i.e. a DML cannot contain further DML.

  • Use of function and procedures

    when we need to use function rather than procedure or viceversa???

    Welcome to the forum!
    Use a function if you want to use the value it returns as you would use any other expression in a SQL statement:
    SELECT  SYSDATE
    ,       my_function (column1)  AS c1
    ,       UPPER (column2)        AS c2
    FROM    table_x;or in PL/SQL:
    IF  my_function (x) > 0  THEN  ...Use a procedure otherwise; for example, if there is no value to be passed back.
    Functions can have OUT (and IN OUT) arguments, but they can cause confusion. Many people use procedures whenever they need OUT arguemnts, which includes all situations where 2 or more values are passed back.
    Any good book or site on PL/SQL, or any kind of procedural programming, should explain the differences between functions and procedures.
    If you don't have at least that much guidance, it's better not to try using PL/SQL.

  • Difference between function module and subroutines

    hey all...
    can u pls explai me the exact difference between subroutines and function modules...
    also, when is a sub routine used and also when is a function module used..???
    regards..
    vishal

    Hi Vishal,
    Basically they do the same thing and purpose is almost same but tecnically the are way apart:
    Function modules must belong to a pool called a function group.
    They possess a fixed interface for data exchange. This makes it easier for you to pass input and output parameters to and from the function module.
          For example, you can assign default values to the input parameters. The interface also supports exception handling. This allows you to catch errors and pass them back to the calling program for handling.
    They use their own memory area. The calling program and the function module cannot exchange data using a shared memory area - they must use the function module interface. This avoids unpleasant side effects such as accidentally overwriting data.
    You call a function module by its name (which must be unique) in a CALL FUNCTION statement.
    and also
    Unlike subroutines, you do not define function modules in the source code of your program. Instead, you use the Structure link Function Builder.
    Check this link too
    Re: Regarding difference between Subroutines and Function modules
    Hope this helps you,
    Regards
    Amit
    Message was edited by: Amit Kumar

Maybe you are looking for