Difference of procedure & function

Hi all

After citing some tutorials, I got to know that the difference between the procedure and the function is that the procedure may or may not return a value as the function must return a value to the calling program. Given below is my procedure. & He would compare the lower of the two numbers would be smaller than

create or replace procedure findmin

(

x in number,

there in numbers,

z series

)

is

Start

if(x<y) then

z: = x;

on the other

z: = y;

end if;

end;

declare

c number;

Start

findmin (23,45,c);

dbms_output.put_line (c);

end;

Here's my function even if it does the same thing.

create or replace function findmin_fun

(

x in number,

y number

)

Return number

is

number of z;

Start

if(x<y) then

z: = x;

on the other

z: = y;

end if;

Return z;

end;

declare

Start

dbms_output.put_line (findmin_fun (56,28));

end;

I would like to know under what are all the scenarios of the procedure and function would be used. And also I want to know could do dml as insert, update, and delete operations

If so, could you guys explain me with some examples to expose DML operations on functions

After citing some tutorials, I got to know the difference between the procedure & function is that the procedure may or may not return a value as the function must return a value to the calling program.

Not quite.

A procedure does NOT return a value - it can fill in the parameters OUT or INOUT but which is NOT considered to be "of return values.

A function ALWAYS returns a value that can be null. The only exception is if the function throws an exception.

My procedure is given below. It would be to compare the lower of the two numbers & would mean that smaller

Not quite - the procedure returns NO value. You use it to try to fill one OUT parameter, but it's NOT the same.

I would like to know under what are all the scenarios the procedure & function would be used.

Functions can be used in SQL; procedures cannot be used in SQL.

The functions return a value; procedures of does NOT return a value.

Use the functions when you need to return a value; Use the procedures when you do NOT need to return a value.

It is not possible to list 'all scenarios' for one or the other, because there may be ANY NUMBER of possible scenarios.

And also I want to know could do dml as insert operations, update & delete

What happened when you tried?

The best and fastest, to learn is to actually TRY THINGS. Don't be afraid to break the Oracle by actually writing code and tests of things yourself.

If so, could you guys explain me with some examples to expose DML operations on functions

The Oracle documentation have a LOT of examples of using functions and procedures and include the code of the example.

https://docs.Oracle.com/CD/E11882_01/AppDev.112/e25519/subprograms.htm#CHDBEJGF

The internet has even more examples of code.

Tags: Database

