Stored Procedures VS Indexed Views - Performance?

Hey folks,
In the past, one of the factors I'd consider when choosing to use a Stored Procedure over a View was the fact that the Stored Procedure would get optimized by storing the query execution path (I'm a developer so I understand this at a higher level than a
DBA would).  But I've recently become aware of the fact that you can now Index your Views.  This has now raised new questions for me as to when I'd get better performance out of the Indexed View versus the Stored Procedure?
Take for example the following:
SELECT colA, colB, sum(colC), sum(colD), colE
FROM myTable
WHERE colFDate < '9/30/2011'
GROUP BY colA, colB, colE
The date will be different every time it's run, so if this were a view, I wouldn't include the WHERE in the view and instead have that as part of my select against the View.  If it were a stored procedure, the date would be a parameter.
If this were an Indexed View, should I expect to get better performance out of it then a stored procedure that's had an opportunity to cache the execution path?  Or would the proc be faster?  Or would
the difference be negligible?  I know we could say "just try both out" but there are too many factors that could falsely bias the results, so I'd like to hear more of the theory behind it and what the expected outcomes are instead.
Thanks!

Very cool.  Thanks Dan.  One question though.  You said "
If you are using SQL Server Enterprise Edition, you do not need to select from the view directly. "  I'm not sure what you mean here.  Where would I selecting from if not from the view?
 Thanks again!
What I mean is that if your query is semantically similar to the same query encapsulated in the view, the optimizer may be able to use the view index even though you specify the table in the query.  For example, each of the queries below will scan
the view index in Enterprise (or Developer) edition instead of the underlying table:
CREATE VIEW dbo.vw_myTable
WITH SCHEMABINDING
AS
SELECT colFDate, colA, colB, SUM(colC) AS colC, SUM(colD) AS colD, colE, COUNT_BIG(*) AS countbig
FROM dbo.myTable
GROUP BY colA, colB, colE, colFDate
GO
CREATE UNIQUE CLUSTERED INDEX cdx_vw_myTable ON
dbo.vw_myTable(colA, colB, colE, colFDate);
GO
SELECT colA, colB, SUM(colC), SUM(colD), colE
FROM dbo.myTable
WHERE colFDate < '20110903'
GROUP BY colA, colB, colE;
GO
SELECT colA, colB, SUM(colC), SUM(colD), colE
FROM dbo.vw_myTable
WHERE colFDate < '20110903'
GROUP BY colA, colB, colE;
GO
SELECT colA, colB, SUM(colC), SUM(colD), colE
FROM dbo.vw_myTable WITH (NOEXPAND)
WHERE colFDate < '20110903'
GROUP BY colA, colB, colE;
GO
Dan Guzman, SQL Server MVP, http://www.dbdelta.com

