Stored Procedure question

I have a bunch of .sql scripts which I have created to do certain things. I have a modified excerpt of a PROC that already works but I have created a bunch of scripts that I want to run in the bottom of it. Can I run them one after another from the stored procedure something like this:
CREATE OR REPLACE PROCEDURE MYPROC(GET_CUR_PERIOD IN DATE, GET_PRIOR_PERIOD IN DATE)
IS
-- Define the DATE variables to be retrieved from initial script.
CUR_PERIOD DATE;
PRIOR_PERIOD DATE;
BEGIN
-- Assign the dates to this procedure that were passed in above.
CUR_PERIOD := GET_CUR_PERIOD; --07/27/2007
PRIOR_PERIOD := GET_PRIOR_PERIOD; --06/27/2007
-- Execute another stored procedure, passing in dates.
MYPROC2(CUR_PERIOD, PRIOR_PERIOD);
-- Some regular SQL statements go here
-- This is what I want to add - Will it work, and is the syntax correct?
@\\MyNetwork\MyFiles\MyFolder\script1.sql
@\\MyNetwork\MyFiles\MyFolder\script2.sql
@\\MyNetwork\MyFiles\MyFolder\script3.sql
End MyProc;
/

As long as myproc is defined in the package spec so it can be called externally, and myproc2 is defined in the package body, you should not have to make any changes to either of them in order to put them in a package. If you include myproc3 and myproc4 in the package as well, then either myproc or myproc2 could call them. Myproc's "thing" would include calling all of the procedures that it needs to do to do its job.
Just be aware that a procedure needs to be declared before it can be called. So, if myproc calls myproc2 and myproc2 is not defined in the specification, then myproc2 needs to be defined first in the package body. Although not strictly required as a format, my usual structure for package spec and body is along the lines of:
CREATE PACKAGE name AS
   signatures of public procedures and functions
   public variables and type
END;
CREATE PACKAGE BODY name AS
   package private variables and types
   package private procedures and functions (actual code)
   implementation of public procedures and functions
END;The number of public versus private procedures will depend on the nature of the tasks that the package is desinged to do. I have one package in our payroll system that produces either a text file to do our direct deposit for paying employees (EFT file), or a interface file to send to a GL system. There are 4 flavours of EFT file and 5 or 6 for the GL interface files.
Since both types of file use a number of common routines, I included them in a single package. There are two public procedures (run_eft(parameters), and run_gl(parameters)). There are about 50 private procedures or functions in the package each designed to do a single thing like
FUNCTION get_next_eft_number(company_id IN NUMBER) RETURN NUMBERwhich determines for a particular company what the next sequential file number id for that company's EFT file. The run_eft procedure looks kind of like:
PROCEDURE run_eft(parameters) IS
   variable declarations
BEGIN
  /* Check if pay is for this company and is completed */
  IF NOT validate_pay_run(p_run, p_co_id) THEN
     RAISE error;
  END IF;
  /* Get common info that all banks need */
  get_pay_date(p_run, l_paydate, l_chqdate);
  /* Get bank used by this company and bank specific info */
  get_bank_info(p_co_id, l_trans_cd, l_acct_no, l_bank_name);
  IF l_bank_name = 'BMO' THEN
     run_bmo_eft(parameters)
  ELSIF l_bank_name = 'RB' THEN
     run_rb_eft(parameters)
  ELSE
     RAISE BAD_BANK;
  END IF;
END;Both run_bmo_eft and run_rb_eft call other procedures to build corredtly formatted header, detail and trailer records as required by the bank. They also have a few procedures in common. Since the tables that tell me how much to pay a person are common across all of the companies, I use a single function to generate the cursor I walk to generate and format the output file.
"Doesn't this get unwieldly after a while, having to have all the code for all the procedures in one file? Or in practice does it actually help?" In practice, it actually helps a lot, as long as you do not get carried away. A package needs to contain related procedures, not every procedure you have ever created in the database.
To go back to my EFT/GL package as an example. I chose to create a single package initially because there were only two companies, both used the same bank for payroll, so the EFT files were identical. The GL systems differed, so I had two different procedures for those. However, there were a number of procedures such as the validate_pay_run proc I referred to that are common to both GL and EFT. We are now up to 5 or 6 companies using 4 different banks and all have different GL systems. In my opinion, this package is on the verge of becoming unwieldy. If we get another bank or two and one or two new GL systems to deal with, I will probably split the package. However, this is one of the benfits of using packages, I can do this easily with minimal disruption to the external users who run these jobs.
If I split, I would probably split it into 3 packages. One for the EFT specific processing, one for the GL interface processing, and one for the helper functions that are common to both. I would keep my current package spec as is as a wrapper so the users need to change nothing. My current and future spec looks like:
PACKAGE uhn_custom IS
   PROCEDURE run_eft(parmaeters);
   PROCEDURE run_gl(parameters);