Similar Questions

  • What is the difference between procedure and function?

    Hello
    I want to know the difference between procedure and function.
    Also, I want to know the types (if any) of procedures and functions.

    Concerning

    A function requires a return value.

    A procedure, while allowing the option PARAMETERS, mandates without return.

  • Difference of procedure package Vs

    In addition to an overload and private subprogrammes, what is the advantage of the procedure/function created within a packet on Stand Alone procedures in terms of performance.

    What will be the difference in the behavior of stand-alone procedure/function and procedure/function inside the package if both are called by 100 different user one by one. Will the charge procedure 100 times for each call or not?

    Can someone give me more clearity on these points:

    Best performance - packages can be compiled and are loaded into memory in full and not piecemeal as other methods. This advantage if at all there is minimal compared to other services.

    Invalidation reduced - change a package body does not invalidate the dependencies to change a function or procedure.

    Hello

    Kimmy says:

    Thanks for the links that I read the post before and then I posted this discussion for more clearity...

    Any code that is executed is loaded into the Cache of the bookstores and remain in the library Cache until it is aged by the LRU algorithm. So if there are a 100 calls to a stand alone procedures be there in the Cache/memory?

    If not why not?

    If Yes... So how this behavior differs from the behavior of charge of the public procedure within a package?

    There is nothing special about 100 calls.  A procedure (or package) might be aged after 1 call or after 100 calls, or it can remain in cache after 1 call or after 100 calls.

    The difference between stand-alone procedures and packages in this regard is that all remains in the cache, or gets old, together.  So if you have requested that a procedure in the package, as this package is cached, then the 1st time you call another procedure in this package it will already be in memory.

    Other differences between packages and stand-alone procedures:

    A package can have variables and types defined in package specifications and so can be used by other users.  (With the help of ouutside of package variables to the package, instead of using functions, maybe not a good idea, however.)

    Change a package body is invisible to dependent objects.  If you change just the package body, no other packages or views will be become disabled or need to be recompiled.

  • What is the difference between size function and aggragate function?

    Hi Experts,

    In OBIEE 11.1.1.6.0, what is the difference between size function and aggragate MDB measure column function?
    If it contains material or detail information, I am very grateful to you.

    Hello

    Good example with screenshots-

    http://www.clearpeaks.com/blog/Oracle-BI-EE/aggregation-based-on-dimensions

    Mark this reply / helped.

    Concerning
    Young

  • Updated APEX collection error ORA-04044: procedure, function, package, type

    Hi all

    I am trying to update the APEX MEMBER of the COLLECTION and encounter errors:


    1 error has occurred
    ORA-06550: line 9, column 8: PL/SQL: ORA-04044: procedure, function, package or type is not allowed here ORA-06550: line 7, column 3: PL/SQL: statement ignored

    The PLSQL code are as below

    DECLARE
    entire x;
    v_date_started VARCHAR2 (255);
    v_date_finished VARCHAR2 (255);
    BEGIN
    SELECT c.seq_id
    X
    OF APEX_COLLECTION c
    WHERE collection_name = "PHASE_COLLECTION."
    AND c001 =: P41_MPM_ID
    and rownum = 1;
    v_date_started: =: P41_DATE_STARTED;
    v_date_finished: =: P41_DATE_FINISHED;

    APEX_COLLECTION. () UPDATE_MEMBER
    p_collection_name = > 'PHASE_COLLECTION '.
    , p_seq = > x
    , p_c004 = > v_date_started
    , P_c005 = > v_date_finished
    );
    END;


    The process will take place after SUBMIT and validation.

    The code I used to add a colletion APEX will work perfectly and is as below

    -Initialization Collection PHASE_COLLECTION
    BEGIN
    IF THIS ISN'T APEX_COLLECTION. COLLECTION_EXISTS('PHASE_COLLECTION') THEN
    APEX_COLLECTION. CREATE_COLLECTION ('PHASE_COLLECTION');
    ON THE OTHER
    APEX_COLLECTION. TRUNCATE_COLLECTION ('PHASE_COLLECTION');
    END IF;
    -Add members to the COLLECTION PHASE of table PHASE_MEMBERSHIP
    IF: P41_MPM_ENG_ID IS NOT NULL THEN
    FOR x IN (SELECT mpm_id, mpm_eng_id, phase_number, date_started, date_finished, date_created
    OF phase_membership
    WHERE mpm_eng_id =: P41_MPM_ENG_ID
    AND active = 1
    ORDER BY date_created)
    LOOP
    APEX_COLLECTION. ADD_MEMBER
    (p_collection_name = > 'PHASE_COLLECTION')
    , p_c001 = > x.MPM_ID
    , p_c002 = > x.MPM_ENG_ID
    , p_c003 = > x.PHASE_NUMBER
    , p_c004 = > x.DATE_STARTED
    , p_c005 = > x.DATE_FINISHED
    , p_c006 = > x.DATE_CREATED

    );
    END LOOP;
    END IF;
    EXCEPTION
    WHILE OTHERS THEN
    Logger.Error (p_message_text = > SQLERRM)
    , p_message_code = > SQLCODE
    , p_stack_trace = > dbms_utility.format_error_backtrace
    );
    LIFT;
    END;


    What I tried to use APEX_COLLETION to check the overlap between the date_range.
    The requirement is just to display a warning if the user adds a record to the new phase or update record of current phase may overlap between the order of phase together.
    Table PHASE_MEMBERSHIP script is

    CREATE TABLE 'PHASE_MEMBERSHIP '.
    (
    ACTIVATE THE "MPM_ID" NUMBER NOT NULL,
    ACTIVATE THE "MPM_ENG_ID" NUMBER NOT NULL,
    ACTIVATE THE "PHASE_NUMBER" NUMBER (2.0) NOT NULL,
    "DATE_STARTED" DATE NOT NULL ACTIVATE.
    DATE OF THE "DATE_FINISHED."
    'NOTES' VARCHAR2 (2000 BYTE),
    'DATE_CREATED' DATE NOT NULL ACTIVATE.
    ACTIVATE THE 'CREATED_BY' VARCHAR2 (20 BYTE) NOT NULL,
    NUMBER (2.0) 'ACTIVE' DEFAULT 1 ACTIVATE NOT NULL)

    So, basically, I want to fill the documents associated with a particular to a collection of APEX called PHASE_COLLECTION MPM_ENG_ID.
    Then when the user specify date_started and date_finished, it will update/insert the APEX collection first.
    Then the rank based on audit collection date
    http://www.Oracle-base.com/articles/Misc/overlapping-date-ranges.php
    then display the warning to ask the user to confirm message.

    But then I'm stuck at the step of updating COLLECTION of APEX.

    If anyone has any ideas on what is wrong, please help.

    Thanks in advance.

    Ann

    Your syntx error line number should give you the trick - it is not a member of the update, rather the SQL - you are referring to apex_collection, not apex_collections view dictionary.

    Scott

  • Build a complicated procedure/function

    Hello world

    I am creating a complicated procedure.

    I have three columns:
    line     A          B        C
    1       5.5       3.2       -
    2       1.05     6.1       -
    3        0.6      7.8       -
    4        6.4     4.13      -
    5         -         -        8.98
    Column C contains a result. So, I need to find how this result was built. In other words, this procedure/function must answer the question:
    What are the numbers in columns A and B, which has contributed to achieve this result.
    In this example, we found that:
    C = B(1) + A(2) + A(3) + B(4) = 3.2 + 1.05 + 0.6 + 4.13 = 8.98
    (there is a condition: we cannot do so one number per line is selected.: A(1) + B(1).)

    Concerning

    Published by: zakaria84 on May 22, 2009 15:25

    Published by: zakaria84 on May 22, 2009 15:49

    Hello Zakaria,

    Here is a right solution with SQL:

    SQL> create table giventable (a,b,c)
      2  as
      3  select 5.5, 3.2, null from dual union all
      4  select 1.05, 6.1, null from dual union all
      5  select .6, 7.8, null from dual union all
      6  select 6.4, 4.13, null from dual union all
      7  select null, null, 8.98 from dual
      8  /
    
    Tabel is aangemaakt.
    
    SQL> create table resulttable as select * from giventable where 1=0
      2  /
    
    Tabel is aangemaakt.
    
    SQL> insert into resulttable
      2  select a
      3       , b
      4       , null
      5    from ( select case mod(trunc(l/power(2,line)),2) when 0 then a else null end a
      6                , case mod(trunc(l/power(2,line)),2) when 1 then b else null end b
      7                , sum(case mod(trunc(l/power(2,line)),2) when 0 then a else b end) over (partition by l) x
      8             from ( select a
      9                         , b
     10                         , row_number() over (order by null) - 1 line
     11                      from giventable
     12                     where c is null
     13                  )
     14                , ( select level - 1 l
     15                      from dual
     16                   connect by level <= power(2,(select count(*) from giventable where c is null))
     17                  )
     18         )
     19   where x = (select c from giventable where c is not null)
     20   union all
     21  select null
     22       , null
     23       , c
     24    from giventable
     25   where c is not null
     26  /
    
    5 rijen zijn aangemaakt.
    
    SQL> select * from resulttable
      2  /
    
             A          B          C
    ---------- ---------- ----------
                      3,2
          1,05
                     4,13
            ,6
                                8,98
    
    5 rijen zijn geselecteerd.
    

    Kind regards
    Rob.

  • DB procedure / function can return multiple values in a PL/SQL block

    Hi all


    I have a problem returning to the exit procedure following in PL/SQL because I have SELECT INTO variable but with no output back in my PL/SQL block even if I turned it into a function.


    . pls suggest.

    CREATE OR REPLACE PROCEDURE nominations (p_start_date AS, p_end_date IN DATE)

    IS

    v_day_id PLS_INTEGER;

    v_day_name VARCHAR2 (33);

    v_day_date DATE;

    BEGIN

    SELECT (2 + (p_start_date + (LEVEL - 1) + LEVEL - 1 - TRUNK (LEVEL - 1 + 1, "IW" + p_start_date)) AS day_id

    , TO_CHAR (LEVEL - 1, 'Day' + p_start_date) AS day_name

    , TO_CHAR (LEVEL - 1, "DD-MM-RRRR" + p_start_date) AS day_date

    IN v_day_id, v_day_name, v_day_date

    OF THE DOUBLE

    CONNECTION OF LEVEL < = 1 + p_end_date - p_start_date;

    END;

    /

    Your insert would be something like this:

    INSERT INTO PR_OPS_APPOINT_SETS (SPEC_CODE1, SPEC_CODE2, CLINIC_NO, SECTOR_ID, USER_ID, APPOINT_DATE)

    SELECT r.SPEC_CODE1, r.SPEC_CODE2, r.CLINIC_NO, r.SECTOR_ID, USER, d.APPOINT_DATE

    PR_OPS_CLINIC_RECS r

    CROSS JOIN)

    SELECT TO_DATE (TO_CHAR (LEVEL - 1, "MM/DD/RRRR" + p_start_date), "MM/DD/RRRR") AS APPOINT_DATE

    OF THE DOUBLE

    CONNECT BY LEVEL<= p_end_date="" -="" p_start_date="" +="">

    ) d

    WHERE SPEC_CODE1 = p_SPEC_CODE1

    AND SPEC_CODE2 = p_SPEC_CODE2

    AND CLINIC_NO = p_CLINIC_NO

    AND SECTOR_ID = P_SECTOR_ID;

    In terms of getting the parameters p_SPEC_CODE1, p_SPEC_CODE2, p_CLINIC_NO, P_SECTOR_ID...? I don't have enough information on your part.

  • Plan does not show the local procedures/functions

    Hello

    SQLD 4.1

    I use the preview to a plsql procedure feature. The procedure provides a local procedure.

    In the window structure the local procedure does not at all. Declared variables and cursors in the local procedure are displayed, but as if they where in the main proceedings.

    Local procedures and functions should be displayed in the window structure. It would be nice if the declares the variables and cursors of a local proceeding would be arranged in suchs a means, it is visible that they belong to this local procedure, perhaps using an indentation.

    Best regards

    Joop

    Hey, Joop!

    A mysterious person, known only as "SF" for the purpose of this response, has also reported this to me. We have filed a bug on this subject, and it shows as 'fixed' in 4.1.1.

  • Synonym, views, trigger, procedures, function - where these items will be present?

    Hi all

    Basic question:
    1 oracle objects as a synonym, trigger, procedures, views, function (of a particular user) where these items will be present? Is - this data dictionary user default tablespace or system?

    2. the user have create session, synonym to create, select any user of permission.and table have default tablespace DATA.

    (a) if the user has create any synonym it will store in the tablespace DATA?
    (b) if the user can able to select a table only or can see all notices and the level of database functions?


    Thank you

    903787 wrote:
    Sorry, I don't understand could you please it explain.

    After SQL & results that show how the synonym of space, function, view, & trigger consume in your DB.

  • solution in OWB, procedure/function

    I have different columns in different tables, with values 0 or 1.
    In the tables in the target, a 0 is no. and 1 Yes.

    What is the best way to implement this.
    a function/procedure on the database using as a transformation in OWB or
    is there a better solution in OWB.

    Another question: will I maps the columns separately or is there a way to map all columns through the 1 design element (transformation? expression?)?

    You will have problems with route mapping plug-in for the re-use of expressions since each use is considered to be a set of independent lines. That would leave functions as the first choice. ODI, reusable expressions can be made using the user-defined functions, with the latter in the code is placed online.

    See you soon
    David

  • Calc Manager differences Sub procedures

    Hi guys,.

    I was looking for the scripts for the rules in the Manager of Calc and noticed that any set of rules are of use (even if they are included in the routine of SubCalculate).

    From the point of view of a traditional .rle file, what are the differences? Are there changes when you use a sub procedure in the SubCalculate routine? As far as I know, there is no change.

    Thank you!

    Kind regards

    L.

    Manager of Calc's all simply a user interface for creating rules HFM, and therefore the traditional major subroutines continue to apply:

    -Calculate
    -Translate
    -Consolidate
    -Dynamic
    -Entry
    -NoInput
    -Allocate
    -Transaction
    -Capital own Pick Up

    Certainly when writing rules we can create more custom subroutines in subroutines main HFM above, but Calc Manager does not change this feature at all.

    -Chris

  • Tlist to reliable independent package/procedure/function

    I want to know the list of tables with is not in the package/procedure and function.

    I did a procedure to find a few tables, but do not come from this procedure. It is not also the view user_source. But the tables are usued on this particular package.


    create table procedure_name (proc_name varchar2 (30), varchar2 (30)) from table_name;

    CREATE OR REPLACE PROCEDURE prc_table_found IS
    cursor c1 is select table_name DISTINCT from user_tables;
    v_table_name varchar2 (30);
    v_str varchar2 (10000);
    TYPE t_procedure IS TABLE OF THE user_source.name%TYPE;
    l_tab t_procedure;
    BEGIN
    Open c1;
    loop
    Fetch c1 into v_table_name;
    OUTPUT WHEN c1% NOTFOUND;
    v_str: =' select distinct name from user_source
    where the text like ' | " ' ||' %'|| v_table_name | » %'||'''';
    dbms_output.put_line (v_str);
    execute immediate v_str in bulk collect into l_tab;
    If l_tab.count > 0 then
    for me in l_tab.first... loop of l_tab. Last
    Insert into procedure_name (proc_name, table_name) values (l_tab (i), v_table_name);
    commit;
    end loop;
    on the other
    null;
    end if;
    end loop;
    Close c1;
    END;

    exec prc_table_found;

    Select distinct table_name from user_tables
    less
    Select distinct procedure_name tbl_name
    ;

    Hello
    http://download.Oracle.com/docs/CD/B14117_01/server.101/b10755/statviews_2513.htm

    Something like that

    select *
      from user_tables t
     where t.table_name not in ( select distinct e.referenced_name
                                   from user_dependencies e
                                  where e.referenced_type = 'TABLE'
                               )
    

    Edited by: user6806750 the 14.10.2011 01:00

  • Can be passed to the formula of the procedure/function the column value?

    Cf_value is back after some calculation using the main request.

    Can be passed directly the value of column of formulas of procedure without assinged to placeorder?
    as below...


    f_convert(:cf_value,new_value);

    ---------------------------------------------------------------

    My procedure is...


    PROCEDURE f_convert (val1 val2 in number, number) IS

    BEGIN

    val2: = val1 * 100;

    END;


    If anyone knows pls answer me...

    In fact, if there is that other calculations he (in Proceudre)

    Can I used is like below?
    ---
    PROCEDURE f_convert (val1 val2 in number, number) IS

    BEGIN

    val2: = val1 * 100;

    return (val2);
    END;
    ----

    A procedure cannot return a value, the return in my previous post clause was part of the function for formula column.
    Let's say you have a column of forms of so-called CF_2, then the function because it will be like:

    function cf_2formula return number
    is
     val1 number;
     val2 number;
    begin
    
     val2 := :cf_1 * 100; -- or val2 := val1 * 100 --parameters not allowed in formula column function
    
     -- All the other code that you need inclusive of calling function, procedure as in any PL/SQL block can be placed 
    
     return (val2);
    
    end;
    

    Any calculation can be used in the service of the formula column

  • database procedure, function

    Hello
    The insert statement below is used in the procedure called "schedule_vehicle_cred_check."
    There are "vpp_error_log" for the "error_program" function name column in the table, I'm not able to understand this.
    could someone help?
    insert into vpp_error_log
                                  (
                                  error_id,
                                  error_type,
                                  error_message,
                                  error_date,
                                  error_program
                                  )
                                  values
                                  (
                                  null,
                                  '2',
                                  err_num ||':' ||err_msg ||','||' Error in vehicle credential check' || ref_rec.vpp_vehicle_seq_number,
                                  sysdate,
                                  'schedule_vehicle_cred_check' <----------------------
                                  );

    Muriel Ram wrote:
    Hello
    The insert statement below is used in the procedure called "schedule_vehicle_cred_check."
    There are "vpp_error_log" for the "error_program" function name column in the table, I'm not able to understand this.
    could someone help?

    insert into vpp_error_log
                                  (
                                  error_id,
                                  error_type,
                                  error_message,
                                  error_date,
                                  error_program
                                  )
                                  values
                                  (
                                  null,
                                  '2',
                                  err_num ||':' ||err_msg ||','||' Error in vehicle credential check' || ref_rec.vpp_vehicle_seq_number,
                                  sysdate,
                                  'schedule_vehicle_cred_check' <----------------------
                                  );
    

    This isn't a function name, it is just a literal string. Looks like it is the registration of the name of a program or procedure that took trapped in an error, but in the end, it is simply insert the literal "schedule_vehicle_cred_check" in the ERROR_PROGRAM column

  • How to get the date and time that a procedure/function has been modified for the last time?

    Hi all

    In Oracle Developer Tools for Visual Studio 2005 can I highlight a function, or a procedure and in the Properties window, it shows me the func/proc has been changed for the last time, and also when it was created

    Where can I get this information?

    See you soon
    CJ

    table object last_ddl_time

Maybe you are looking for

  • Satellite A105-S1712 - connection Wi - Fi dropping out in 15 minutes

    Hello my first ad... hope I understand... I checked the support Toshiba us site but nothing available to help, as countless other forums.A neighbor brought the PC above States and place a wi - fi network - with a Belkin router model network, Modem AD

  • There is no fast charge on bike G4?

    I just got my new bike G4 this Saturday I bought mainly because of problems I had with my old cellphone battery. Motorola/Lenovo says that new G4 Media the young man in charge that will provide up to 6 hours of battery life with 15 minutes of charge.

  • My Inbox weather?

    I had something appear on my iPhone 6 that looked as if it were a normal Appendix Alas, it seems to be. He seemed all right until he asked to be installed through settings. Now, it appears as an actual email address and it seems to be spam email. I t

  • Printing using Adobe Reader problems

    Sometimes when I try to print a PDF with Adobe Reader, it will print the first two pages OK, then the rest will be ruined. This may be the cause for this? Any thoughts would be much appreciated.

  • Cannot change the brightness and contrast on my 4540 s of HP ProBook with the software Intel(r) HD Graphics

    This was never resolved?  I'm having the same problem on the same computer that I can't manually adjust the brightness of the screen with the help of the function or function + F2, F3 keys screen brightness.