Procedures vs Views

Hi,
I want to know in what situations we can use procedures and views?
Any performance difference between procedure and view?
which is best choice?
I want info. with examples.......
So Can any body clarify or send the link of any site please...............
Cheers...:-)
Suman Naidu Sakinala

>
having said that, I was trying to find out earlier if
I could return a set of data (multiple records) from
a stored proc. the answer I think was no, which would
be in line with what i think most of you are saying.
I may not be understanding you. But, the answer is yes, you can create a Stored Proc in Oracle to return a result set. But, you must create a Result Package first, and in your returning select statement, you 'open' it into your package. Maybe you did not realize this?
I too learned SQL Server before Oracle. Perhaps an Oracle guru would have some reason as to why a package is required for something so basic and common? Then again I always believed there way a good reason behind how 'Dual' got it's name. When I found out how 'Dual' got its name, I was shocked!
Other than that I believe the basics behind Views and Stored Procedures is the same in Oracle and SQL Server.
As a prior poster mentioned, all a view is, is an SQL statement. I once read someone's opinion to never put any business logic in a view. I don't agree with that. Since an SQL query could contain business logic, therefore so could a view. A good reason to use a view is, instead of copy and pasting SQL code all over the place (ie. SQL code related to queries or returing result records), stick it in a view.
If you need to use the result set in an SQL Query, I don't think, you can do this in a Stored Proc in any Database. Something like for a Stored Proc sp_A, you can't do:
select
T.*, sp_A(T.c1)
from
T
(If I'm wrong on that please somebody correct me.)
But a view can be incorporated into an SQL query

Similar Messages

  • How to handle Stored Procedure and Views

    Dear All
    While dealing with Oracle database related scenario. I came across Stored Procedures and Views. Which are complex in nature. Using SAP XI how we can handle them ?
    Is JDBC adaptor is capable of that.? Can you help me Data type structure for oracle.
    How max occur play important role in that. How to identify root and item level structure for oracle
    I am dealing with stored procedures while inserting data. and using views i need to get data from oracle database.
    What is the syntax of query we use to put while using JDBC adaptor?
    Please help and provide bit detail information over this so that i can execute scenario
    Thanks
    Gaurav

    1) jdbc:oracle:thin:@xxx.xxx.xxx.xxx:1521:sid
    2)Occurence==> o,1, >1 , Unbounded
    Occurrence=> ready to accept 0 / 1 / more than 1/ multiple record  (for source) and how it will be passed to target.
    http://help.sap.com/saphelp_erp2004/helpdata/en/b6/0b733cb7d61952e10000000a11405a/frameset.htm
    3)
    <StatementName5>
    <storedProcedureName action=” EXECUTE”>
        <table>realStoredProcedureeName</table>
    <param1 [isInput=”true”] [isOutput=true] type=SQLDatatype>val1</param1>
    </storedProcedureName >
      </StatementName5>
    refer
    http://help.sap.com/saphelp_nw04/helpdata/en/22/b4d13b633f7748b4d34f3191529946/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/2e/96fd3f2d14e869e10000000a155106/frameset.htm

  • Which is better to use Store Procedure or Views in Crystal Reports ?

    Hi,
    which one is more better to use Store Procedure or Views in Crystal Reports ?
    Thanks.

    It depeneds on the requirement. Well, but from performance point of view as u know that stored procedures are already compiled on DB side, they would be more efficient. Views are handled differently. Here CR has nothing to do with it.
    But if the stored procedure u r using is having 2 Select statements, CR will only display the results from the first select statement. In that case you need to use Views as one can use more than one views in the report and join them.
    Using a Generic view which is created by the DBA for a larger audience will result in performance issues meaning if a View "V" has 25 fields and View is based on 5 tables  and ur report is using only 5 fields which are coming only from 2 tables inside the view,in this case u will end up in joining 3 more tables unnecessarily.
    Hope this helps!

  • JOB execution fails due to Access failure to procedures and views using certificates (encryption)

    Job execution fails using SQLServerAgent account but runs successfully under another windows personal account.
    Both have same security access on server and DB.
    The Windows account is mapped to dbo on the database .
    The package uses procedures and views which are using encryption by certificates.
    Please advice on how to provide security so that job runs from the agent

    Hi Prady26,
    If the SQL Server Agent Service account and the proxy account generated based on a Windows user account have the same permissions on both the SQL Server database and the File System of the server, it may be related to the protection level of the package.
    If the package is set to encrypt with UserKey, the job will fail unless it runs under the security context of the Windows user that designs the package in BIDS/SSDT. You can check the
    ProtectionLevel of the package in the BIDS/SSDT to see if it is EncryptSensitiveWithUserKey or EncryptAllWithUserKey, if it is, re-deploy/reinstall the package and set the package protection
    level to “Relay on server storage for encryption”.
    If the issue persists, post the error message in the job history for further analysis.
    Regards,
    Mike Yin
    If you have any feedback on our support, please click
    here
    Mike Yin
    TechNet Community Support

  • Stored Procedure vs Views, Please clearify.

    Hi Gents,
    I am working on client side as a crystal report developer, the client has several applications linked to each other by some means and each application has its own database. They have created a common database called Reporting Layer, the database consists of only stored procedures, that is the stored procedures are collecting data from all the databases and making up a dataset. Now I need to develop reports using these stored procedures. Consider these stored procedures as tables for now.
    If you have got the basics, here is my concern about using stored procedures for the reports.
    Example : Say I need to refer 3 stored procedures for my report to get the required data then I need to call or attach all the three stored procedures with crystal and link them properly to get the required data. The question here is, say I need only 2 columns from each stored procedure then I simply drag the columns needed and drop on the reports...!!!
    So if I had a view instead of a stored procedure then I could refer 3 views in the command object or might have written a stored procedure to return the results containing only the columns the report is ment for.
    Select v1.a, v1.b, v2.a, v2.b, v3.a, v3.b from v1,v2,v3 where v1.id = v2.id and v1.id = v3.id
    or
    Select v1.a, v1.b, v2.a, v2.b, v3.a, v3.b from v1 inner join v2 on v1.id = v2.id inner join v3 on v1.id = v3.id
    I want to explain this to my client and ask them to convert all the stored procedures to views, please suggest what can I tell them ? And if you think that the method my client has opted that is of stored procedures is better than views then please explain in this scenario.
    Thanks
    -Azhar

    Hi Azhar,
    Not sure if you are in the right place, you would likely get a better description if you post your question to the Forums for which ever DB server you are using. They likely have more detailed info on the efficiencies of each.
    For Crystal Reports one possble scenario with using multiple Stored Proceedures (SP) is that each SP would or should be in it's on subreport. Unless you can link them, this will cause the SP to run each time that section is hit. Worst Example is if you put the subreport in the detail section for every record returned the subreport would run. If in the group header for each Group header condition met the subreport would run.
    Using them in a Command Object would work but not that efficient and would be better if you used one SP to get the data or use a database to save all the data into as you suggested and report directly off of it.
    As for the amount of data the SP returns CR may only ask for the fields used, depends on a few conditions, or it may have to get all of the data and filter out just the fields used in the report. Could be a big delay waiting for the SP to run and/or client side data filtering.
    As for Views all the data collection is done server side, same as an SP, but only one view would be required. Or you may want to create specific SP's for use in the reports and not use Command Objects but simply drop the SP into the Database Wizard as the data source. This way all data collection is done server side which is much more efficient and CR at filtering data.
    CR does not care if you use Views or SP's, we are simply sending the SQL to the server and waiting for the results. Which one is more efficient is more for that DB forum to answer.
    Hope this helps
    Don

  • Procedure to view a photo on the E72

    The procedure to view a photo on the E71 model is different from the E72 model.
    The E72 model is to open the photo from the file manager, when we have the photo on screen, we can use the following keys:
    1 - rotate left
    3 - rotate right
    4 - move up
    6 - move down
    2 - move right
    8 - move left
    * - Zoom in
    # - Zoom out
    E61 - E51 - E90 - E71 - 5800 - E72 - E52 - E55

    The procedure to view a photo on the E71 model is different from the E72 model.
    The E72 model is to open the photo from the file manager, when we have the photo on screen, we can use the following keys:
    1 - rotate left
    3 - rotate right
    4 - move up
    6 - move down
    2 - move right
    8 - move left
    * - Zoom in
    # - Zoom out
    E61 - E51 - E90 - E71 - 5800 - E72 - E52 - E55

  • Stored procedures with view in tabular form

    Dears,
    i use apex 4.2 and database xe 11g , i have create tabular depend on view and i use stored procedures in process after computation and validation , the problem that view not update
    this tabular form query
    select
    "ROWID",
    "DOC_DET_ID",
    "DOC_ID",
    "MOV_QNTY",
    BATCH_DET,
    "ITEM_NAME",
    "UOM_NAME",
    "SIZE_NAME",
    "COLOR_NAME",
    "STOREG_BRCHAS_BATCHINTERNN",
    "EXPR_DATE",
    "PROD_DATE",
    AVL_QNTY,
    storage_code,
    "LOCATION_CODE"
    from "#OWNER#"."STORAGE_MOV_DET_VIEW"
    WHERE DOC_ID =:P117_DOC_IDthis a process that i use stored procedure in it
    DECLARE
       V_OLD     NUMBER:=0;
    BEGIN
       FOR i IN 1 .. apex_application.g_f02.COUNT  LOOP
          IF apex_application.g_f02 (i) IS NOT NULL THEN
             SELECT MOV_QNTY INTO V_OLD
              FROM STORAGE_MOV_DET
              WHERE DOC_DET_ID =apex_application.g_f02 (i);
               IF apex_application.g_f13 (i) >  V_OLD THEN
                 V_OLD :=apex_application.g_f13 (i)- V_OLD;
               END IF;
         ELSE
             V_OLD :=apex_application.g_f13 (i);
         END IF;
         if  V_OLD  <> 0 then
            GET_EXTRACT_PARENT_ITEM(apex_application.g_f04 (i) ,
                                   :P117_STORAGE_CODE ,
                                   apex_application.g_f12 (i) ,
                                   V_OLD);
        end if;
    END LOOP;
    END;when i use update this error i found
    Current version of data in database has changed since user initiated update process. current row version identifier = "A80CEBCFF06062F98D920BC75CB415AE" application row version identifier = "BCBA67120A87213D64EE059E10F3B15C" (Row 1)please help

    Do you still have the Apply MRU process running? I assume you do because otherwise you wouldn't receive the error message. Is the process you are talking about running before the Apply MRU process? It seems it does. Try chaning the execution sequence and run this process after the automatic MRU process.
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.apress.com/9781430235125
    http://apex.oracle.com/pls/apex/f?p=31517:1
    http://www.amazon.de/Oracle-APEX-XE-Praxis/dp/3826655494
    -------------------------------------------------------------------

  • Calling HANA procedures and Views in oracle DB as secondary DB

    Hi Experts
    I have a doubt
    we know using secondary database connection we can access HANA DB
    My primary database is Oracle and Secondary DB is HANA
    While creating secondary database connection we need to define default schema.
    As we know we can access only the tables present in default schema
    Can we access view and procedures created in the default schema or _SYS_BIC schemas  in ECC report running on oracle db using ADBC ?
    Message was edited by: Jens Weiler

    Hi Pawan,
    not sure if I understand your use case correctly.
    You can use a secondary DB to the HANA system. Via this secondary DB connection (e.g. in ADBC) you can create views/procedures in the HANA system. And (using again a secondary DB connection) you can consume the views/procedures.
    You should not define a schema explicitely in the DDL/DML statements, this is done kind of automatically when you use the secondary database connection.
    On the other hand, you have your Oracle DB. You can as well define views/procedures in the Oracle DB via ADBC and consume them (of course with Oracle DB specific syntax :-)). You can use the connection to your primary database, i.e. Oracle DB. You can even use a secondary database connection to your primary database.
    What's the concrete use case you'd like to do?
    Cheers,
      Jasmin

  • Decrypt the Encrpted Stored procedure and views

    Hi,
          Anybody can help me, how to decrypt the encrypted stored procedure in SQL server.?

    They are not encrypted. They are obfuscated. ApexSQL can show you the source code with the wink of an eye.
    But before you do that - if this is a vendor application, check your license agreement.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Guided Procedures runtime view custom

    Hello everybody,
    is possible modify standard guided procerdure RUNTIME iview...
    i need remove "OVERVIEW" view and "YOU CAN" vied from runtime GP view.
    how can do this ?
    than you
    Stefan

    thank's everybody

  • Editing of View - screen is different to Procedures

    Hi,
    I use SQL devleoper 1.1.3.
    When I want to edit a procedure, I press the edit button and the editable code is available in a new tab. But when I want to edit a view, the only option is to right click on the view name and select Edit. The Edit view window is a very unfriendly looking window where one can not see the code like the Procedure edit Tab window.
    Is there any setting which will eanble me to edit View similar to the Procedure editing?
    Thank you.

    No, but it shouldn't be too difficult to write an extension for this.
    If you search the source for the procedure and view nodes, you should be able to copy the Edit context menu entry from one to the other. Pack the additions as an extension, and you can even publish you're enhancement on the Extension Exchange.
    Have fun,
    K.

  • How to refresh/redraw visuals in a mobile view

    I have an issue with a list properly sizing itself.  Here's my basic layout:
    <s:Scroller width="100%" height="100%" >
            <!-- required b/c scroller can only handle one component -->
            <s:Group width="100%" >
                <s:layout >
                    <s:VerticalLayout gap="0" />
                </s:layout>
                   <!-- text blocks -->
                   <s:List width="100%" id="textBlocks"
                                        dataProvider="{calendar.taskDetails}"
                                        itemRenderer="components.BBWListMultilineRenderer">
                    <s:layout>
                        <s:VerticalLayout variableRowHeight="true" gap="0" horizontalAlign="justify"/>
                    </s:layout>
                </s:List >
                <components:BBWHeaderSubComp label="Team Members"/>
                <s:List width="100%"
                             dataProvider="{calendar.taskLogins}" />
    The issue is with how the list handles the test block area.  My custom renderer allows for multiple lines of text.  Let's assume I've got two "blocks" of text (two rows within the list each with multiple lines of text) as shown in the screen shot below.  If the first text block is larger than the second then the second block is drawn reserving the same height as the first.  As you can see below, the second block "ends" and there is still more space to make up for the difference in size.
    HOWEVER, if I make an orientation change (emulator or device) then the list instantly snaps everything to the right size. 
    Here is how it looks after the orientation change:
    So, how do I get the visuals to update via code as I can't just tell users to switch their orientation?  Thanks!

    take a look at this:
    Diagnosis
        In the view, not all of the mandatory fields were included as key
        fields. The key of the view therefore is not unique.
    System Response
        All the fields are regarded as key fields in order to guarantee that th
        key lengths are unique.
    Procedure
        For views with a large number of fields, this could have a negative
        effect on the performance for the language construction described below
        In this case, all the mandatory key fields should be included in the
        view.
    regards

  • Can not see all the SQL server views

    My SQL Server 2005 (SP2 STD)  has about 1000 views. When I created a Crystal Report using Crystal Report 10, I can only see about 225 views are listed in Database Expert. Here is the procedure to reproduce the problem:
    1. Create a new Crystal Report
    2. Create a new connection using ODBC RDO
    3. Drill into DSN Name->DB Name->dbo->Views. Only the first 200 or so views in alphabetical order are listed on Available Data Sources on the left pane.
    I am using SQL authentication and sa account to connect to SQL. So security should not be the problem. I can also use Access 2003 linked table to see all the views in my SQL server.
    Is there a restriction on how many views can be listed in Crystal Data Source? Is there another way to add data source to Report without using Database Expert?
    Thanks in advance!

    Youdao,
    There is a default limit of 8000 objects that Crystal will see in the database.
    I would suggest right clicking on your datasource and selecting Options. In the Data Explorer uncheck Tables and Stored Procedures leaving Views selected > press OK > then right click again and refresh.
    If the limit was being reached then you should now see at least more Views if not all.
    The default limit can be edited in the Registry (*Always recommended to back up the registry before editing).
    The key is HKEY_CURRENT_USER > Software > Crystal Decisions or Business Objects > (version number) > Crystal Reports > Fetch options > NTablesMax

  • PL SQL Procedure Problem

    I have a procedure that resides in a package and which is called by another application(Adobe Flex app).
    I would like to strip out and run/test individually one of the procedures with the package.
    I dont know how to create the procedure as a standalone procedure first. The reason for the test is that I have an application that has data (by month) for a range of dates in the tbl_dashb_data table. The procedure should return 14 records for data in the table for a date range of Jan07-Feb08.
    What I would like to do is run the procedure or the package and test to see how many records are returned.
    Do I need to put in a DBMS_OUTPUT.PUT_LINE statement into the procedure to view results in an SQL Plus session?
    Do I need to hardcode some of the variables in the procedure to get results.
    Im new to PL-SQL and trying to debug an application, any help would be great
    thanks
    [email protected]
    The package that it resides in is defined as;
    create or replace PACKAGE "PKG_DASHB_DATA" IS
    TYPE crsr_Data is REF CURSOR;
    PROCEDURE sp_getDateRange(p_TargetComp_ID IN NUMBER,p_Data OUT crsr_Data);
    END pkg_Dashb_Data;
    PROCEDURE sp_getDateRange(p_TargetComp_ID IN NUMBER,p_Data OUT crsr_Data) IS
    start_Date DATE;
    end_Date DATE;
    start_Year NUMBER;
    end_Year NUMBER;
    start_Month NUMBER;
    end_Month NUMBER := 24;
    lbl_TmpDate DATE;
    lbl_Month VARCHAR(30);
    lbl_Year VARCHAR(30);
    BEGIN
    SELECT MIN(Publication_Date),MAX(Publication_Date) INTO start_Date,end_Date FROM tbl_Dashb_Data WHERE
    Target_Cmpny_ID = p_TargetComp_ID ;
    start_Year := TO_CHAR(start_Date,'YYYY');
    end_Year := TO_CHAR(end_Date,'YYYY');
    start_Month := TO_CHAR(start_Date,'MM');
    end_Month := TO_CHAR(end_Date,'MM');
    FOR vYear IN start_Year..end_Year
    LOOP
    FOR vMonth IN start_Month..end_Month
    LOOP
    lbl_TmpDate := TO_DATE('01-' || vMonth || '-' || vYear,'DD-MM-YYYY');
    lbl_Month := TO_CHAR( lbl_TmpDate ,'MONTH');
    lbl_Year := vYear ;
    INSERT INTO TMPTBL_DATERANGES VALUES( lbl_Month ,lbl_Year);
    END LOOP;
    END LOOP;
    COMMIT;
    OPEN p_Data FOR
    SELECT * FROM TMPTBL_DATERANGES;
    END;

    Hi,
    If you really need to make a stand-alone procedure from a package procedure, it's basically just a matter of adding "CREATE OR REPLACE " in front ot "PROCEDURE". See the SQL Reference manual (under "CREATE PROCEDURE") for details.
    Like Warren said, you can run the package procedure from SQL*Plus, so there's no need to make a stand-alone version. One thing you can't do from SQL*Plus is have OUT-parameters. Put the call in an anonymous block, which you can run from SQL*Plus:
    DECLARE
         c     pkg_dashb_data.crsr_data;
    BEGIN
         pkg_dashb_data.sp_getDateRange(10, c);
    END;
    /There's no reason to hard-code any variables. Is there a reason why you think that would help?
    That's all I have to say about the questions you asked.
    Below is a suggestion that you didn't request, but I hope it helps you.
    SQL has a DATE type, with lots of convenient features. TO_CHAR (DT) is useful for displaying a DATE, but think very carefully before using it for any other purpose. Converting DATES to strings or numbers to manipulate them, and then convert them back is cumbersome, inefficient, error-prone and only rarely necessary.
    For example, you could write the procedure like this:
    CREATE OR REPLACE PROCEDURE sp_getDateRange2
    (     p_TargetComp_ID     IN     NUMBER
    ,     p_Data          OUT     pkg_dashb_data.crsr_Data
    ) IS
         start_Date DATE;
         end_Date DATE;
         lbl_TmpDate DATE;
         lbl_Month VARCHAR(30);
         lbl_Year VARCHAR(30);
    BEGIN
         SELECT     MIN (Publication_Date),     MAX (Publication_Date)
         INTO     start_Date,          end_Date
         FROM     tbl_Dashb_Data
         WHERE     Target_Cmpny_ID = p_TargetComp_ID ;
         lbl_TmpDate := TRUNC (start_date, 'MM');
         WHILE  lbl_TmpDate <= end_date
         LOOP
              lbl_Month := TO_CHAR( lbl_TmpDate ,'MONTH');
              lbl_Year := TO_CHAR( lbl_TmpDate ,'YYYY');
              INSERT INTO TMPTBL_DATERANGES VALUES( lbl_Month ,lbl_Year);
              lbl_TmpDate := ADD_MONTHS (lbl_TmpDate, 1);
         END LOOP;
         OPEN p_Data FOR
              SELECT * FROM TMPTBL_DATERANGES;
    END;
    /

  • How to set key fields in a Database view

    Hi guru's
    iam balaji,plz guide me with how to set key fields in a view.......that field is a non key field in the base table....
    thanks in advance,
    Balaji.S

    take a look at this:
    Diagnosis
        In the view, not all of the mandatory fields were included as key
        fields. The key of the view therefore is not unique.
    System Response
        All the fields are regarded as key fields in order to guarantee that th
        key lengths are unique.
    Procedure
        For views with a large number of fields, this could have a negative
        effect on the performance for the language construction described below
        In this case, all the mandatory key fields should be included in the
        view.
    regards

Maybe you are looking for

  • Diff b/w occurs 0 and 1

    hi, what is the difference b/w occurs 0 and occurs 1? and what is the significance of begin of?

  • Macbook lagging to Appel Tv.

    After installing Yosemite i now have problems with streaming from my macbook to appel tv. Why. No problems with maverick.

  • Updating an index in InDesign CS6 and retaining commas

    I have an index in a book document I am creating in InDesign CS6 and as I add imagery to the text the page numbers change so I go to the index panel and generate index which overrides the previous version. This has been working perfectly but my last

  • HP C6180 will not install correctly.

    I have a C6180 All in one Photosmart printer it has a scanner and fax also I can not get it installed right. It only shows a plan printe. rAlso the HP solution Center keeps trying to download unsuccessfully.

  • Control Table of Content

    Hello all, I've searched for ages now and can't find how to control the Captivate SWF i created. In the ToC i made diffrent entries (including "directories"). I would like to control the movie from a link (html, flash var?). I made a manual in Captiv