END;However, the future body, instead of having the implementation details would be simply:
PACKAGE BODY uhn_custom IS
PROCEDURE run_eft(parmaeters) IS
BEGIN
   eft_package.run_eft(parameters);
END;
PROCEDURE run_gl(parameters) IS
BEGIN
   glint_package.run_gl(parameters);
END;
END;The only code changes I need make would be to preface all of the calls to the common helper functions in each package with the new helper_package name.
HTH
John

Similar Messages

  • File to JDBC Scenario using stored procedure Question

    Does anyone have an aswer (or have you seen a Blog that covers it) to the problem of having to do a table refresh before doing inserts in a file 2 jdbc scenario?
    Essentially the details are as follows:
    I have an input file that has all the data for a table (it's a complete table dump) of lets say userdata (username, name, hiredate).
    I need to pass that to an oracle database via stored procedure(s).  But before I start issuing my insert (via insert stored procedure) I have to somehow issue a delete statement to delete all the contents of the table I'm about to update.  I'm on XI 3.0 and aren't sure what the best solution to this may be.
    Again if there is a blog that covers this then if you could point me in that direction it would be great.  Otherwise if anyone has any good ideas it would be appreciated.

    Hi,
    For structure refer this blog..
    /people/sap.user72/blog/2005/06/01/file-to-jdbc-adapter-using-sap-xi-30
    Use two <Statement> tags as shown here and there you may have separate tablenames.
    http://help.sap.com/saphelp_nw04/helpdata/en/2e/96fd3f2d14e869e10000000a155106/frameset.htm
    Thanks,
    Jogula Ramesh

  • Another "How to call a stored procedure" question

    Hi,
    I want to call a stored procedure which returns 4 VARCHAR as a output
    parameter, and use 2 VARCHAR as a input parameter. How can I do
    that ?
    the signature of the SP is like this
    dec(
    in_a IN VARCHAR2,
    in_b IN VARCHAR2,
    out_c OUT VARCHAR2,
    out_d OUT VARCHAR2,
    out_e OUT VARCHAR2,
    out_f OUT VARCHAR2,
    Thank You

    There is an example in your wls installation, did you check that? it shows
    you how to access cursor as a resultset.
    <wls install dir>\samples\examples\jdbc\mssqlserver4\complexproc.java
    hth
    sree
    "Saman" <[email protected]> wrote in message
    news:[email protected]..
    >
    Hi,
    I am using weblogic JDriver for MSSQLServer 7.0. I want to call a
    stored procedure which returns a CURSOR as a output parameter. How can Ido
    that ?
    the signature of the SP is like this
    Myprocedure (@c CURSOR VARYING OUTPUT)
    Thank You,
    Saman

  • How to call a stored procedure question

    Hi,
    I am using weblogic JDriver for MSSQLServer 7.0. I want to call a
    stored procedure which returns a CURSOR as a output parameter. How can I do
    that ?
    the signature of the SP is like this
    Myprocedure (@c CURSOR VARYING OUTPUT)
    Thank You,
    Saman

    There is an example in your wls installation, did you check that? it shows
    you how to access cursor as a resultset.
    <wls install dir>\samples\examples\jdbc\mssqlserver4\complexproc.java
    hth
    sree
    "Saman" <[email protected]> wrote in message
    news:[email protected]..
    >
    Hi,
    I am using weblogic JDriver for MSSQLServer 7.0. I want to call a
    stored procedure which returns a CURSOR as a output parameter. How can Ido
    that ?
    the signature of the SP is like this
    Myprocedure (@c CURSOR VARYING OUTPUT)
    Thank You,
    Saman

  • New to Oracle - Stored Procedure Question

    All I want to do is create a stored procedure that returns rows of data from the database. All that I have read says that you use a function for this in Oracle, but all the samples I've seen only returns a single value.
    Can anyone provide a sample for returning rows of data to the client (Visual Basic in my case).
    Thanks.

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Rob Davis:
    All I want to do is create a stored procedure that returns rows of data from the database. All that I have read says that you use a function for this in Oracle, but all the samples I've seen only returns a single value.
    Can anyone provide a sample for returning rows of data to the client (Visual Basic in my case).
    Thanks.<HR></BLOCKQUOTE>
    I'm not sure why you had to use a procedure to return rows, but if your objective is to return rows based on joins of tables, why not use views?
    If you have to pass parameters, then that's another story. Sorry!!!
    Cheers
    null

  • Conc. prog as pl/sql stored procedure question

    When I registered a conc. program as pl/sql stored procedure, and, with in procedure I am using as following:
    exception
    when others
    retcode := 2;
    Where I am expecting the conc. request screen should show me as red one, that is completed with error. But, even though my program aborted for unknown reason, the conc. request screen for this conc. request-id shows as "completed-normal" insted of "completed_error".
    Any idea? what are the exact retcode should be used? please explain.
    Thanks
    R2b.
    null

    What about
    exception
    when others
    THEN
    retcode:=2;
    Jack

  • Table Trigger and Stored Procedure Question

    I'm rusty with triggers/procedures and have a quick question.
    If a rollback occurs within a procedure containing a raise_applciation_error called from a table insert trigger, will this prevent the insert on the table from occuring?
    I want the transaction to be occur on the table even though an exception is raised within the called procedure.

    If the trigger is an "after insert" and the procedure called by the trigger raises an error, will the row still be inserted?
    SQL> create table t (n number);
    Table created.
    SQL> create or replace
      2  procedure p as
      3  begin
      4     raise_application_error(-20001,'Something bad happened');
      5  end;
      6  /
    Procedure created.
    SQL> create or replace
      2  trigger t_trig
      3  after insert
      4  on t
      5  begin
      6     p;
      7  end;
      8  /
    Trigger created.
    SQL> insert into t values (42);
    insert into t values (42)
    ERROR at line 1:
    ORA-20001: Something bad happened
    ORA-06512: at "SELSE.P", line 3
    ORA-06512: at "SELSE.T_TRIG", line 2
    ORA-04088: error during execution of trigger 'SELSE.T_TRIG'
    SQL> select * from t;
    no rows selected

  • Newbie question on how to return java objects from java stored procedures

    Hi,
    As you may guess, i'm new to this.
    I have a stored procedure that does some calculations and creates a list of java objects as the result of the query.
    How would I return the list from the database to the client application?
    Would I have to create an Oracle type that maps to the java object?
    Please help.
    Jag

    Hi Jag,
    Your question is very vague (to me). Perhaps you could post what you have done so far? Have you tried looking through the Sample Code page of the Technet Web site, or tried searching the Ask tom Web site, or MetaLink?
    Good Luck,
    Avi.

  • Question about MySQL, JDBC, SQLJ, Stored procedure & callable statements

    Hi, there. I'm using j2sdk1.4.1_01 and MySQL ver 12.18 Distrib 4.0.12, and when I try to install a store procedure, it throws the following message:
    SQLException: Stored procedures not supported: {call sqlj.install_jar('blah...blah...MyProject-20031206.jar', 'routines_jar', 0)}
    Who's is not supporting store procedures here? Java or MySQL? What can I do?
    The book and sample code I'm using as a reference mention that "the sample code assumes that the DBMS already stores the built-in SQLJ procedure sqlj.install_jar, which loads a set of classes written in the Java programming language in an SQL system". Now my question is: the "SQLJ procedure sqlj.install_jar" is something extra that I need to install or it has nothing to do with the problem?
    Is it true that MySQL does not support stored procedures? Thank you in advance for any hint or suggestion.
    Regards,
    Hector.

    Who's is not supporting store procedures here? Java or
    MySQL?MySQL.
    What can I do?1. Don't use stored procedures.
    2. Use a database that supports stored procedures.
    3. Wait for the release of MySQL that does support stored procedures.

  • Design Question::Instantiating Object from Stored Procedure Output

    Hi All,
    I am confused with approaching this design issue. I called a Stored Procedure, and the output from the Stored Procedure is a REF CURSOR. The size of the REF CURSOR can be large.
    My Question is, is it a good idea to pass the values from the REF CURSOR to a class constructor, there by instantiating an object of that type. lets say
    //rset is of type ((OracleCallableStatement)callableStatement).getCursor(5);
    //rset is not ResultType
    while (rset.next()){
    new ClassXYZ(var1, var2, var3);
    /*var1, var2, var3 would be rset.getObject(1),rset.getObject(2),rset.getObject(3)
    Class XYZ does some business logic
    }Other things:
    1) Will the JVM hold up assuming good enough JVM mem size, while creating objects for the range 100 thousands?
    2) I do not know the cursor size. It can change randomly from business perspective. And, it would be in the range of 100 thousands
    I was thinking, If I can "police" the call to the Class XYZ in case of large data. May be I am totally off the best solution. Any light on the best way to approach will be great.
    Anyhow, this would be a standalone java application. Just in case if people are trying to suggest/recommend DAO etc.,
    Thank you,
    VJ

    You can use ConvertTo-Html:
    http://ss64.com/ps/convertto-html.html
    Here's an example:
    http://social.technet.microsoft.com/Forums/scriptcenter/en-US/5cb016d3-e2fb-43e7-9c01-10b6878056e4/formattable-lost-in-email
    Don't retire TechNet! -
    (Don't give up yet - 13,085+ strong and growing)

  • Testing stored procedures - stupid question

    Ok here is a stupid question.. I have a stored procedure that returns 3 refcursors. When I call the procedure from code (C#), everything works fine.. however, I want a way to review the output of the stored procedure in Oracle Sql Developer before I test it in code. I can run it, but I can't figure out a way to display the records in the refcursors, =D

    Well I am really looking for syntax help.. sql server developer here, used to things being easier.. here is my procedure signature from running it in sql developer:
    DECLARE
    CONSUMETYPE NUMBER;
    RESULTS SYS_REFCURSOR;
    RESULTS2 SYS_REFCURSOR;
    RESULTS3 SYS_REFCURSOR;
    BEGIN
    CONSUMETYPE := NULL;
    USP_SELECT_PROMOTIONS(
    CONSUMETYPE => CONSUMETYPE,
    RESULTS => RESULTS,
    RESULTS2 => RESULTS2,
    RESULTS3 => RESULTS3
    -- Modify the code to output the variable
    -- DBMS_OUTPUT.PUT_LINE('RESULTS = ' || RESULTS);
    -- Modify the code to output the variable
    -- DBMS_OUTPUT.PUT_LINE('RESULTS2 = ' || RESULTS2);
    -- Modify the code to output the variable
    -- DBMS_OUTPUT.PUT_LINE('RESULTS3 = ' || RESULTS3);
    END;
    Where it says "Modify the code to output the variables".. It gives me a compile error when uncommenting those lines, and I am assuming because it cannot output a cursor that way, so I am trying to find a way to just output the cursor to a grid or text pane?

  • Question: Are there any advantages for stored procedure for data block?

    There are two ways to create data block:
    1. query table or view or
    2. stored procedure.
    After 9i, AS has a PL/SQL compiler. Do we still see the advantage of using stored procedure, as claimed that it is faster due to the stored procedure always compiled?
    Thank you in advance.
    Jimmy

    Jimmy,
    The "fast" side is not the only one benefit of stored procedures.
    Of course, you can use the BULK COLLECT functionality which is not available into Forms.
    But stored procedure is a good way to perform the following actions:
    complex handeling of datas (insert, update or delete that generate severals actions on other tables).
    externalization/centralisation of business rules.(separate the design and functionnal work).
    more secutity, because you can prohibit manipulation of datas outside of the procedures.
    You can change the rules without modify the forms.
    etc.
    Francois

  • Question?? - passing 2D array as a parameter of a stored procedure

    Hi,
    I have been having a lot of trouble with executing a stored procedure. I'm hoping someone can help me with this:
    THe stored proc. has 10 parameters, 5 IN and 5 OUT. One of these parameters coming out is a 2D array, however I"m not sure how I would be able to call the correct OCCI type coming out.
    I've declared a 2D array char sample[10][10];
    and then:
    stmt - > registerOutParam ( 7, oracle::occi:OCCI*???, sizeof(sample);
    and then :
    char outarray[10][10];
    out_array = stmt -> getString??? get*??
    I tried just passing a string itself, but as the procedure is looking for a 2D array, the program aborts, but I'm really not sure how I can solve this...??
    I'm kind of new to this subject, and I would really appreciate any help anyone can provide, with being able to pass in a 2D char array and being able to receive the outcomning data.
    Thanks a lot for any help!

    Hi,
    thank you for the link, it helped a lot....
    my C++ app that calls my stored procedure does compile, however, when I execute it "Aborts". I debugged it and found that right before my
    stmt->executeUpdate()
    statement, it outputs "Aborts", I'm really not sure why this is aborting, are there any specific debug statements or anything I can use specific to occi so that I can trace why my program aborts right before the executeUpdate statement (also I have checked my procedure and it is compiled and valid, and all my parameter types are correct).
    Does anyone have any ideas??
    Any help on this matter is really appreciated... thank you

  • Stored Procedure basic timing questions

    If I have the following statements in one stored procedure, what happens if a user does an update, insert, or select to the MAIN_TABLE during the procedure (assume the procedure takes a few seconds)?
    MY_PROCEDURE:
    INSERT INTO BACKUP_TABLE (COL1, COL2, ETC.)
    (SELECT COL1, COL2, ETC. FROM MAIN_TABLE WHERE BACKED_UP = 'N');
    UPDATE MAIN_TABLE SET BACKED_UP = 'Y' WHERE BACKED_UP = 'N';If they do an update/insert, will the data in MY_PROCEDURE see that update/insert and send it to BACKUP_TABLE? Or will it depend on whether that record has been processed yet? Or will the update/insert not persist until the procedure is complete? (I suspect the latter, but it's hard to get the timing right to test this myself)
    Would there be any problems doing a select on MAIN_TABLE while this process is occurring?
    If there's a reference to how these timing issues are resolved that someone could point me to, that'd be great; I can't seem to find anything on my own.

    when all else fails Read The Fine Manual
    http://download.oracle.com/docs/cd/E11882_01/server.112/e16508/consist.htm#sthref1118

  • Help - Stored Procedure/datablock question

    I have a fair understanding, but I'm a bit confused right now. Here' the scenario:
    For performance reasons, I have many tables that I want to load using stored procedures. They are all "look up" tables and don't need to be updated.
    How do I call a stored procedure and populate my datablock?
    Could someone post sample code for the stored procedure and how I integrate that into a data block? THANKS!!!!!
    null

    Bert,
    Create your stored procedures in the database.
    Choose the data block you need populated.
    Select the Data Block Wizard and choose Stored Procedure. Enter the Procedure name as stored in the database, click refresh and you are on your way.
    You will be prompted for each type of operation(the first screen is Select, the next INS, UPD, LOCK). Use the procedures you have defined as appropriate to each screen and Forms does all the work for you. You can define arguments to the procedures if necessary on each of the screens.

Maybe you are looking for

  • Adobe Premiere Elements 11 Editor: how to get support when you purchase at Apple Store?

    [Moving to Premiere Elements... JTS] I purchased Adobe Premiere Elements 11 Editor software at Apple Store in May/11/2013. I could use the product no more than 2 times because it started to have problems to open, since then I could not use anymore. I

  • Final Cut Pro HD 4.5  Will not work with the new dual core dual processors

    Does anyone know of any solutions that will avoice having to purchase the FCP 5.

  • Need help with 'Find my iPhone'

    Yesterday, I lost my ipod touch (gen 4) on an amtrack train.  I believe that I had the location feature turned on, as well as 'find my iphone'.  Now I'm trying to figure out how to use / access 'find my iphone'.  I realize the ipod may have lost its

  • Mac 10.5.8 - any good 'Skype' alternatives out there?

    As many Mac users have found out recently, Skype have summarily removed access to users (like me - Mac 10.5.8) following their recent 'upgrade'. It may be several weeks or months before Skype's promised upgrade, specifically for Mac 10.5.8 becomes a

  • Configuring Mail appearance

    How do I configure Mail to look like it was on Snow Leopard? Apparently there are "improvements" under Mountain Lion that I don't like. I would like my mailboxes on the left and emails on the right. Is there any way to configure Mail's appearance? Th