Function & Procedure Help

CUST- customer_num, first_name, last_name
DELIVERY - customer_num, free_delivery
INVOICE- customer_num, delivery, item_num
INVENTORY - item_num, price
using just these columns from these tables i have to create a detailed report as to which customers have spent over $700 using a procedure or a function...I then will have to go back into the delivery table and change free_delivery to "YES"
I'm new to sql/pl and i've have tried so many different ways if any one could help me even begin with what directon i should go, I would be thankful
UPDATE DELIVERY SET free_delivery='YES'
WHERE customer_num IN(
SELECT C.customer_num
FROM CUST C
INNER JOIN INVOICE INV ON C.customer_num=INV.customer_num
INNER JOIN INVENTORY INVT ON INV.item_num=INVT.item_num
GROUP BY C.customer_num
HAVING SUM(INVT.price)>700)

I hope you want to convert the above query into a function block that can be called several times. If that is the case, the below block might help.
It will also allow you to pass the amount value by which you can update rows for dynamic amounts.
FUNCTION free_delivery (f_amount NUMBER)
   RETURN BOOLEAN
IS
   rvalue   BOOLEAN;
   v_rows_processed NUMBER;
BEGIN
   UPDATE delivery
      SET free_delivery = 'YES'
    WHERE customer_num IN (SELECT   c.customer_num
                               FROM cust c INNER JOIN invoice inv
                                    ON c.customer_num = inv.customer_num
                                    INNER JOIN inventory invt
                                    ON inv.item_num = invt.item_num
                           GROUP BY c.customer_num
                             HAVING SUM (invt.price) > f_amount);
   v_rows_processed := SQL%ROWCOUNT;
   if (v_rows_processed > 0) then
    rvalue = TRUE;
   else
    rvalue = FALSE;
   end if;                               
   RETURN rvalue;
END;If you want to commit the changes in the function itself it can be done, but not recommended.
Just add commit after the if loop.

