Procedure grant issue

I have 2 schema (schema1 and schema2) in same databaase.if I create following procedure in schema1 for selecting a tale in schema2.
CREATE OR REPLACE PROCEDURE schema1.select_test
AUTHID CURRENT_USER as
v_test number;
BEGIN
select count(*)
into v_test
from schema2.table1;
end;
I created a role called SCH1_ROLE for schema1 and granted access of table1 to this role from schema2 but still if I compile the procedure it is saying table does not exist.Please help.

This question is asked many times per week, though there is a plethora of resources available answering it.
Roles are disabled during compilation of stored procedures, as roles are volatile.
There are three solutions to this in order of preference.
1 Make sure the owner of the procedure equals the owner of the table, grant execute privilege on the procedure.
This is called encapsulation
2 Create the procedure with the authid current_user pragma. However this will result in a parse the procedure is invoked for the first time
3 NOT preferred: grant SELECT privilege on the procedure directly, not using roles. This will result in a myriad of grants.
Solution 1 is the best solution.
Sybrand Bakker
Senior Oracle DBA

Similar Messages

  • Approval Procedure for Issue to Production and Receipt from Production

    Hi All,
    Is there a way to create an approval procedure for Issue to production and Receipt from production?
    Thanks.
    Eric

    Hi Riyaz,
    Yes it is not in Standard SAP Business One.  But is there a way to create one for issue to production and receipt from production? 
    Thanks.
    Eric

  • Object granting issues 11g

    We are in the process of migrating to 11.2.0.2 RAC/ASM on new hardware from 10.2.0.4 RAC/OCFS2 ... as such I am migrating my entire database using Data Pump Export/Import. Everything seems to have come over fine and the only errors I see in my import logs are related to objects already existing in the SYS schema. Now to my issue ...
    I have an object GN.UNPOST_JOURNAL_ENTRY ... execute rights on this object have been given to the role GL_ADMIN. This role has been then granted to my non admin SCARLSON user account. In our 10.2.0.4 system this works just fine ... but in our 11g system I am unable to execute this procedure. In fact the only way I am able to see the procedure is to grant my SCARLSON account execute rights directly or grant my SCARLSON account the system privelege of "EXECUTE ANY PROCEDURE" ...
    I have already completely deleted DB instance, recreated my instance, ran my export/import, removed the object, roles, groups, and grants no less than 20 times at this point with the same results ... has anyone ran into this issue before or does anyone have an idea of what to start looking into first?

    Is the role password protected ? You can check with :
    select * from dba_roles where role = 'GL_ADMIN';Password protected roles are no more enabled by default since 10.2.0.5: see Oracle Patchset 10.2.0.5.0 impact on password enabled roles

  • Grant issue for oracle package LT_EXPORT_PKG

    Hi,
    I am having oracle 10g with version 10.2.0.4
    While giving execute grant on "LT_EXPORT_PKG" to one of my schema it gives error :
    USING SYS USER:
    GRANT EXECUTE ON LT_EXPORT_PKG TO <SCHEMA-NAME>;
    ERROR at line 1:
    ORA-04042: procedure, function, package, or package body does not exist
    i checked package "LT_EXPORT_PKG " in "sys" user it gives below result:
    SQL> select owner,object_name,status from dba_objects where OWNER = 'SYS' and OBJECT_NAME = 'LT_EXPORT_PK
    G';
    no rows selected
    SQL>
    the same script executes successfully on oracle 10g with version 10.2.0.1.
    How to rectify this issue now.

    mohsin javed wrote:
    Hi,
    I am having oracle 10g with version 10.2.0.4
    While giving execute grant on "LT_EXPORT_PKG" to one of my schema it gives error :
    USING SYS USER:
    GRANT EXECUTE ON LT_EXPORT_PKG TO <SCHEMA-NAME>;
    ERROR at line 1:
    ORA-04042: procedure, function, package, or package body does not exist
    i checked package "LT_EXPORT_PKG " in "sys" user it gives below result:
    SQL> select owner,object_name,status from dba_objects where OWNER = 'SYS' and OBJECT_NAME = 'LT_EXPORT_PK
    G';
    no rows selected
    SQL>
    the same script executes successfully on oracle 10g with version 10.2.0.1.
    How to rectify this issue now.
    Hi,
    That is because the package does not exist, you have select from dba_objects and nothing returned so the object does not exist
    If the package exist in 10.2.0.1 then simply copy and create it in 10.2.0.4
    Cheers

  • Role granting issue

    Hi,
    I have created one role with some system privileges like create any table,dubug any procedure etc and with some object prvileges like select grant on DBA_TABLES, DBA_JOBS etc. Now I have granted the role to a different user where I have written a package which consist of few procedures, one of the procedures in package spec like below :
    PROCEDURE REGISTER (
    p_Owner IN ORBIT_DELTA_CNTL.OWNER%TYPE,
    p_Object IN ORBIT_DELTA_CNTL.NAME%TYPE,
    p_Type IN ORBIT_DELTA_CNTL.OBJECT_TYPE%TYPE,
    p_RefreshInterval IN DBA_JOBS.INTERVAL%TYPE,
    p_PurgeInterval IN DBA_JOBS.INTERVAL%TYPE,
    p_Tablespace IN DBA_TABLES.TABLESPACE_NAME%TYPE DEFAULT NULL
    which throws a error during compilation "PLS-00201: identifier 'DBA_JOBS' must be declared". Can any one please explain why this error is coming though I have granted the role to that user.
    Regards,
    Koushik

    Koushik,
    The reason is probably dependencies related. When an object gets invalid, all dependent objects get invalid et cetera. When objects could be valid because of a grant via a role, this means that an object could get invalid by revoking a grant from a role. Because granting user access via a role should not make big parts of the database invalid, it is only allowed via direct grants.
    Regards,
    Rob.

  • Stored Procedure Command issues in CS3

    I've been having a problem using some stored procedures in
    CS3 which had previously worked with no issue in 8.0.2. I'm running
    CS3 on a Mac for ASP & SQL Server 2000.
    The input parameters for the stored procedure are...
    Fieldname: CategoryID (int) length: 4
    Fieldname: Men (bit) length: 1
    Fieldname: Women(bit) length:1
    I have no problem using the Command function to call this
    stored procedure in DW 8.0.2, but in CS3, while I am able to TEST
    the recordset successfully within the Command dialog, when I press
    OK and then attempt to view the field list in the Bindings panel, I
    get this error...
    [Microsoft][ODBC SQL Server Driver][SQL Server]Procedure
    'spCategoryProduct' expects parameter '@Men', which was not
    supplied.
    When I open up the command settings dialog again, Default
    Values and the Runtime Values I entered for the Men and Women bit
    parameter are blank. The only Default Value and Runtime Value
    retained is for the field CategoryID.
    CS3 is able to call other stored procedures which do not
    contain a Bit field type without issue, so I'm curious if this is
    the culprit.
    I have DW8.0.2 still installed on the same system, and have
    been able to call this stored procedure in this older version,
    without any problems.
    Please help!

    Holy thread-resurrection Batman!
    Please open a new dicussion after reading the bi4.0 data access guide: http://help.sap.com/businessobject/product_guides/boexir4/en/xi4sp5_data_acs_en.pdf
    Also, please specify which SP and Patch you are using.
    Regards,
    H

  • DBAdapter procedure call issue (dev and test env have seperate schema)

    Hi All
    We are facing an issue with DBAdapter (even after commenting the schema name from JCA file). The procedure is using SQL objects and collections. The DBAdapter is trying to find these objects in the old schema (the one used in dev) but they are compiled on a diff schema in INT and hence it is throwing an exception.
    How can i get this to work. Please help.
    CREATE OR REPLACE
    TYPE QUERY_INVENTORY AS OBJECT (
    requestingstoreid VARCHAR2 (20),
    simuserid VARCHAR2 (60),
    storeidlist vfuk_store_id_list,
    itemidlist vfuk_item_id_list,
    flexfield1 VARCHAR2 (200),
    flexfield2 VARCHAR2 (200),
    flexfield3 VARCHAR2 (200)
    CREATE OR REPLACE
    TYPE QUERY_INVENTORY_LIST AS TABLE OF QUERY_INVENTORY;
    CREATE OR REPLACE PACKAGE abcd
    AS
    PROCEDURE def (
    i_queryrequest IN QUERY_INVENTORY_LIST,
    o_errormsg OUT VARCHAR2,
    o_errorcode OUT VARCHAR2
    END abcd;
    /

    Hi Arik
    Thanks for the reply. A DB procedure with normal arguments (VARCHAR, DATE etc) is working fine after commenting the schema name in JCA file (It is taking the schema name from data source).
    But if you use SQL objects and SQL collections as IN\OUT parameters, it generates the XSD with complex types that have the schema prefix attached to them. So, even after commenting in JCA it is still looking for those SQL objects in the OLD schema.
    Do i need to change the prefixes in the XSD as well? This would not be a feasible option as i would have to do it for all the environments.
    Somebody pls help....

  • Grant issue  .DBMS_SESSION

    Hi
    I create a procedure but get this error.
    i have given my user
    SQL> grant ALTER SESSION to UMESH;
    Grant succeeded.
    SQL> GRANT CREATE ANY CONTEXT TO UMESH;
    Grant succeeded.
    SQL> grant create session to umesh;
    Grant succeeded.
    SQL> grant create any context to umesh;
    Grant succeeded.
    SQL> grant create table to umesh;
    Grant succeeded.
    SQL>
    SQL>
    SQL> grant execute on dbms_rls to umesh;
    Grant succeeded.
    SQL> grant execute on dbms_session to umesh;
    Grant succeeded.
    CREATE OR REPLACE package body SearcProduct_Pkg  is
    procedure SearchProVar(PCode in varchar2, Storeid in number,Usertype in varchar2) is
    begin
    dbms_session.set_context(
    namespace => 'paramsNew1', attribute => 'PCode', value => PCode);
    dbms_session.set_context(
    namespace => 'paramsNew1', attribute => 'Storeid', value => Storeid);
    dbms_session.set_context(
    namespace => 'paramsNew1', attribute => 'Usertype', value => Usertype);
    dbms_output.put_line('pcode is'||PCode);
    end SearchProVar;
    end SearcProduct_Pkg;
    when i execute it
    like
    SQL>  DECLARE
      2     PCODE VARCHAR2(200);
      3     STOREID NUMBER;
      4     USERTYPE VARCHAR2(200);
      5
      6   BEGIN
      7     PCODE := '655454';
      8     STOREID := 5030;
      9     USERTYPE := NULL;
    10
    11     UMESH.SEARCPRODUCT_PKG.SEARCHPROVAR ( PCODE, STOREID, USERTYPE );
    12   END;
    13   /
    DECLARE
    ERROR at line 1:
    ORA-01031: insufficient privileges
    ORA-06512: at "SYS.DBMS_SESSION", line 82
    ORA-06512: at "UMESH.SEARCPRODUCT_PKG", line 4
    ORA-06512: at line 11
    thanks.

    Sir
    i made this package and this pages is used in a view which is
    CREATE OR REPLACE VIEW SEARCHPRODUCT_VIEW ( ITEM_ID,
    PRODUCT_ID, PRODUCT_NAME, OPT1, OPT1VALUE,
    OPT2, OPT2VALUE, PRICE, ASL
    ) AS Select b.Item_id,b.Product_id,a.Product_name,
    (select attribute_name from attribute_master where attribute_id=(select attribute_id from attribute_property where property_id=b.Color) and rownum=1) as opt1,
    (select attribute_property from attribute_property where property_id=b.Color) as opt1value,
    (select attribute_name from attribute_master where attribute_id=(select attribute_id from attribute_property where property_id=b.size1)and rownum=1) as opt2,
    (select attribute_property from attribute_property where property_id=b.Size1) AS opt2value,
    ((case when upper(sys_context('paramsNew1', 'Usertype'))='W' then b.WHOLE_SELL_PRICE
    when upper(sys_context('paramsNew1', 'Usertype'))='R' then b.RETAILER_PRICE
    end )+b.extra_price)  as Price
    ,b.Actual_stock_level as ASL from product_master a,product_detail b where a.p_id=b.p_id and Upper(a.product_id) like  Upper('%'||sys_context('paramsNew1', 'PCode') || '%' ) and a.Storeid=to_number(sys_context('paramsNew1', 'Storeid'))i think i need to give some permission on this view
    but don't know what to give
    thanks

  • Grants issue !!

    Hi,
    O/S : HP Unix
    DB : 11.2.0.3
    Server Source_A : Let's say i have user with the name 'Rob' and this user has been assigned a role 'MY_SRC_ROLE' .
    I developed a table under rob schema and granted access to this table via role
    GRANT DELETE, INSERT, SELECT, UPDATE ON rob.emp TO MY_SRC_ROLE;
    I have 100 more users & they have been granted this role 'MY_SRC_ROLE'. These 100 users can now access emp table via Role 'MY_SRC_ROLE' without any issues.
    Now i took a datapump export & performed datapump import on target server which is also HP Unix with 11.20.3 . On target server i have user 'JACK' and a role called 'MY_WORK_ROLE'. 5000 users have been granted 'MY_WORK_ROLE' on this server.
    I have used remap tablespace clause & remap schema clause in datapump import script. Once i performed an import , due to schema remap , i can see JACK now owns table 'emp', however grants are still not there, I tried searching on google & oracle documentation, if somehow we can remap ROLE GRANTS also while doing datapump imp, but i couldn't find supporting syntax. Am i missing something or probably can i assume datapump import is not capable to handle this particular scenario ? I was able to do it by manipulating sqlfile and replacing role name in that but i am looking for a sol. within datapump itself.
    So bottom line how can grants assigned to ROLE 'X' be transferred to 'Role Y' via datapump import.
    Let me know, if any any additional details are required.
    -Learner    

    Hi,
    AFAIK, you can not remap/rname the roles. you can generate the Dynamic script and Apply on Target
    something like that
    spool role_target.sql
    select 'grant '|| PRIVILEGE || ' MY_WORK_ROLE;' from dba_sys_privs where GRANTEE='MY_SRC_ROLE';
    spool off
    @role_target.sql
    HTH

  • Stored Procedure/Variable issue

    Hopefully this is the last issue to work through... but we need to access images stored on another server. We have a stored procedure called 'get_doc' that accesses the image file, and we've successfully tested it with a hardcoded value. A button calls a process that executes the following PL/SQL:
    get_doc (
    p=> 77456);
    However, when I use the same process with a variable on the page (which has the same numeric value of 77456), the procedure says the value of p is Null.
    get_doc (
    p=> :P7_STARTERNUM);
    Any suggestions or advice?
    (Using ApEx 4.0 in IE8)

    CPate  wrote:
    Yes, the connection is correct. And I swapped in the hardcode number, the process does what it is supposed to and returns the image. Swap back in the variable (with to_number as well, just to be sure) and it returns null.
    I tried debugging it and didn't see where P7_STARTERNUM was changed. It just says:
    ..Process "STARTERGET": PLSQL (AFTER_SUBMIT) get_doc (p=&gt; to_number(:P7_STARTERNUM));The trace should look something like:
    0.00275     0.00220     A C C E P T: Request="SAVE"
    0.00484     0.00801     Metadata: Fetch application definition and shortcuts
    0.01291     0.00110     alter session set nls_language="ENGLISH"
    0.01399     0.00069     alter session set nls_territory="UNITED KINGDOM"
    0.01476     0.00084     NLS: CSV charset=WE8MSWIN1252
    0.06085     0.00087     Session State: Save form items and p_arg_values
    0.06173     0.00146     ...Session State: Save "P7_CUSTOMER_ID" - saving same value: "7"
    0.06319     0.00264     ...Session State: Save Item "P7_CUST_FIRST_NAME" newValue="Eugene" "escape_on_input="N"     
    0.33200     0.00090     Processing point: After Submit
    0.33285     0.11813     ...Process "Process Row of DEMO_CUSTOMERS": DML_PROCESS_ROW (AFTER_SUBMIT) #OWNER#:DEMO_CUSTOMERS:P7_CUSTOMER_ID:CUSTOMER_ID|IUD
    {code}
    There should be a session state change like those shown recorded for your <tt>P7_STARTERNUM</tt> item.
    What's the *Display As* type of the <tt>P7_STARTERNUM</tt> item?
    the procedure says the value of p is Null.
    How do you know this?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Stored Procedure creation issue

    Hi All,
    I need a stored procedure's for below Scenario:
    tblProduct is a parameter table that has values list of Products and every product has code (Eg, PEN A, BOOK B , PENCIL C and so on)
    For every value a procedure sp_findIndex will be called 
    sp_findIndex finds the index of the alphabet based on the tblKeyValue a key value table which has two columns key and value, key 1,2,3....
    and values A,B,C..
    Further sp_findIndex calls sp_evenOdd with
    the index as input and provides an output whether index is an even or an odd number 
    which is printed through sp_findIndex procedure 
    Task 1
    List down even and odd for all the products.
    Task 2
    Now warp this logic to stored procedure sp_wrapper which takes input Product names separated by comma.
    Thanks in Advance.........
    Tbl_Product
    Create table Tbl_Product
    Product varchar(50) NULL,
    Code Varchar (50) NULL
    Insert into Tbl_Product values('PEN','A')
    Insert into Tbl_Product values('BOOK','B')
    Insert into Tbl_Product values('PENCIL','C')
    Insert into Tbl_Product values('TV','D')
    Insert into Tbl_Product values('COMPUTER','E')
    Insert into Tbl_Product values('SHOES','F')
    Insert into Tbl_Product values('SHIRT','G')
    Tab_KeyValue
    Create table tbl_KeyValue
    value char(3) NULL,
    keys int NULL
    Insert into tbl_Keyvalue values('A',1)
    Insert into tbl_Keyvalue values('B',2)
    Insert into tbl_Keyvalue values('C',3)
    Insert into tbl_Keyvalue values('D',4)
    Insert into tbl_Keyvalue values('E',5)
    Insert into tbl_Keyvalue values('F',6)
    Insert into tbl_Keyvalue values('G',7)
    Main
    Procedure:
    CREATE PROCEDURE DBO.SP_WRAPPD
    (PRODUCT1 VARCHAR(1000))
    AS
    BEGIN
    DECLARE @COMMA VARCHAR(2)
    SET @COMMA =','
    SELECT CODE FROM TBL_PRODUCT WHERE CHARINDEX(PRODUCT,@PRODUCT) >0
    END
    Second
    procedure:
    Create Procure sp_findIndexes(@value varchar(10))
    as
    begin
    Declare @keys int
    set @Keys =(select A.keys from tbl_keyvalue A where A.value=@value)
    Declare @Evenodd varchar(10)
    Declare @result int
    Exec @result =sp_EvenOdds @keys
    if @result=1
    set @EvenOdd ='Even'
    else
    set @EvenOdd='Odd'
    insert into ##EvenOddResultss select A.keys,B.Product,@evenodd as evenodd from tbl_product B
    inner join
    tbl_KeyValue A
    on A.Value=B.code and A.keys=@keys
    end
    Third
    Procedure:
    Create procedure sp_EvenOdds (@Key int)
    as
    begin
    if(@key%2=0)
    return(1)
    else
    return(0)
    end
    I am calling third procure from second,second from Main Procedure...
    Thanks in Advance...

    Hi,
    1. Again this is a image and not a code!
    Do you want to waste our time on typing while we can help other people?!?
    Isn't it more helpful to use copy/paste and to bring us a code and not stories/images? 
    2. How can we recreate the issue and execute or even just create this SP without having the relevant elements (like the tables) ?!?
    Please post DDL+DML!
    DDL = Data Definition Language. In our case that is, CREATE TABLE statements for your tables and other definitions that are needed to understand your tables structure and there for let us to test and recreate the problem in our server. Without DDL no one
    can execute any query.
    How to get DDL: Right click on the table in Object Explorer and select script table as CREATE. Post these create table scripts here.
    DML = data manipulation language is a family of queries used for manipulating the data it self like: inserting, deleting and updating data. In our case we need some sample data in order to check the query and get result, so we need some indert query for
    sample data.
    If you post a "create query" for the tables and "insert query" with some sample, then we could help you without Assuming/Guessing. There is a reason that DDL is generally asked for and expected when discussing query problems - it helps
    to identify issues, clarify terminology and prevent incorrect assumptions.  Sample data also provides a common point of reference for the discussion. A script that can be used to illustrate or reproduce the issue you have, will encourage others to help.
    [Personal Site] [Blog] [Facebook]
    Hi Pituach,
    Tbl_Product
    Create table Tbl_Product
    Product varchar(50) NULL,
    Code Varchar (50) NULL
    Insert into Tbl_Product values('PEN','A')
    Insert into Tbl_Product values('BOOK','B')
    Insert into Tbl_Product values('PENCIL','C')
    Insert into Tbl_Product values('TV','D')
    Insert into Tbl_Product values('COMPUTER','E')
    Insert into Tbl_Product values('SHOES','F')
    Insert into Tbl_Product values('SHIRT','G')
    Tab_KeyValue
    Create table tbl_KeyValue
    value char(3) NULL,
    keys int NULL
    Insert into tbl_Keyvalue values('A',1)
    Insert into tbl_Keyvalue values('B',2)
    Insert into tbl_Keyvalue values('C',3)
    Insert into tbl_Keyvalue values('D',4)
    Insert into tbl_Keyvalue values('E',5)
    Insert into tbl_Keyvalue values('F',6)
    Insert into tbl_Keyvalue values('G',7)
    Main Procedure:
    CREATE PROCEDURE DBO.SP_WRAPPD
    (PRODUCT1 VARCHAR(1000))
    AS
    BEGIN
    DECLARE @COMMA VARCHAR(2)
    SET @COMMA =','
    SELECT CODE FROM TBL_PRODUCT WHERE CHARINDEX(PRODUCT,@PRODUCT) >0
    END
    Second procedure:
    Create Procure sp_findIndexes(@value varchar(10))
    as
    begin
    Declare @keys int
    set @Keys =(select A.keys from tbl_keyvalue A where A.value=@value)
    Declare @Evenodd varchar(10)
    Declare @result int
    Exec @result =sp_EvenOdds @keys
    if @result=1
    set @EvenOdd ='Even'
    else
    set @EvenOdd='Odd'
    insert into ##EvenOddResultss select A.keys,B.Product,@evenodd as evenodd from tbl_product B
    inner join
    tbl_KeyValue A
    on A.Value=B.code and A.keys=@keys
    end
    Third Procedure:
    Create procedure sp_EvenOdds (@Key int)
    as
    begin
    if(@key%2=0)
    return(1)
    else
    return(0)
    end
    I am calling third procure from second,second from Main Procedure

  • Approval Procedure For Issue For Production form

    Hi All,
    How to Defind the Approval procedure For the Issue For Production tell me is it possible or not
    vikas

    Hi Vikas,
    As workaround you can set the approval to the stock transfer for the production warehouse and allow only issue for production from that production warehouse.
    Cheers

  • Can someone help me diagnose a strange stored procedure performance issue please?

    I have a stored procedure (posted below) that returns message recommendations based upon the Yammer Networks you have selected. If I choose one network this query takes less than one second. If I choose another this query takes 9 - 12 seconds.
    /****** Object: StoredProcedure [dbo].[MessageView_GetOutOfContextRecommendations_LargeSet] Script Date: 2/18/2015 3:10:35 PM ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE PROCEDURE [dbo].[MessageView_GetOutOfContextRecommendations_LargeSet]
    -- Parameters
    @UserID int,
    @SourceMessageID int = 0
    AS
    BEGIN
    -- variable for @HomeNeworkUserID
    Declare @HomeNeworkUserID int
    -- Set the HomeNetworkID
    Set @HomeNeworkUserID = (Select HomeNetworkUserID From NetworkUser Where UserID = @UserID)
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON
    -- Begin Select Statement
    Select Top 40 [CreatedDate],[FileDownloadUrl],[HasLinkOrAttachment],[ImagePreviewUrl],[LikesCount],[LinkFileName],[LinkType],[MessageID],[MessageSource],[MessageText],[MessageWebUrl],[NetworkID],[NetworkName],[PosterEmailAddress],[PosterFirstName],[PosterImageUrl],[PosterName],[PosterUserName],[PosterWebUrl],[RepliesCount],[Score],[SmallIconUrl],[Subjects],[SubjectsCount],[UserID]
    -- From View
    From [MessageView]
    -- Do Not Return Any Messages That Have Been Recommended To This User Already
    Where [MessageID] Not In (Select MessageID From MessageRecommendationHistory Where UserID = @UserID)
    -- Do Not Return Any Messages Created By This User
    And [UserID] != @UserID
    -- Do Not Return The MessageID
    And [MessageID] != @SourceMessageID
    -- Only return messages for the Networks the user has selected
    And [NetworkID] In (Select NetworkID From NetworkUser Where [HomeNetworkUserID] = @HomeNeworkUserID And [AllowRecommendations] = 1)
    -- Order By [MessageScore] and [MessageCreatedDate] in reverse order
    Order By [Score] desc, [CreatedDate] desc
    ENDThe Actual Execution Plan Shows up the same; there are more messages on the Network that is slow, 2800 versus 1,500 but the difference is ten times longer on the slow network.Is the fact I am doing a Top 40 what makes it slow? My first guess was to take the Order By Off and that didn't seem to make any difference.The execution plan is below, it takes 62% of the query to look up theIX_Message.Score which is the clustered index, so I thought this would be fast. Also the Clustered Index Seek for the User.UserID take 26%which seems high for what it is doing.
    I have indexes on every field that is queried on so I am kind of at a loss as to where to go next.
    It just seems strange because it is the same view being queried in both cases.
    I tried to run the SQL Server Tuning Wizard but it doesn't run on Azure SQL, and my problem doesn't occur on the data in my local database.
    Thanks for any guidance, I know a lot of the slowness is due to the lower tier Azure SQL we are using, many of the performance issues weren't noticed when were on the full SQL Server, but the other networks work extremely fast so it has to be something to
    with having more rows.
    In case you need the SQL for the View that I am querying it is:
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE VIEW [dbo].[MessageView]
    AS
    SELECT M.UserID, M.MessageID, M.NetworkID, N.Name AS NetworkName, M.Subjects, M.SubjectsCount, M.RepliesCount, M.LikesCount, M.CreatedDate, M.MessageText, M.HasLinkOrAttachment, M.Score, M.WebUrl AS MessageWebUrl, U.UserName AS PosterUserName,
    U.Name AS PosterName, U.FirstName AS PosterFirstName, U.ImageUrl AS PosterImageUrl, U.EmailAddress AS PosterEmailAddress, U.WebUrl AS PosterWebUrl, M.MessageSource, M.ImagePreviewUrl, M.LinkFileName, M.FileDownloadUrl, M.LinkType, M.SmallIconUrl
    FROM dbo.Message AS M INNER JOIN
    dbo.Network AS N ON M.NetworkID = N.NetworkID INNER JOIN
    dbo.[User] AS U ON M.UserID = U.UserID
    GO
    The Network Table has an Index on Network ID, but it non clustered but I don't think that is the culprit.
    Corby

    I marked your response as answer because you gave me information I didn't have about the sort. I ended up rewriting the query to be a join instead of the In's and it improved dramatically, about one second on a very minimal Azure SQL database, and before
    it was 12 seconds on one network. We didn't notice the problem at all before we moved to Azure SQL, it was about one - three seconds at most.
    Here is the updated way that was much more efficient:
    CREATE PROCEDURE [dbo].[Procedure Name]
    -- Parameters
    @UserID int,
    @SourceMessageID int = 0
    AS
    BEGIN
    -- variable for @HomeNeworkUserID
    Declare @HomeNeworkUserID int
    -- Set the HomeNetworkID
    Set @HomeNeworkUserID = (Select HomeNetworkUserID From NetworkUser Where UserID = @UserID)
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON
    ;With cteMessages As
    -- Begin Select Statement
    Select (Fields List)
    -- Join to Network Table
    From MessageView mv Inner Join NetworkUser nu on MV.NetworkID = nu.NetworKID -- Only Return Networks This User Has Selected
    Where nu.HomeNetworkUserID = @HomeNeworkUserID And AllowRecommendations = 1
    -- Do Not Return Any Messages Created By This User
    And mv.[UserID] != @UserID
    -- Do Not Return The MessageID
    And mv.[MessageID] != @SourceMessageID
    ), cteHistoryForThisUser As
    Select MessageID From MessageRecommendationHistory Where UserID = @UserID
    -- Begin Select Statement
    Select Top 40 (Fields List)
    -- Join to Network Table
    From cteMessages m Left Outer Join cteHistoryForThisUser h on m.MessageID = h.MessageID
    -- Do Not Return Any Items Where User Has Already been shown this Message
    Where h.MessageID Is Null
    -- An Order By Is Needed To Get The Best Content First
    Order By Score Desc
    END
    GO
    The Left Outer Join to test for null was the biggest improvement, but it also helped to join to the NetworkUser table instead of do the In sub query.

  • Stored procedure Performance issue in SQLserver 2005

    Hi All,
    i am inserting the data to Database by using of Stored procedure in target DB.
    My source structure and target structures are looking below
    I have the source structure having lot of rows and look like my structure is below:
    <?xml version="1.0" encoding="utf-8" ?>
    <ns0:POCA0013_KANLOG_REQUEST_MT_response xmlns:ns0="urn:com:POCA0013:sample">
    <SCMDB_response>
    -  <row>
          <PROJK>O-USA</PROJK>
          <KOLLO>123</KOLLO>
       </row>
    -  <row>
          <PROJK>O-Denmark</PROJK>
          <KOLLO>256</KOLLO>
       </row>
        n  number of rows
    </SCMDB_KANLOGVIEW_response>
    </ns0:POCA0013_KANLOG_REQUEST_MT_response>
    and after mapping my target structure is coming to like this.
    <?xml version="1.0" encoding="UTF-8" ?>
    <ns0:POCA0013_DB_MT xmlns:ns0="urn:pg-com POCA0013:sample">
    <StatmentName>
       <XI_SP_DATA action="EXECUTE">
         <PROJEK isInput="TRUE" type="CHAR">O-USA</PROJEK>
         <KOLLO isInput="TRUE" type="CHAR" >123</KOLLO>
       </XI_SP_DATA>
    </StatmentName>
    <StatmentName>
       <XI_SP_DATA action="EXECUTE">
         <PROJEK isInput="TRUE" type="CHAR">O-Denmark</PROJEK>
         <KOLLO isInput="TRUE" type="CHAR" />256</KOLLO>
       </XI_SP_DATA>
    </StatmentName>
      N number of times
    </ns0:POCA0013_DB_MT>
    this is working perfectly to insert the records into the database by using stored procedure. each record  it call the stored procedure for insert the records, for example we had 100 records and it call 100 times stored procedure.
    But in case of huge data, for example 10000 records, it call the 10000 times to stored procedure.in that case we had a problem for database side.
    we have  one reason to use the stored procedure here, because once insert the data into table, if successful log table is created with successful status , if not log table is created with error status. for that purpose i am using stored procedure here.
    Our customer wants to call the stored procedure for one time for all records.How i can manage this situation.
    Can you give me your valuble ideas about this problem.
    Thank you very much.,
    Sateesh
    Edited by: sateesh kumar .N on Apr 23, 2010 6:53 AM
    Edited by: sateesh kumar .N on Apr 23, 2010 6:54 AM
    Edited by: sateesh kumar .N on Apr 23, 2010 7:54 AM

    Hi Sateesh,
    how about a different approach.
    Add 2 more tables to your solution. The first table is used as a staging table, where PI inserts all the data without making any checks, whatsoever. The second table is used as a control table. If the insertion is finished, a log entry is inserted into this second table, containing the information about success or failure or how many rows had been inserted. Put an insert trigger on this table, which in term starts a stored procedure. This stored procedure can read all the data from the staging table and put it into the desired target tables. Additionally you can perform plausiblitiy checks inside this SP.
    Okay I know, this is a complete new solution in comparison to what you did before. But in my experience, this will be much more performant than 10000 calls to one stored procedure who only does inserts as you described.
    Regards
    Sven

  • Stored Procedure Output Issue in Query Template

    Hi,
    We have written a stored procedure which returns 3 outputs which are of type CLOB. Whenever we call the procedure from query template it gives an error Wrong number or type of parameters. It seems that we need to pass some variables which are of type clob to the procedure while calling which we cannot do as per my knowledge in query template.
    Even if we are able to get the output we will not be getting complete output since the out put values are of type CLOB.
    Can you guide me how to achive this
    Thanks,
    Shalaka

    Hi,
    Sometime back i faced the similar problem. But I used oracle pipelined functions to achieve this....
    The basic thing is it will break the chunk into records of length of 4000 chars and it will return in a table. And from other end you can loop and concatenate. Hope this helps....
    create or replace FUNCTION FN_GEN_XML RETURN dashb_xml pipelined IS v_xml CLOB := NULL;
    v_temp VARCHAR2(4000) := NULL;
    v_counter NUMBER := 1;
    BEGIN
      SELECT somefunction(0)
      INTO v_xml
      FROM dual;--v_xml here is clob type. here you might need to call your proc and get it into this variable.
      dbms_output.put_line ('length of v_xml is:' || length(v_xml));
      DBMS_OUTPUT.PUT_LINE('start of this function');
      LOOP
        v_temp := SUBSTR(v_xml,   v_counter,   4000);
        EXIT
      WHEN v_temp IS NULL;
      DBMS_OUTPUT.PUT_LINE(to_char(v_temp));
      pipe ROW(v_temp);
      v_counter := v_counter + 4000;
    END LOOP;
    RETURN;
    END;
    Regards,
    Ravi Kumar

Maybe you are looking for

  • Omni 10 SD performanc​e

    I ran some benchmarks on the Omni 10's SD performance, and came away disappointed.  Using a Samsung MB-MGCGB 64GB MicroSDHC Pro card and CrystalDiskMark 3.0.3, I got the following results: CrystalDiskMark 3.0.3 (C) 2007-2013 hiyohiyo                 

  • File Receiver Adapter is not writing the file?

    Hi All, I am having a file to file scenario using NFS as both the source and destination are on server. File is getting picked up from server but not reaching the destination. In RWB for Receiver channel it only shows <b>Channel active and started co

  • TDS Entries

    Dear All, Can any one send me the Accounting entries which are generted from Advance Payment  to vendor Invoice and clearing the vendor account transactions. Thanks & Regards, Kumar.D

  • Calling another class from a java program

    I tried to call the Server1.class from the password program, but I failed. The password program source code is as follows: class PasswordDialog extends java.awt.Dialog implements java.awt.event.ActionListener      * Constructor. Create this visual di

  • Is it possible to add a caption on each photo of my album ? Thank u

    Hello, Is it possible to add a caption on each photo of my album Iphoto ? Thank you for your help.