Similar Messages

  • How to Rap a Stored Procedure in Calculation View

    Please suggest/guide with step by step how to rap a stored procedure in calculation view, which latter I can use to call from odata service.
    I have one input parameter PRDID
    Table: Product
    PRDID
    PRDTYPE
    PRDCAT
    QTY
    PRICE
    MMT1
    OP
    BOOKS
    1
    12
    MMT2
    OP
    BAG
    2
    32
    MMT3
    OP
    PEN
    3
    12
    MMT4
    OP
    NOTEPAD
    6
    12
    MMT5
    OP
    MOUSE
    6
    36
    MMT6
    OP
    HANDBAG
    1
    22
    CREATE PROCEDURE <yourschema>."Product" (INOUT prd VARCHAR(10)) LANGUAGE SQLSCRIPT AS
    BEGIN
    select "PRDID", "PRDTYPE","PRDCAT","PRICE"
       from <yourschema>."Product"
       where "PRDID" = :prd;
    END;
    Thanks

    Hi Deere,
    Check this post, we already discussed the same.
    http://scn.sap.com/thread/3528968
    Step 1 : Create a calculation view in script mode.
    Step 2 : Create your output structure(as same as the procedure output structure)
    Step 3 : Call the procedure inside the script .
    Step 4: Map the fields to the output variable.
    Step 5: Map the input variables to the procedure input(if needed)
    Exposing :
    Step 5 :  In the xsodata file, you can consume as usual .
    Sreehari

  • Create a View, function or stored procedure for query?

    Hi All,
    I like to know how I can create a view or function for the query below. If its going to be a function or stored procedure will I be able to union it with another view?
    DECLARE
    @BegDate DATE,
    @EndDate DATE
    SELECT
    @BegDate = MIN(vl.VoidStartDate),
    @EndDate = MAX(vl.LetDate)
    FROM #VoidLoss vl
    ;WITH d(d) AS (
    SELECT TOP (DATEDIFF(dd, @BegDate, @EndDate))
    DATEADD(dd, ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) -1, @BegDate)
    FROM sys.all_objects o
    ), cal AS (
    SELECT
    d.d,
    MONTH(d.d) AS m,
    YEAR(d.d) AS y
    FROM d
    SELECT
    vl.History_IND,
    vl.PropCode,
    vl.VoidCategory,
    vl.ControlGroup,
    CASE WHEN vl.VoidStartDate < MIN(cal.d) THEN MIN(cal.d) ELSE vl.VoidStartDate END AS VoidStartDate,
    CASE WHEN vl.LetDate > MAX(cal.d) THEN MAX(cal.d) ELSE vl.LetDate END AS LetDate,
    vl.MarketRent,
    DATENAME(mm, CAST('1900-' + CAST(cal.m AS VARCHAR(2)) + '-1' AS DATE)) AS [Month],
    cal.y AS [Year],
    COUNT(*) AS DaysVoid,
    COUNT(*) * vl.MarketRent AS VoidLoss
    FROM
    #VoidLoss vl
    JOIN cal
    ON cal.d BETWEEN DATEADD(dd, 1, vl.VoidStartDate) AND vl.LetDate
    GROUP BY
    vl.History_IND,
    vl.PropCode,
    vl.VoidCategory,
    vl.ControlGroup,
    vl.VoidStartDate,
    vl.LetDate,
    vl.MarketRent,
    cal.m,
    cal.y
    ORDER BY
    vl.History_IND,
    vl.PropCode,
    vl.VoidStartDate
    Thanks

    A view or an inline-function is a single query, so this part does not fit in:
    DECLARE
    @BegDate DATE,
    @EndDate DATE
    SELECT
    @BegDate = MIN(vl.VoidStartDate),
    @EndDate = MAX(vl.LetDate)
    FROM #VoidLoss vl
    And you cannot have it multi-statement function either, since you cannot refer to temp tables in such a function. In any case, using a multi-statement function in a view definition or nest it in another function definition is likely to be a performance disaster.
    The sole alternative that remains as long as you have the temp table is a stored procedure. You cannot use a stored procedure in a view or a function.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Need Help With a Stored Procedure

    Help With a Stored Procedure
    Hi everyone.
    I am quite new relative to creating stored procedures, so I anticipate that whatever help I could get here would be very much helpful.
    Anyway, here is my case:
    I have a table where I need to update some fields with values coming from other tables. The other tables, let us just name as tblRef1, tblRef2 and tblRef3. For clarity, let us name tblToUpdate as my table to update. tblToUpdate has the following fields.
    PlanID
    EmployeeIndicator
    UpdatedBy
    CreatedBy
    tblRef1, tblRef2 and tblRef3 has the following fields:
    UserName
    EmpIndicator
    UserID
    In my stored procedure, I need to perform the following:
    1. Check each row in the tblToUpdate table. Get the CreatedBy value and compare the same to the UserName and UserID field of tblRef1. If no value exists in tblRef1, I then proceed to check if the value exists in the same fields in tblRef2 and tblRef3.
    2. If the value is found, then I would update the EmployeeIndicator field in tblToUpdate with the value found on either tblRef1, tblRef2 or tblRef3.
    I am having some trouble writing the stored procedure to accomplish this. So far, I have written is the following:
    CREATE OR REPLACE PROCEDURE Proc_Upd IS v_rec NUMBER;
    v_plan_no tblToUpdate.PLANID%TYPE;
    v_ref_ind tblToUpdate.EMPLOYEEINDICATOR%TYPE;
    v_update_user tblToUpdate.UPDATEDBY%TYPE;
    v_created_by tblToUpdate.CREATEDBY%TYPE;
    v_correct_ref_ind tblToUpdate.EMPLOYEEIDICATOR%TYPE;
    CURSOR cur_plan IS SELECT PlanID, EmployeeIndicator, UPPER(UpdatedBy), UPPER(CreatedBy) FROM tblToUpdate;
    BEGIN
    Open cur_plan;
         LOOP
         FETCH cur_plan INTO v_plan_no, v_ref_ind, v_update_user, v_created_by;
              EXIT WHEN cur_plan%NOTFOUND;
              BEGIN
              -- Check if v_created_by has value.
                   IF v_created_by IS NOT NULL THEN
                   -- Get the EmpIndicator from the tblRef1, tblRef2 or tblRef3 based on CreatedBy
                   SELECT UPPER(EmpIndicator)
                        INTO v_correct_ref_ind
                        FROM tblRef1
                        WHERE UPPER(USERNAME) = v_created_by
                        OR UPPER(USERID) = v_created_by;
                        IF v_correct_ref_ind IS NOT NULL THEN
                        -- Update the Reference Indicator Field in the table TRP_BUSPLAN_HDR_T.
                             UPDATE TRP_BUSPLAN_HDR_T SET ref_ind = v_correct_ref_ind WHERE plan_no = v_plan_no;
                        ELSIF
                        -- Check the Other tables here????
                        END IF;
                   ELSIF v_created_by IS NULL THEN
                   -- Get the EmpIndicator based on the UpdatedBy
                        SELECT UPPER(EmpIndicator)
                        INTO v_correct_ref_ind
                        FROM tblRef1
                        WHERE UPPER(USERNAME) = v_update_user
                        OR UPPER(USERID) = v_created_by;
                        IF v_correct_ref_ind IS NOT NULL THEN
                        -- Update the Reference Indicator Field in the table TRP_BUSPLAN_HDR_T.
                             UPDATE TRP_BUSPLAN_HDR_T SET ref_ind = v_correct_ref_ind WHERE plan_no = v_plan_no;
                        ELSIF
                        -- Check the Other tables here????
                        END IF;
                   END IF;
              END;
         END LOOP;
         CLOSE cur_plan;
         COMMIT;
    END
    Please take note that the values in the column tblToUpdate.UpdatedBy or tblToUpdate.CreatedBy could match either the UserName or the UserID of the table tblRef1, tblRef2, or tblRef3.
    Kindly provide more insight. When I try to execute the procedure above, I get a DATA NOT FOUND ERROR.
    Thanks.

    Ah, ok; I got the updates the wrong way round then.
    BluShadow's single update sounds like what you need then.
    I also suggest you read this AskTom link to help you see why you should choose to write DML statements before choosing to write cursor + loops.
    In general, when you're being asked to update / insert / delete rows into a table or several tables, your first reaction should be: "Can I do this in SQL?" If you can, then putting it into a stored procedure is usually just a case of putting the sql statement inside the procedure header/footers - can't really get much more simple than that! *{;-)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • EJB from stored procedure lookup problem

    We are running a test case with in an EJB deployed to Oracle 8.1.6, accessing it from a Java stored procedure. It works okay if the stored procedure is called a limited number of times from a single client (client is non-Java). However, for performance testing, we are trying to run it several hundred times in sequence to better simulate the eventual production environment. Consistently on the 216th call, it fails with a NamingException from the InitialContext lookup. We can restart the client again and it will fail on the same call.
    Sounds like something memory related to me. Does anyone have any ideas? I'm using standard EJB client code in my stored procedure, instantiating an InitialContext, performing a lookup on the EJB, performing a home interface create, then accessing an EJB method.
    Thinking it might be that my test was too fast for whatever garbage collection is being done on the server, I tried a 2 second delay between invocations--same problem occurs, however. Should I be making a call to remove my EJBs when my stored procedure ends? If so, how would I do that?
    I did try making the handle to my EJB a static variable within the stored procedure and only "creating" the EJB once. That works okay with a single client, but if I run 2 clients simultaneously, 1 will work for awhile and then eventually die trying to call the EJB method--while the other client continues to run successfully.
    I'm stumped. Any insight or guidance will be greatly appreciated. Thanks.

    My DBA bumped up the large_pool_size and java_pool_size settings and the problem went away. I couldn't convince him to bump the settings one at a time, so am not sure which one was at the root of the problem.
    As I looked at the trace logs on the server, I also noticed that we were getting intermittent "peer disconnected socket" messages during the testing. That appears to have gone away with the pool size increases, also--in case that helps out anyone else.

  • MaxDB 7.6 carshes on calling stored procedure with driver 7.6

    Hi All,
    Recently I upgraded MaxDB from v7.5 to v7.6 after several hiccups I am almost done but one strange problem remains. I have a stored procedure which is used for generating Bill Of Material (recursive cursor). The said stored procedure uses some views (if that matters at all). If I call that stored procedure using JDBC driver v7.5 then all works well and if JDBC driver v7.6 is used to call the stored procedure it simply crashes the database. Does not it sound strange
    Does anyone have any clues?
    Thanks,
    Vinod

    Hi Marco,
    Here is the stored procedure, which causes database crash-
    START -
    [code]CREATE DBPROC shortlist_all_month (IN schedule VARCHAR(14)) RETURNS CURSOR AS
        $CURSOR = 'bom';
        BEGIN
        CREATE TABLE temp.bom_view
          (bom_version, main_item_code, sub_item_code, sub_item_qty, bom_item_remarks) AS
          SELECT bom_version, main_item_code, sub_item_code, sub_item_qty, bom_item_remarks
          FROM suman.mfg_bom_m
          WHERE bom_version = (SELECT MAX(bom_version) FROM suman.mfg_bom_m M
                        WHERE M.main_item_code = mfg_bom_m.main_item_code);
        DECLARE :$CURSOR CURSOR FOR
        WITH RECURSIVE PX (main, sub, qty, super_main) AS
           (SELECT main_item_code, sub_item_code, sub_item_qty, main_item_code
             FROM temp.bom_view WHERE main_item_code IN (
                SELECT schedule_plan_item FROM suman.ppc_schedule_m WHERE schedule_code = :schedule)
            UNION ALL
            SELECT main_item_code, sub_item_code, sub_item_qty, super_main
             FROM temp.bom_view B, suman.PX
             WHERE sub = B.main_item_code)
        SELECT sub AS sub_item_code, item_item_desc, item_mfg_flag, stock_item_qty,
         SUM(qty * schedule_plan_qty) AS req_qty, (stock_item_qty - SUM(qty * schedule_plan_qty)) AS short_qty
         FROM suman.PX B, suman.ppc_schedule_m S, suman.mfg_item_p I, suman.mfg_item_stock V
         WHERE B.super_main = S.schedule_plan_item
         AND schedule_code = :schedule
         AND B.sub = I.item_item_code
         AND B.sub = V.stock_item_code
         AND V.stock_dept_code = 'DP0008'
         GROUP BY sub, item_item_desc, item_mfg_flag, stock_item_qty
         HAVING SUM(qty * schedule_plan_qty) > 0 ORDER BY 3, 1;
        DROP TABLE TEMP.BOM_VIEW;
    END;[/code]----
    END -
    This used to work fine for last >4 years. See if you can find something fishy. I will try to give a runnable test case to reproduce the crash.
    Thanks,
    Vinod

  • Response from one stored proc. to another stored procedure call in JDBC

    Hi,
    I have to call 2 stored procedures, where the response from first stored procedure ( an id) is mapped as a parameter to the second stored procedure call.
    My question is that can this be achieved without using BPM?
    Can we somehow map the response from the stored procedure 1 to stored procedure 2 parameter w/o using BPM?
    I have to insert multiple rows using the stored procedure.
    Should I use STATEMENT unbounded times ( which means stored procedure is called multiple times) or should I use the parameter as unbounded ( like an array, maybe define the parameter as an array in the stored procedure)?
    From the performance standpoint, which approach is better?
    Please suggest.

    Hi Ardent !
    I think you could use 2 mapping programs (message mapping objects) in your interface mapping. The first one, executes and returns the ID to a message type defined by you for internal use only between both stored procedure executions. The second ones uses that message type as source message and the XML required by the JDBC for the second stored procedure execution as target message type. This can be done without BPM.
    Regards,
    Matias.

  • Getting exception whil calling an oracle stored procedure from java program

    Dear All,
    I encounter this error in my application when I call only the stored procedure but the view is executing fine from the application and my environment is as follow:
    Java 1.4
    oracle 10g
    oracle jdbc driver:9.2.0.8.0
    websphere portal 6.0.0.1
    this error is occur from time to time randomly, when it happens, the only workaround is to restart the server..Does anyone have any idea about this error?
    Unable to execute stored Procedure in Method
    java.lang.NullPointerException
    at oracle.jdbc.driver.T4C8Oall.getNumRows(T4C8Oall.java(Compiled Code))
    at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:1140)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java(Compiled Code))
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java(Compiled Code))
    at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3606)
    at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:5267)
    at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.pmiExecute(WSJdbcPreparedStatement.java:632)
    at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.execute(WSJdbcPreparedStatement.java:427)
    And sometime I am getting this exception
    Unable to execute stored Procedure in Method
    java.lang.ArrayIndexOutOfBoundsException: 27787320
    at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java(Compiled Code))
    at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:1134)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java(Compiled Code))
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java(Compiled Code))
    at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3606)
    at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:5267)
    at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.pmiExecute(WSJdbcPreparedStatement.java:632)
    at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.execute(WSJdbcPreparedStatement.java:427)
    Thanks
    Jay

    spacetorrent escribi&oacute;:
    for (int x=0; x <result.size(); x++){
    System.out.println(result.get(x));
    I can't do this, because result object is a Map, and I need write the Key of the Value to obtain.
    So I can do:
    result.get("res");And I odtain a *$Proxy3* Object

  • Passing Tables back from Java Stored Procedures

    Thomas Kyte has written (in reference to
    trying to pass an array back from a stored
    function call):
    You can do one of two things (and both require the use of
    objects). You cannot use PLSQL table types as JDBC cannot bind to
    this type -- we must use OBJECT Types.
    [snip]
    Another way is to use a result set and "select * from
    plsql_function". It could look like this:
    ops$tkyte@8i> create or replace type myTableType as table of
    varchar2 (64);
    2 /
    Type created.
    ops$tkyte@8i>
    ops$tkyte@8i>
    ops$tkyte@8i> create or replace
    2 function demo_proc2( p_rows_to_make_up in number )
    3 return myTableType
    4 as
    5 l_data myTableType := myTableType();
    6 begin
    7 for i in 1 .. p_rows_to_make_up
    8 loop
    9 l_data.extend;
    10 l_data(i) := 'Made up row ' &#0124; &#0124; i;
    11 end loop;
    12 return l_data;
    13 end;
    14 /
    Function created.
    ops$tkyte@8i>
    ops$tkyte@8i> select *
    2 from the ( select cast( demo_proc2(5) as mytableType )
    3 from dual );
    COLUMN_VALUE
    Made up row 1
    Made up row 2
    Made up row 3
    Made up row 4 [Image]
    Made up row 5
    So, your JDBC program would just run the query to get the data.
    If the function "demo_proc2" cannot be called from SQL for
    whatever reason (eg: it calls an impure function in another piece
    of code or it itself tries to modify the database via an insert
    or whatever), you'll just make a package like:
    ops$tkyte@8i> create or replace package my_pkg
    2 as
    3
    4 procedure Make_up_the_data( p_rows_to_make_up in
    number ); 5 function Get_The_Data return myTableType;
    6 end;
    7 /
    Package created.
    ops$tkyte@8i>
    ops$tkyte@8i> create or replace package body my_pkg
    2 as
    3
    4 g_data myTableType;
    5
    6 procedure Make_up_the_data( p_rows_to_make_up in number )
    7 as
    8 begin
    9 g_data := myTableType();
    10 for i in 1 .. p_rows_to_make_up
    11 loop
    12 g_data.extend;
    13 g_data(i) := 'Made up row ' &#0124; &#0124; i;
    14 end loop;
    15 end;
    16
    17
    18 function get_the_data return myTableType
    19 is
    20 begin
    21 return g_data;
    22 end;
    23
    24 end;
    25 /
    Package body created.
    ops$tkyte@8i>
    ops$tkyte@8i> exec my_pkg.make_up_the_data( 3 );
    PL/SQL procedure successfully completed.
    ops$tkyte@8i>
    ops$tkyte@8i> select *
    2 from the ( select cast( my_pkg.get_the_data as mytableType
    ) 3 from dual );
    COLUMN_VALUE
    Made up row 1
    Made up row 2
    Made up row 3
    And you'll call the procedure followed by a query to get the
    data...
    I have tried this, and it works perfectly.
    My question, is what does the wrapper look
    like if the stored function is written
    in java instead of PL/SQL? My experiments
    with putting the function in java have been
    dismal failures. (I supposed I should also
    ask how the java stored procedure might
    look also, as I suppose that could be where
    I have been having a problem)
    null

    Thanks for the response Avi, but I think I need to clarify my question. The articles referenced in your link tended to describe using PL/SQL ref cursors in Java stored procedures and also the desire to pass ref cursors from Java to PL/SQL programs. Unfortunately, what I am looking to do is the opposite.
    We currently have several Java stored procedures that are accessed via select statements that have become a performance bottleneck in our system. Originally the business requirements were such that only a small number of rows were ever selected and passed into the Java stored procedures. Well, business requirements have changed and now thousands and potentially tens of thousands of rows can be passed in. We benchmarked Java stored procedures vs. PL/SQL stored procedures being accessed via a select statement and PL/SQL had far better performance and scaleable. So, our thought is by decouple the persistence logic into PL/SQL and keeping the business logic in Java stored procedures we can increase performance without having to do a major rewrite of the existing code. This leads to the current problem.
    What we currently do is select into a Java stored procedure which has many database access calls. What we would like to do is select against a PL/SQL stored procedure to aggregate the data and then pass that data via a ref cursor (or whatever structure is acceptable) to a Java stored procedure. This would save us a significant amount of work since the current Java stored procedures would simple need to be changed to not make database calls since the data would be handed to them.
    Is there a way to send a ref cursor from PL/SQL as an input parameter to a Java stored procedure? My call would potentially look like this:
    SELECT java_stored_proc(pl/sql_stored_proc(col_id))
    FROM table_of_5000_rows;
    Sorry for the lengthy post.

  • Using stored procedures

    hi all
    How can i use stored procedures for tuning the database?
    thanks

    If you mean "will using stored procedures help improve application performance?" the answer is they may, depending on your application, number of users, etc, etc.
    Stored procedures are just application code stored in the database. This means the network traffic of information being sent back and forth between the server and clients is reduced and the application has more resources (usually) as it is running on the server and not the client. Also stored procedures can be used to cache information for future use by the same user.
    These 2 tutorials on pl/sql may help
    [http://www.asktheoracle.net/plsql-tutorial.html | oracle-plsql-tutorial-part1.htm]
    and
    [http://www.smart-soft.co.uk/Oracle/oracle-plsql-tutorial-part1.htm | plsql-tutorial-part1.htm]
    They are specifically on pl/sql but the general principles pf when and why to use them would be teh same for Java stored procedures or .net stored procedures.
    Edited by: ow007829 on 15/06/2010 14:40

  • Using stored procedures for insert, update and delete

    Hello all;
    We have a question from our customer (who is the DBA), who has not in the past used TopLink, about whether it makes sense to tie TopLink into existing stored procedures to save and retrieve informations.
    Is it possible?
    Is there any circumstance under which it is a good idea?
    Thanks

    In TopLink any operation for which TopLink generates SQL, can be replaced by custom SQL, or a stored procedure call.
    Custom SQL or stored procedures can be used for each of the descriptor's CRUD operations, but also for mapping queries and named queries. The Mapping Workbench only supports defining custom SQL for the descriptor CRUD operations and named queries, so many of the stored procedures call from the descriptor and mappings will need to be done through amendment methods.
    Whether it makes sense or not depends on the application and the company and their requirements. It will add significant overhead to the development process to have to define and maintain all of the stored procedures, and the stored procedure calls in the descriptors. You may wish develop your application using TopLink generated SQL, and once you have the model and queries stabilized then switch to using stored procedures.
    Whether it is a good idea depends on the application and the company and their requirements. Stored procedures may give the DBA more freedom to change the data-model once in production, and may allow for adding database-level security checks. In general using stored procedures will not improve performance if the procedures contain the same SQL that would have be executed anyway, but they may allow for the DBA to tune the SQL better.

  • Help: FRM-40505 for a FORM based on stored procedures

    Hi,
    I am working on a FORM based on stored procedures. When it performs a query, it actually returns record, but still comes with the message FRM-40505: ORACLE error: unable to perform query. Any recommendations on the possible coding area to check?
    Thank you in advance.
    Jimmy

    Jimmy,
    To base a block on a stored procedure is not a simple task because it depends on the .....
    .... stored procedure !
    If you do not provide much information (like the famous stored procedure), we could not do anything for you.
    As much information you provide, as much chance we have to understand the problem.
    Francois

  • Help with use of Java Stored Procedures to invoke Java Code within Applicat

    Good afternoon everyone
    Our development team is looking for some assistance/validation of a design strategy we are deploying for a client. Let me first layout the environment and then the design issue at hand:
    Business User Workstation component: Oracle SQL*Developer 1.5.x
    Reporting Tool: Actuate e.Spreadsheet A10
    Application Web UI: J2EE application developed with Eclipse
    Application Scripting: Application has a scripting component whereby business users can write Oracle PL/SQL to perform many of the functions that are available in the Web UI, but can be batched up or repeated several times.
    Application Server WebLogic 9.2.3 (client constraint)
    Database Serve: Oracle 11g, Release 11.1.0.7
    Lots of other stuff included but irrelevant for this conversation.
    Here's the scenario in question:
    1.     Through the scripting solution, the application user must use PL/SQL to invoke functionality within the Web UI. All PL/SQL that the application user creates does not contain any SQL. Instead our security model mandates that “pre-defined” routines will perform all of the SQL operations against the database; the application user simply invokes the stored procedures of functions to perform activities in the database.
    2.     There is a component of the scripting application that facilitates the creation of reports. In our application, we are using Actuate’s e.Spreadsheet Engine to create the report and format the report based on a template. The template is provided as input, as well as other data items, into Actuate for processing. The net result is the report is created by the Actuate e.Spreadsheet engine in pdf format and then sent back to the user for distribution to other users in the company.
    3.     The Actuate e.Spreadsheet engine consists of one or more JAR files within the Application Server framework. The Web UI utilizes these JAR files as well to perform report generation and data manipulation activities. In the case of the reporting functionality, the pdf report that is generated by Actuate is returned into either the Web UI or into the scripting component for persistence in the database. The mechanism exists to create multi-step jobs that can create multiple reports in one run.
    4.     So to facilitate the above, we are creating one or more Java Stored Procedures that will mediate the communication between the PL/SQL the user’s create and the Java components that are required for business processing. PL/SQL will invoke one or more Java Stored Procedures. Then the Java Stored Procedures invoke Actuate e.Spreadsheet, generate the report, saves the report in the database and returns control back to the invoking procedure.
    So the question is: Is this a viable and correct use of Oracle Java Stored Procedures. What are the advantages/disadvantages of doing so? Any security issues or potholes that you can think of? Tuning issues for the JVMs? Any white papers that you can think of?
    For any Oracle employees that respond, material such as Oracle Whitepapers, etc. would be great.
    I can be contacted at (313) 227-4350 or at [email protected]
    Thanks in advance.

    So are you planning on loading the entire e.Spreadsheet engine into the database server's JVM?
    If so, I would expect that to work, but I expect that you'd have some performance issues. I'd expect that the process of building these PDFs is going to be relatively expensive. Tuning the database server's JVM tends to be rather more challenging than tuning JVM's in an app server.
    If not, I'm not sure how the Java stored procedure would invoke the e.Spreadsheet engine on the application server. It is possible to use Oracle AQ to send a JMS message, but I don't think you can use the standard J2EE JMS APIs-- I think you'd have to use Oracle's AQ interface.
    Justin

  • Help with a stored procedure....

    i'll be honest, i have never written one, and i have been doing research all day to do one and i have not had much luck. Seems like they mostly all take variables or require data that i just do not want it to require.
    I have a query (using TOAD fyi) that is run every morning.... i am trying to make it a stored procedure because i am in the process of automating this for people who want it as opposed to sending it to everyone.
    This is the query i am trying to turn into a stored procedure.... (some details removed for sake of security)
    SELECT CASE
    WHEN stuff
    ELSE 'Unknown'
    END aging,
    a.transaction_type, a.status_code, b.description, a.exception_code,
    c.description,
    decode(a.exception_code,'XXXX','YYYY',
    'XXXX','YYYY',
    'XXXX','YYYY','EXCEPTION') "CATEGORY"
    ,COUNT (*)
    FROM (SELECT TO_DATE
    (DBMS_LOB.SUBSTR (clob_details,10,DBMS_LOB.INSTR (clob_details,
    '<TransactionDate>') + 17 ),'yyyy-mm-dd') receipt_date,
    transaction_type, status_code, exception_code
    FROM thisdb.TRANSACTION
    WHERE status_code = 'MX'
    AND clob_details IS NOT NULL) a,
    thisdb.status b,
    thisdb.EXCEPTIONS c
    WHERE a.exception_code = c.exception_code
    AND a.status_code = b.status_code
    and a.status_code = 'MX'
    GROUP BY a.status_code,
    b.description,
    a.transaction_type,
    a.exception_code,
    c.description,
    CASE
    WHEN Stuff
    ELSE 'Unknown'
    END;
    now, please do not worry about the contents of the query, it works nicely and does its job :)
    but how can i take this and encapsulate it so that i can turn it into a stored procedure?
    Thank you all very much for any and all advice, i do greatly appreciate it!

    Hi,
    user12733751 wrote:
    it is just a query, the results will be going to excel later, all that is created already (the connection and runnign basic queries via excel VBA), so perhaps you are right, i do not need a stored procedure but a view?
    I have not heard of a view (stored query), how does that work?You create a view once for all like this:
    CREATE OR REPLACE VIEW  fubar
    AS
    SELECT    CASE
               WHEN  stuff
              ...     -- the rest of your original query goes here
              END;And you use it just like a table:
    SELECT  *
    FROM    fubar;A user who runs this last, extremely short, query gets the exact same results as someone who runs your original query.
    Here's a completely different approach.
    Depending on your front-end, you could also save your original query in a script, called fubar.sql, and people could run it by simply saying
    @fubar

  • Arabic characters from Oracle Stored Procedure

    Hi,
    I am having a problem displaying arabic fields from Oracle Stored Procedure. When viewing the arabic field on the web page, i get the following:
    ÙƒØكد Øاكد غبد افلبٍ افاربش
    I have checked with our Oracle DBAs and we seem to be using the AR8ISO8859P6 (ISO-8859-6). I tried to set the return string encoding to UTF-16 and ISO-8859-6 but still no use.
    What should be done to display it?

    Bashar Abdullah wrote:
    Hi,
    I am having a problem displaying arabic fields from Oracle Stored Procedure. When viewing the arabic field on the web page, i get the following:
    I have checked with our Oracle DBAs and we seem to be using the AR8ISO8859P6 (ISO-8859-6). I tried to set the return string encoding to UTF-16 and ISO-8859-6 but still no use.
    What should be done to display it?The first place I'd ask is the Oracle JDBC forum:
    http://forums.oracle.com/forums/forum.jspa?forumID=99
    Joe

Maybe you are looking for