Similar Messages

  • Function/Procedure help - just want to build simple query and show results

    I'd like a simple "histogram" function - perhaps there is one built-in I'm not aware of. I just want to count discrete values of a column. So I'm constantly writing queries of the form:
    select column_name, count(*)
    from table_name
    group by column_name
    order by column_name;
    and I'm trying to write a function that will allow me to just type:
    execute whatever(column_name, table_name)
    or select whatever(column_name, table_name) from ?
    and get the equivalent results from the query above.
    How do you, or can you, write a procedure to take column/table names as inputs, substitue them into a query, execute the query and just display the results of that query? As I'm trying to figure out how to do this via google search, I keep going down rabbit holes of creating temporary tables/data types/records/refcursors etc. and I can't get any of it to compile. I'm not a DBA or SQL expert, so I'm hoping there's a simple way to accomplish this (without having to store and then process the "results" one row at a time)

    If I understand the requirement correctly, a simple pipelined function will do it:
    Dynamic
    GROUP_VALUE                    NUM_RECS
    10                                    1
    20                                    2
    30                                    6
    40                                    1
    50                                   45
    60                                    5
    70                                    1
    80                                   34
    90                                    3
    100                                   6
    110                                   2
                                          1
    12 rows selected.
      1  SELECT *
      2* FROM TABLE (Gen_Counts.Group_Count ('EMPLOYEES', 'DEPARTMENT_ID'))
    Static
    DEPARTMENT_ID   COUNT(*)
               10          1
               20          2
               30          6
               40          1
               50         45
               60          5
               70          1
               80         34
               90          3
              100          6
              110          2
                           1
    12 rows selected.
      1  SELECT department_id, Count(*)
      2    FROM employees
      3   GROUP BY department_id
      4*  ORDER BY 1The types and package code is:
    CREATE OR REPLACE TYPE group_count_type IS OBJECT
        (group_value VARCHAR2(4000), num_recs NUMBER);
    CREATE OR REPLACE TYPE group_count_list_type IS TABLE OF group_count_type;
    CREATE OR REPLACE PACKAGE Gen_Counts IS
    FUNCTION Group_Count (p_tab_name VARCHAR2, p_col_name VARCHAR2) RETURN group_count_list_type PIPELINED;
    END Gen_Counts;
    CREATE OR REPLACE PACKAGE BODY Gen_Counts IS
    FUNCTION Group_Count (p_tab_name VARCHAR2, p_col_name VARCHAR2) RETURN group_count_list_type PIPELINED IS
      l_cur             SYS_REFCURSOR;
      l_rec_list    group_count_list_type;
      l_cur_str     VARCHAR2(1000) := 'SELECT group_count_type (' || p_col_name || ', Count(*)) FROM ' || p_tab_name ||
        ' GROUP BY ' || p_col_name || ' ORDER BY ' || p_col_name;
    BEGIN
      OPEN l_cur FOR l_cur_str;
      DBMS_Output.Put_Line (l_cur_str);
      LOOP
        FETCH l_cur BULK COLLECT
         INTO l_rec_list LIMIT 1000;
        EXIT WHEN l_rec_list.COUNT = 0;
        FOR i IN 1..l_rec_list.COUNT LOOP
          PIPE ROW (group_count_type (l_rec_list(i).group_value, l_rec_list(i).num_recs));
        END LOOP;
      END LOOP;
    END Group_Count;
    END Gen_Counts;
    /Edited by: BrendanP on 06-Sep-2012 07:18
    Just to be clear - I'm not saying it's a great idea to do that, just that's a way of doing it technically. I'd just use the static way myself.

  • Calling Function/Procedure from HTML_DB

    Hi,
    I am new to HTML_DB,i didn't even have a look and feel of the tool.My doubt is "Whether it is possible to call a Function/Procedure from a HTML_DB application,If so where i can find relevant documents".
    Please help me ASAP.
    Thanks,
    Siva.G

    Hi Siva,
    I assume you're talking about existing PL/SQL functions and procedures? The answer is yes you can call them easily.
    There's a great deal of documentation on OTN regarding Apex, which I would advise you to have a look through to get a better feel for how to use Apex -
    http://www.oracle.com/technology/products/database/application_express/index.html
    The 2-Day developer document is particularly worth having a look through -
    http://www.oracle.com/pls/db102/to_pdf?pathname=appdev.102%2Fb16376.pdf

  • How to improve function & procedure performence

    Hi,
    How to improve performence of function and procedure .
    When i have to use parallel_enable,deterministic features .
    thank you
    Edited by: 808542 on Dec 22, 2010 2:25 AM
    Edited by: 808542 on Dec 22, 2010 2:26 AM

    How to improve performence of function and procedure .Start with tracing the session that executes the functions/procedures and tkprof the trc. file (with wait events).
    The tkprof output will give you pointers where you could make some improvement.
    You can find many examples on http://asktom.oracle.com, do a search on 'tuning'
    For example:
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:6904032233295
    If you have no clue what all this means then ask your DBA to help you.
    See also the Performance Tuning Guide @ http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/toc.htm

  • Search function in Help not working in any application

    The Search function is not working in any application's Help. Upon entering the terms I need help for I get a hang at "Searching..." but never any result. This problem started sometime in the last year or so. Prior to that the search function in Help worked fine. My network connectivity is excellent.
    I recently reinstalled OS X 10.5 but I'm sure the problem existed before that and persisted after the reinstall.
    The reinstall was due to upgrading to 10.7 and only then finding that I had lost needed functionality, but I don't think this has anything to do with the current problem. All other aspects of Help seem to be working fine
    I don't find any reference to this problem anywhere so I'm hoping someone can help with my Help(!) problem. Thanks in advance.

    Try running your Leopard install disk again, as well as the 10.5.8 combo updater. This might reinstall any 'missing bits'.
    You can do this without deleting the hard drive, just install straight over your existing system, but close all applications and external devices first.
    Or you could also do this via an Archive and Instal:
    How to Archive & Install:
    http://support.apple.com/kb/HT1710
    and this also:
    http://support.apple.com/kb/HT2196?viewlocale=en_US
    This document explains how to correctly reinstall a prior version of Mac OS X in the event that other troubleshooting does not resolve an issue:
    http://docs.info.apple.com/article.html?artnum=25404
    BUT: Don't install older versions of Mac OS than what came with your computer:
    http://support.apple.com/kb/HT2186?viewlocale=en_US

  • Mac mini 2009 mavericks won't boot. Blank display no logo,etc. Tried all keyboard boot functions, no help. replaced RAM w/known good. No help. Removed HD mounted in external enclosure and ran permissions and repair. No help. Upgraded HD to Yosemite a

    Mac mini 2009 Mavericks won't boot. Chimes and power light comes on. USB ports have power. Blank display no logo,etc. Tried all keyboard boot functions, no help. Replaced RAM w/known good. No help. Removed HD and mounted in external enclosure and ran permissions and repair. No help. Upgraded HD to Yosemite and was able to boot another mini from HD mounted in external enclosure, reinstalled HD still no boot. Any ideas on how to proceed appreciated.

    - Make an appointment at the Genius Bar of an Apple store. You have a hardware problem.
      Apple Retail Store - Genius Bar

  • Is there any way to block the shutdown of the device is protected by password? This function would help in case of theft with the issue of the find my iphone app.

    is there any way to block the shutdown of the device is protected by password? This function would help in case of theft with the issue of the find my iphone app.

    Device experiences issues, locks up.
    I need to do a reset.
    How would I do that with a pass code lock in place?
    Wait until the battery dies?
    Apple's changes in iOS 7 are smarter.
    "Losing your iOS device feels lousy. Thankfully, Find My iPhone can help you get it back. But if it looks like that’s not going to happen, new security features in iOS 7 make it harder for anyone who’s not you to use or sell your device. Now turning off Find My iPhone or erasing your device requires your Apple ID and password. Find My iPhone can also continue to display a custom message, even after your device is erased. And your Apple ID and password are required before anyone can reactivate it. Which means your device is still your device. No matter where it is."
    http://www.apple.com/ios/whats-new/

  • How can I compile all functions, procedures and packages with a script?

    I need to compile all functions, procedures and packages of 5 schemas (users) with a script.
    How can I do it?
    Thanks!

    you can create a script to select all invalid objects in those schemas Since Oracle 8 introduced NDS this approach has struck me as a trifle old fashioned. It's much simpler to loop round the query in PL/SQL and use EXECUTE IMMEDIATE to fire off the DDL statements. No scripts, no muss, no fuss.
    Having said that, the problem with this approach and also with using DBMS_UTILITY.COMPILE_SCHEMA is that they do not compile all the invalid objects in dependency order. This may result in programs being invalidated by the subsequent compilation of dependencies. This is due to the introduction of Java into the database.
    The UTLRP script is much better, because it (usually) avoids cyclic references. But you still may need to run it more than once.
    In general it is better to avoid sledgehammer recompilations (like DBMS_UTILITY.COMPILE_SCHEMA, which starts by invalidating all the objects). If we have twenty invalid objects, nineteen of which are dependencies of the twentieth, we actually only need to recompile the master object, as recompiling it will trigger the recompilation of all the others.
    Cheers, APC

  • Read item from Java class and call to stored function/procedure of database

    Hi,
    I am looking solution that I was trying to find becasue of I am not expert and novice of ADF so I am getting problem to do. I am trying migrating from oracle forms to JDeveloper[ADF].
    I want to call database stored function from JSF pages by java bean class of a button press event (manually created) and after button event I have called java class which I created manually. But I can not read that values what I given into jsp page.
    question1: How can I read jsp pages items value to java class ?
    question2: How can I call to database stored function/procedure with that parameter?
    question3: How can I use return value of that stored function/procedure ?
    Please reply me .
    Thanks,
    zakir
    ===
    Edited by: Zakir Hossain on Mar 29, 2009 10:22 AM

    ---

  • My Macbook pro,s Airdrop isn't functional  plz help me to use it

    Hi everybody.
    My Macbook pro,s  Airdrop  isn't  functional  plz help me to use it.

    Mac Basics: AirDrop helps you share items with others nearby

  • Private function / procedure to be used with in a package

    Hi All
    I wanted to find out how would the definition be for a function which is defined so as to be used/called by the other functions / procedures with in a particular pakage and should not be visible/accessible for any other routine out side the package in which it is defined..
    could you please advice me on this? Thanks!
    Sarat

    It is possible: you can nest one function/procedure in another:
    SQL>CREATE OR REPLACE FUNCTION sum_squares(
      2     p_a   IN   NUMBER,
      3     p_b   IN   NUMBER)
      4     RETURN NUMBER
      5  IS
      6     FUNCTION square(
      7        p_n   IN   NUMBER)
      8        RETURN NUMBER
      9     IS
    10     BEGIN
    11        RETURN p_n * p_n;
    12     END square;
    13  BEGIN
    14     RETURN square(p_a) + square(p_b);
    15  END sum_squares;
    16  /
    Function created.
    SQL>SELECT sum_squares(3, 4) FROM dual;
    SUM_SQUARES(3,4)
                  25Urs

  • Syntax for nested function/procedure?

    Hi,
    What's the syntax to create a sub function/procedure in another function/procedure? Is this available in 9i?
    Thanks.

    Nested functions and procedures have been available since at least 7.3. However, any nested functions or procedures need to be the last things in your declare section.
    This works:
    SQL> CREATE OR REPLACE PROCEDURE test_proc is
      2     l_v VARCHAR2(100);
      3     FUNCTION nested_function RETURN VARCHAR2 IS
      4     BEGIN
      5        RETURN('nested function call') ;
      6     END;
      7  BEGIN
      8     l_v := nested_function;
      9     DBMS_OUTPUT.Put_Line(l_v);
    10  END;
    11  /
    Procedure created.But this does not:
    SQL> CREATE OR REPLACE PROCEDURE test_proc is
      2
      3     FUNCTION nested_function RETURN VARCHAR2 IS
      4     BEGIN
      5        RETURN('nested function call') ;
      6     END;
      7     l_v VARCHAR2(100);
      8  BEGIN
      9     l_v := nested_function;
    10     DBMS_OUTPUT.Put_Line(l_v);
    11  END;
    12  /
    Warning: Procedure created with compilation errors.
    SQL> show err
    Errors for PROCEDURE TEST_PROC:
    LINE/COL ERROR
    7/4      PLS-00103: Encountered the symbol "L_V" when expecting one of the
             following:
    12/0     PLS-00103: Encountered the symbol "end-of-file" when expecting
             one of the following:
             begin function package pragma procedure formTTFN
    John

  • ORA-30626: function/procedure parameters of remote object types not support

    Hello,
    I am trying to create a dynamic LOV.
    I have a table and package in a remote database, I am connecting to the database using dblink. When I access package I am getting error
    ORA-30626: function/procedure parameters of remote object types are not supported
    However I can access table with [email protected], not the package!
    How can I solve this problem?

    Did you ever get an answer/workaround to this? I'm having similar problems in 10g.

  • How to launch a function/procedure without suspending the parent process?

    Hi everybody,
    I would like to know if I can define something as follows in PLSQL:
    procedure master
    begin
    call a procedure_child;
    End master;
    I would like that the procedure master does not suspend the execution and wait that the procedure_child finishes in order to resume the executions with the further code.
    Thanks a lot in advanced
    Tomeu

    In the future, please stick to posting in a single forum.
    Re: How to launch a function/procedure without suspending the parent process?

  • How to use functions/procedures like wwv_flow_sw_api

    Hello,
    I want to use functions/procedures like wwv_flow_sw_api.check_priv(:P4_SCHEMA) in a process, but I get the error "identifier wwv_flow_sw_api.check_priv(:P4_SCHEMA); must be declared".
    How can I access these functions?
    Thank you,
    Kirsten

    Hi Jari,
    my problem is, that I need to replicate the exact feature of Query Builder page in my
    application (see thread Re: How to create Query Builder page in application
    So I imported the page 1002 and tried to make it working.
    Do you know any solution?
    Than you,
    Kirsten

Maybe you are looking for

  • How to display different text for labels in Group Above Report Oracle Repor

    Hello, Is there a way to change the text that is displayed in Labels in a Group Above Report? For example, I have a Group Above report with my columns of data and above the columns I have my column labels, but I would like to be able to display vario

  • Where are my fonts?? where is the file??

    I recently got a new imac with leopard. I am donating my old G5 to a pal. I am in the process of removing all my files but will leave the programs etc. on the computer. Same with the fonts. I use suitcase fusion and have for years. According to the s

  • Approval for scheduling overview

    Hi PM experts, Here my issue is that, how to provide approval for preventive miantenance schedule. In brief, In the  plant person responsibile for maintenance is creating the preventiv emaintenance plan for one year and he is scheduling for on eyear

  • External inspection

    Hello all I have this situation: The company doesn't have its own laboratory, so they always subcontract the inspection services of the products they buy. I have a inspection plan for goods receipts for the bought materials , and I created and extern

  • Create an Encapsulation of Select * Statements?

    I'm looking to encapsulate a mysql db call that returns a large result set due to Select *. I prefer to return the results and let the calling routine parse (or display) the data. Unfortunately most of the methods I've tried -- multidimensional array