Optimization of CURSORS/SQL inside PL/SQL

Hi Friends
I have a query regarding optimization working with CURSOR FOR loops and embedded SQL stmts inside PL/SQL procedure.
I have a code where i am using a Cursor holding multiple rows and than LOOP over it to process individual rows. I am using nested Cursor FOR Loops too.
I want to know what optimizations are possible in this kind of scenario, where i ahve to process each row of a Cursor.
Kindly Guide....
Thanks and Regards

Hello Friends.....
Thanks so very much for your reply!!
I am attaching my code for your reference. Will also go through the links u have provided.
Kindly, suggest what can be done in this kind of scenario:
CREATE OR REPLACE procedure insert_sfdc_account
as
--DECLARE
CURSOR C1 IS
SELECT customer_code, name1, name2, name3, name4, phone_number, fax, web_address, industry_sector, customer_profile, customer_type,
address, city, postal_code, country_key, zzcust_type, vat_code
FROM load_cust_general
WHERE account_group = 'ZSIT';
v_cust_cur c1%ROWTYPE;
-- type sales_tab is table of load_cust_sales_area%rowtype;
v_sales_area load_cust_sales_area%ROWTYPE;
-- v_sales_area sales_tab;
     v_salesorg varchar2(10);
     v_sales_district varchar2(10);
     v_salesoff varchar2(10);
     v_custgrp varchar2(10);
     v_salesgrp varchar2(10);
v_type varchar2(20);
v_nature varchar2(10);
v_partner_code varchar2(10);
v_parent_cust varchar2(20);
v_credit_blk varchar2(20);
BEGIN
open c1;
loop
fetch c1 into v_cust_cur;
exit when c1%NOTFOUND;
for i in (SELECT customer_code, salesorg from load_cust_partner
where customer_code = v_cust_cur.customer_code ) LOOP
dbms_output.put_line(v_cust_cur.customer_code );
-- BEGIN
                    SELECT partner_code into v_partner_code from load_cust_partner
where customer_code = i.customer_code and salesorg = i.salesorg and partner_function = 'Z1';
dbms_output.put_line(v_partner_code||i.customer_code);
SELECT salesorg, sales_district, salesoff, salesgrp, custgrp INTO v_salesorg, v_sales_district, v_salesoff, v_salesgrp, v_custgrp FROM load_cust_sales_area
          WHERE customer_code = i.customer_code and salesorg = i.salesorg;
               dbms_output.put_line(v_salesorg||i.salesorg);
               dbms_output.put_line('Customer_Code : '|| i.customer_code);
               dbms_output.put_line('SalesOrg : '|| i.salesorg);
     /*     SELECT parent_customer INTO v_parent_cust
from load_cust_hierarchy
WHERE customer_code = '1234'
and salesorg = 'abc'
and hierarchy_type = 'G'; */
                    SELECT parent_customer
INTO v_parent_cust
FROM load_cust_hierarchy
WHERE lower(customer_code) = lower(trim(i.customer_code))
AND lower(salesorg) = lower(trim(i.salesorg))
AND hierarchy_type = 'G';
               /*     SELECT parent_customer INTO v_parent_cust from load_cust_hierarchy
WHERE customer_code = i.customer_code and salesorg = i.salesorg and hierarchy_type = 'G';
dbms_output.put_line(v_parent_cust);
                         dbms_output.put_line('Successfully Executed SQL st. Error is somewhere else');
exception
WHEN NO_DATA_FOUND THEN
v_parent_cust := 'ACHINSUMAN';*/
     --          END;
                    SELECT credit_block INTO v_credit_blk from load_cust_company_cod
          WHERE customer_code = i.customer_code;
dbms_output.put_line(v_credit_blk);
for j in (SELECT account_group, customer_type from load_cust_general
where customer_code IN (select customer_code from load_cust_partner
                              where partner_code = i.customer_code and salesorg = i.salesorg and partner_function = 'ZS'))
                                                  LOOP
-- exit when j%NOTFOUND;
     dbms_output.put_line(j.account_group);
if (j.account_group = 'ZDIS') THEN
v_type := 'DISAC';
          v_nature := '06';
     --     EXIT ;
else
v_type := 'SPACC';
v_nature := '01';
-- ********************* Part to be extended**************
END IF;
dbms_output.put_line(v_type||' '||v_nature);
END LOOP;
INSERT INTO sfdc_account
          (SAP_ACCOUNT_ID__C, NAME, TYPE, RECORDTYPEID, PARENTID, PHONE, FAX, WEBSITE, OWNERID, MARKETING_DOMAIN__C,
INDUSTRIAL_SECTOR__C, ABC_CLASSIFICATION__C, NAME_1__C, NAME_2__C, NAME_3__C, NAME_4__C, PAYMENT_STATUS__C,
CUSTOMER_GROUP__C, ADDRESS_STREET__C, CITY__C, POSTAL_CODE__C, COUNTRY__C, SALES_OFFICE__C, SALESORG__C,
SALESDISTRICT__C, SALESGROUP__C, NATURE__C, VATCODE__C)
VALUES((i.customer_code||i.salesorg), (v_cust_cur.Name1||' '||v_cust_cur.name2), ' ', v_type, v_parent_cust,
v_cust_cur.phone_number, v_cust_cur.fax, v_cust_cur.web_address, v_partner_code, SUBSTR(v_cust_cur.industry_sector,1,2),
v_cust_cur.industry_sector, v_cust_cur.customer_profile, v_cust_cur.name1, v_cust_cur.name2, v_cust_cur.name3,
v_cust_cur.name4, v_credit_blk, v_custgrp, v_cust_cur.address, v_cust_cur.city, v_cust_cur.postal_code,
v_cust_cur.country_key, v_salesoff, v_salesorg, v_sales_district,
v_salesgrp, v_nature, v_cust_cur.vat_code);
end loop;
end loop;
CLOSE c1;
-- Delete data from Load Table
-- EXECUTE IMMEDIATE 'TRUNCATE TABLE load_cust_general';
/* truncate table load_cust_partner;
truncate table load_cust_hierarhy;
truncate table load_cust_sales_area;
truncate table load_cust_company_cod;
commit;
exception
WHEN NO_DATA_FOUND THEN
raise_application_error( -20001, substr( sqlerrm, 1, 150 ) );
when others then
raise_application_error( -20001, substr( sqlerrm, 1, 150 ) );
END;
Thanks and Regards

Similar Messages

  • How to get the Sql inside Omni SQL portlet.

    Hi,
    We are trying to find a table/view which stores/holds the Sql and Pl/Sql code of Omni Pl/sql portlets.
    Thanks,
    Ram.

    by default all sql jobs are executed as sql server agent account, unless otherwise a proxy is setup.
    you can get the proxy information as Olaf mentioned, if the proxy_id is null for the step, it implies that the job step was executed as sql server service account and in such case it will be null
    so, if it is null, it ran as sql server agent account.
    so, one work around is get the sql server agent service account and if the proxy is null, that means it ran as sql server agent account, so, use isnull function. the disadvantage would be if the sql server agent account was switched, you might not get the
    accurate information as the new account will show up though the job really ran as old account, to get this information, you need to  get this from the logmessage column as you mentioned above.
     try this code...
    /*from sql 2008r2 sp1, you get the service accounts using tsql,otherwise you have to query the registry keys*/
    declare @sqlserveragentaccount varchar(2000)
    select @sqlserveragentaccount= service_account
    from sys.dm_server_services
    where servicename like '%sql%server%agent%'
    select message,isnull(name,@sqlserveragentaccount) as AccountName
    from sysjobhistory a inner join sysjobsteps b
    on a.step_id=b.step_id and a.job_id=b.job_id
    left outer join sysproxies c on c.proxy_id=b.proxy_id
    Hope it Helps!!

  • No Data Found: Exception in SQL inside PL/SQL block

    Hi Friends
    I am trying to execute an SQL SELECT stmt inside a PL/SQL block. But when i execute the procedure, it gives me No Data Found Exception.
    I know it is because no row is fetched in the query, but the condition of the SELECT query i have specified is being satisfied, i have checked it by running it on the SQL prompt.
    But somehow, it is not running from inside the PL/SQL procedure.Can anybody help me out on this as to why is this happening?? I am giving my code for reference and have Highlighted the Query inside it:
    CREATE OR REPLACE procedure insert_sfdc_account
    as
    --DECLARE
    CURSOR C1 IS
    SELECT customer_code, name1, name2, name3, name4, phone_number, fax, web_address, industry_sector, customer_profile, customer_type,
    address, city, postal_code, country_key, zzcust_type, vat_code
    FROM load_cust_general
    WHERE account_group = 'ZSIT';
    v_cust_cur c1%ROWTYPE;
    -- type sales_tab is table of load_cust_sales_area%rowtype;
    v_sales_area load_cust_sales_area%ROWTYPE;
    -- v_sales_area sales_tab;
         v_salesorg varchar2(10);
         v_sales_district varchar2(10);
         v_salesoff varchar2(10);
         v_custgrp varchar2(10);
         v_salesgrp varchar2(10);
    v_type varchar2(20);
    v_nature varchar2(10);
    v_partner_code varchar2(10);
    v_parent_cust varchar2(20);
    v_credit_blk varchar2(20);
    BEGIN
    open c1;
    loop
    fetch c1 into v_cust_cur;
    exit when c1%NOTFOUND;
    for i in (SELECT customer_code, salesorg from load_cust_partner
    where customer_code = v_cust_cur.customer_code ) LOOP
    dbms_output.put_line(v_cust_cur.customer_code );
                        SELECT partner_code into v_partner_code from load_cust_partner
    where customer_code = i.customer_code and salesorg = i.salesorg and partner_function = 'Z1';
    dbms_output.put_line(v_partner_code||i.customer_code);
    SELECT salesorg, sales_district, salesoff, salesgrp, custgrp INTO v_salesorg, v_sales_district, v_salesoff, v_salesgrp, v_custgrp FROM load_cust_sales_area
              WHERE customer_code = i.customer_code and salesorg = i.salesorg;
                   dbms_output.put_line(v_salesorg||i.salesorg);
                        SELECT parent_customer INTO v_parent_cust from load_cust_hierarchy
    WHERE customer_code = i.customer_code and salesorg = i.salesorg and hierarchy_type = 'G'; dbms_output.put_line(v_parent_cust);
                        SELECT credit_block INTO v_credit_blk from load_cust_company_cod
              WHERE customer_code = i.customer_code;
    dbms_output.put_line(v_credit_blk);
    for j in (SELECT account_group, customer_type from load_cust_general
    where customer_code IN (select customer_code from load_cust_partner
                                  where partner_code = i.customer_code and salesorg = i.salesorg and partner_function = 'ZS'))
                                                      LOOP
    -- exit when j%NOTFOUND;
         dbms_output.put_line(j.account_group);
    if (j.account_group = 'ZDIS') THEN
    v_type := 'DISAC';
              v_nature := '06';
         --     EXIT ;
    else
    v_type := 'SPACC';
    v_nature := '01';
    END IF;
    dbms_output.put_line(v_type||' '||v_nature);
    END LOOP;
    INSERT INTO sfdc_account
              (SAP_ACCOUNT_ID__C, NAME, TYPE, RECORDTYPEID, PARENTID, PHONE, FAX, WEBSITE, OWNERID, MARKETING_DOMAIN__C,
    INDUSTRIAL_SECTOR__C, ABC_CLASSIFICATION__C, NAME_1__C, NAME_2__C, NAME_3__C, NAME_4__C, PAYMENT_STATUS__C,
    CUSTOMER_GROUP__C, ADDRESS_STREET__C, CITY__C, POSTAL_CODE__C, COUNTRY__C, SALES_OFFICE__C, SALESORG__C,
    SALESDISTRICT__C, SALESGROUP__C, NATURE__C, VATCODE__C)
    VALUES((i.customer_code||i.salesorg), (v_cust_cur.Name1||' '||v_cust_cur.name2), ' ', v_type, v_parent_cust,
    v_cust_cur.phone_number, v_cust_cur.fax, v_cust_cur.web_address, v_partner_code, SUBSTR(v_cust_cur.industry_sector,1,2),
    v_cust_cur.industry_sector, v_cust_cur.customer_profile, v_cust_cur.name1, v_cust_cur.name2, v_cust_cur.name3,
    v_cust_cur.name4, v_credit_blk, v_custgrp, v_cust_cur.address, v_cust_cur.city, v_cust_cur.postal_code,
    v_cust_cur.country_key, v_salesoff, v_salesorg, v_sales_district,
    v_salesgrp, v_nature, v_cust_cur.vat_code);
    end loop;
    end loop;
    CLOSE c1;
    -- Delete data from Load Table
    -- EXECUTE IMMEDIATE 'TRUNCATE TABLE load_cust_general';
    /* truncate table load_cust_partner;
    truncate table load_cust_hierarhy;
    truncate table load_cust_sales_area;
    truncate table load_cust_company_cod;
    commit;
    exception
    when others then
    raise_application_error( -20001, substr( sqlerrm, 1, 150 ) );
    END;
    Kindly Help.....
    Thanks and Regards

    Create the procedure again and execute it in SQL*Plus environment and paste the output:
    CREATE OR REPLACE procedure insert_sfdc_account
    as
    --DECLARE
    CURSOR C1 IS
    SELECT customer_code, name1, name2, name3, name4, phone_number, fax, web_address, industry_sector, customer_profile, customer_type,
    address, city, postal_code, country_key, zzcust_type, vat_code
    FROM load_cust_general
    WHERE account_group = 'ZSIT';
    v_cust_cur c1%ROWTYPE;
    -- type sales_tab is table of load_cust_sales_area%rowtype;
    v_sales_area load_cust_sales_area%ROWTYPE;
    -- v_sales_area sales_tab;
    v_salesorg varchar2(10);
    v_sales_district varchar2(10);
    v_salesoff varchar2(10);
    v_custgrp varchar2(10);
    v_salesgrp varchar2(10);
    v_type varchar2(20);
    v_nature varchar2(10);
    v_partner_code varchar2(10);
    v_parent_cust varchar2(20);
    v_credit_blk varchar2(20);
    BEGIN
    open c1;
    loop
    fetch c1 into v_cust_cur;
    exit when c1%NOTFOUND;
    for i in (SELECT customer_code, salesorg from load_cust_partner
    where customer_code = v_cust_cur.customer_code ) LOOP
    SELECT partner_code into v_partner_code from load_cust_partner
    where customer_code = i.customer_code and salesorg = i.salesorg and partner_function = 'Z1';
    SELECT salesorg, sales_district, salesoff, salesgrp, custgrp INTO v_salesorg, v_sales_district, v_salesoff, v_salesgrp, v_custgrp FROM load_cust_sales_area
    WHERE customer_code = i.customer_code and salesorg = i.salesorg;
    dbms_output.put_line('Customer_Code : '|| i.customer_code);
    dbms_output.put_line('SalesOrg : '|| i.salesorg);
    SELECT parent_customer INTO v_parent_cust from load_cust_hierarchy
    WHERE customer_code = i.customer_code and salesorg = i.salesorg and hierarchy_type = 'G';
    dbms_output.put_line('Successfully Executed SQL st. Error is somewhere else');
    SELECT credit_block INTO v_credit_blk from load_cust_company_cod
    WHERE customer_code = i.customer_code;
    for j in (SELECT account_group, customer_type from load_cust_general
    where customer_code IN (select customer_code from load_cust_partner
    where partner_code = i.customer_code and salesorg = i.salesorg and partner_function = 'ZS'))
    LOOP
    -- exit when j%NOTFOUND;
    if (j.account_group = 'ZDIS') THEN
    v_type := 'DISAC';
    v_nature := '06';
    -- EXIT ;
    else
    v_type := 'SPACC';
    v_nature := '01';
    END IF;
    END LOOP;
    INSERT INTO sfdc_account
    (SAP_ACCOUNT_ID__C, NAME, TYPE, RECORDTYPEID, PARENTID, PHONE, FAX, WEBSITE, OWNERID, MARKETING_DOMAIN__C,
    INDUSTRIAL_SECTOR__C, ABC_CLASSIFICATION__C, NAME_1__C, NAME_2__C, NAME_3__C, NAME_4__C, PAYMENT_STATUS__C,
    CUSTOMER_GROUP__C, ADDRESS_STREET__C, CITY__C, POSTAL_CODE__C, COUNTRY__C, SALES_OFFICE__C, SALESORG__C,
    SALESDISTRICT__C, SALESGROUP__C, NATURE__C, VATCODE__C)
    VALUES((i.customer_code||i.salesorg), (v_cust_cur.Name1||' '||v_cust_cur.name2), ' ', v_type, v_parent_cust,
    v_cust_cur.phone_number, v_cust_cur.fax, v_cust_cur.web_address, v_partner_code, SUBSTR(v_cust_cur.industry_sector,1,2),
    v_cust_cur.industry_sector, v_cust_cur.customer_profile, v_cust_cur.name1, v_cust_cur.name2, v_cust_cur.name3,
    v_cust_cur.name4, v_credit_blk, v_custgrp, v_cust_cur.address, v_cust_cur.city, v_cust_cur.postal_code,
    v_cust_cur.country_key, v_salesoff, v_salesorg, v_sales_district,
    v_salesgrp, v_nature, v_cust_cur.vat_code);
    end loop;
    end loop;
    CLOSE c1;
    -- Delete data from Load Table
    -- EXECUTE IMMEDIATE 'TRUNCATE TABLE load_cust_general';
    /* truncate table load_cust_partner;
    truncate table load_cust_hierarhy;
    truncate table load_cust_sales_area;
    truncate table load_cust_company_cod;
    commit;
    exception
    when others then
    raise_application_error( -20001, substr( sqlerrm, 1, 150 ) );
    END;
    SQL> set serveroutput on
    SQL> exec insert_sfdc_account;

  • Select query inside PL/SQL block.

    Hello Experts,
    I am just a beginner with PL/SQL.
    If I write a select query from client like SQL dev and fire it against a database, it gives me result.
    Eg: select * from employee;
    Now when I use the same Query inside a PL/SQL block suppose:
    Declare
    begin
    select * from employee;
    end;
    This gives error on execution, mentioning that an INTO is expected etc...
    I have doubts here:
    1. Can't I use a plain select inside a PL/SQL block (if so why?)
    I know this is kind of very basic question, I tried searching this on the forum but could not find the thread, please redirect me to the link if this is already answered.

    user8578271 wrote:
    Hello Experts,
    I am just a beginner with PL/SQL.
    If I write a select query from client like SQL dev and fire it against a database, it gives me result.
    Eg: select * from employee;
    Now when I use the same Query inside a PL/SQL block suppose:
    Declare
    begin
    select * from employee;
    end;
    This gives error on execution, mentioning that an INTO is expected etc...
    I have doubts here:
    1. Can't I use a plain select inside a PL/SQL block (if so why?) Because when you run a query in a tool like SQL Developer, or SQL*Plus or TOAD etc. then it opens up a cursor and fetches the data into internal memory structures before displaying it, and that is all done automatically and hidden from you. In PL/SQL, there is no interface to display the results of SQL queries, so you have to specifically tell it what to put the data into.
    The syntax is (in basic terms)...
    SELECT column1, column2... columnX
    INTO variables or record structure
    FROM ...Though that can only select a single row of data. If your query returns more than 1 row it will give a TOO_MANY_ROWS exception. If your query returns no rows you will get a NO_DATA_FOUND exception.
    If you need to select multiple rows into variables etc., then you would need to "BULK COLLECT" into a collection/array structure, though this takes up valuable memory on the server and shouldn't be used unless necessary (and you understand the implications of doing it).

  • Create a cursor from a PL/SQL variable or an external file

    Dear friends,
    is there a way for me to make Oracle Forms read a cursor from a PL/SQL variable, or an external file? Let's suppose we have the code below:
    DECLARE
    cursor c_values is select * from my_table;
    r_values c_values%ROWTYPE;
    BEGIN
    for r_values in c_values loop
    do_something;
    end loop;
    END;
    In the situation described above, could I create "select * from my_table" from a PL/SQL variable (it could be something like p_cursor = 'select * from my_table'), or an external file - for example, make my form read the contents of c:\my_select.sql , where we see the "select * from my table" text?
    My question comes because I need to export data from select instructions that were dinamically created inside the form - that is, via PL/SQL -, and I don't want to rewrite it, but I'll have to do it if I have no choice. Your help will be greatly appreciated.
    Best regards,
    Franklin
    Edited by: franklinbrasil on 12/03/2009 11:33
    Edited by: franklinbrasil on 12/03/2009 11:35

    Dear friends,
    I am using DBMS_SQL package, which solved my problem. Please let me explain it better, if it's not clear.
    I have some PL/SQL blocks inside my form, which creates SQL queries dinamically, and a dinamically created SQL is stored into a VARCHAR2 variable. These SQL queries are exported for use in Oracle Graphics, but since OG is not being developed by Oracle anymore then I am trying to find a substitute for it.
    So I thought about creating an option for the final user: he/she can choose exporting data into Microsoft Excel, and user does what he/she wants, creating a customized graphic. Exporting into Excel works finely, with no problems at all - I could find a routine by searching on the web.
    My goal was to use the same queries created above to export data dinamically to Microsoft Excel, and I absolutely don't want to rewrite all these dinamically created queries - one which works dinamically, other with no flexibility inside my form. Worse than it, I have many other dinamically created queries, and I obviously don't want to rewrite them all - any maintenance in this form would be terrible, with each SQL instruction written twice.
    Since all dinamically created SQL instructions are stored inside a VARCHAR2 variable, I thought about reusing the same SQL, as explained above - and here we have your suggestions about using a ref cursor, execute immediate, and so on. And (answering Andreas) query structure is always based on the same table, but its structure changes a lot, depending on what the final user chooses in a drop-down list (it's a list of graphics options, where final user chooses one option, and form must mount SQL dinamically, based on user's choice).
    By using your explanations, I could find DBMS_SQL solution here: http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96590/adg09dyn.htm#26799
    . Please notice that I had to change DBMS_SQL.native into 1 for it to work in my form. I'll mark all your answers as helpful because I can use them both for database and form purposes.
    If my message was not clear enough, please tell me and I'll try to make it more clear.
    Best regards,
    Franklin

  • I cant get Fourth Elephant (Insider for SQL Developer)

    hi,guys
    please, help me.
    I want to user insider for sql developer of fourth elephant.
    but I cant access
    http://fourthelephant.com/sqldeveloper/download/
    who used it?
    thanks.

    yes, I see
    I want to know someone downloaded it.
    can anyone share it?

  • XSU  and CURSOR expression in the sql query

    Platform: oracle 8.X on ibm aix and java client code from
    windows NT.
    JDBC DRIVER: JDBC Oracle thin driver version 1.2.
    when i execute a Sql satement with Cursor expression from the
    java client code with XSU it returns an XML DOM But if the
    CURSOR EXPRESSION IN THE SQL QUERY RETURNS EMPTY ROWS i get
    back an error node with "ORA-01001 Invalid Cursor" error
    message.i had aslo set the setNullAttributes(true) property
    on oraclexmlquery.
    Interestingly, if i exceute the same query in the SQL plus
    it returns the column names with no rows.
    is there any way where i can get xml document with table
    structure, when there are no rows instead of ORA error message.

    Ok.
    I assume that you have for one activity several asset PNR and for one asset several activity.
    The factPNR is on this way a real bridge table. It's a way to be able to design a many-to-many relationship.
    Have a look here for more detail on how to build a many-to-many relationship :
    http://gerardnico.com/wiki/dw/data_quality/relationships#many-to-many
    Therefore I assume that you want this design :
    DimActivity -< FactActivity >- < FactPNR >- DimPNR  and you will have :
    DimActivity -< FactActivity >- < BridgeTable >- DimPNR  How to build your bridge table ?
    In the physical layer, :
    * create a new table BridgeActivityPNR, open it and select "statement"
    * enter your sql statement
    SELECT DISTINCT A.ROW_WID ACTIVIDAD_WID, B.ROW_WID ASSET_WID
    FROM W_ACTIVITY_F A,
    W_ASSET_D B,
    W_SRVREQ_D C,
    X_S_CMPT_MTRC_F D,
    X_S_ASSET_FEA_D E
    WHERE A.X_SRA_SR_ID=C.INTEGRATION_ID AND
    C.X_VLG_FLIGHT_ID=D.X_ROW_ID AND
    D.X_ROW_ID=E.X_CM_ID AND
    E.X_ASSET_ID=B.X_ROW_ID* add two columns in the column tab : ACTIVIDAD_WID and ASSET_WID
    * create the physical join with the table FactActivity and DimPNR
    * drag and drop in the business model your table BridgeActivityPNR
    * in the BMM, create the complex join like this :
    DimActivity -< FactActivity >- < BridgeTable >- DimPNR  * open your logical bridge table and check the bridge table option.
    And you are done if I didn't forget anything.
    A complete example here :
    http://gerardnico.com/wiki/dat/obiee/obiee_bridge_table

  • Calling a package function inside a sql

    Hi friends!!!
    First of all happy Christmas! And them please help! :)
    We have a query calling a package function:
    SELECT * FROM DW025H WHERE DW025H_NR=MPPCI.ENCR ('0000000000000000');There is a primary key just with one column DW025H_NR and the problem is that is not accessing by INDEX UNIQUE SCAN,
    it's accessing by TABLE ACCESS FULL.
    May be the problem is that we are calling a procedure inside the query?
    I have been able to run that query accessing by primary key from my computer but a workmate hasn't!
    We both are connecting the same data base 10.2.0.4 and using Oracle SQL Developer!
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 5343K| 1406M| 15670 (7)| 00:02:43 |
    |* 1 | VIEW | DW025H | 5343K| 1406M| 15670 (7)| 00:02:43 |
    |* 2 | FILTER | | | | | |
    | 3 | TABLE ACCESS FULL| DW025H | 5343K| 1406M| 15670 (7)| 00:02:43 |
    Predicate Information (identified by operation id):
    1 - filter("DW025H_NR"="MPPCI"."ENCRIPTAPAN"('0000000000000000'))
    2 - filter(CASE "OPS$SISINFO"."IS_USER_DNI"() WHEN 1 THEN
    SYS_AUDIT('OPS$SISINFO','DW025H','CMINFOGR001',3) ELSE NULL END IS
    NULL)
    The correct path would be:
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 276 | 3 (0)| 00:00:01 |
    |* 1 | FILTER | | | | | |
    | 2 | TABLE ACCESS BY INDEX ROWID| DW025H | 1 | 276 | 3 (0)| 00:00:01 |
    |* 3 | INDEX UNIQUE SCAN | PK_DW025H | 1 | | 2 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    1 - filter(CASE "OPS$SISINFO"."IS_USER_DNI"() WHEN 1 THEN
    SYS_AUDIT('OPS$SISINFO','DW025H ','CMINFOGR001',3) ELSE NULL END IS NULL)
    3 - access("DW025H_NR"="MPPCI"."ENCR"('0000000000000000'))
    Please any ideas!?!?!
    Thanks a lot!
    José
    Edited by: jamv on Dec 20, 2011 10:50 AM

    Hello
    Have a read of this and try to pull together the information in it and post it up here. That will help immensely with getting to the root of your problem...
    HOW TO: Post a SQL statement tuning request - template posting
    In the mean time:
    From the execution plan you have extra predicates that aren't present in the query you supplied, so that's either not the SQL or you have something like VPD switched on.
    Anyway, there could be lots of reasons for the difference in execution plan. Sorry if this is very basic and possibly patronising question but it's always worth checking the basics I think - are you both definitely connecting to the same database? If so, have a look in v$sqlarea for this SQL statement and find the SQL_ID, use this to query v$sql and look at the child_number column.
    select
        sql_id
    from
        v$sqlarea
    where
        sql_text like '%SELECT * FROM DW025H WHERE DW025H_NR=MPPCI.ENCR%(''0000000000000000'')%'
    and
        sql_text not like '%v$sqlarea%'
    select child_number from v$sql where sql_id='<enter the sql id returned by the query above>'as an example...
    XXXX> select /* my sql statement*/ rownum id from dual;
            ID
             1
    1 row selected.
    Elapsed: 00:00:00.10
    XXXX> select sql_id from v$sqlarea where sql_text like '%my sql statement%'
    and sql_text not like '%v$sqlarea%';
    SQL_ID
    a6ss4v79udz6g
    1 row selected.
    Elapsed: 00:00:03.56
    XXXX> select child_number from v$sql where sql_id='a6ss4v79udz6g'
      2  /
    CHILD_NUMBER
               0
    1 row selected.   If you have more than one row in v$sql there could be differences in the optimiser environment. The supplied like shows you how to gather the information that should help find what the differences are if any.
    Also as a side note if you're calling PL/SQL functions from SQL, you can take advantage of subquery caching to help reduce the number of calls (depending on your version). As it stands, your function is most likely going to be called for every row - when there is only a single row returned, that's not necessarily a problem but for multiple rows, the overhead can quickly grow. If there's no way to get rid of the function call, select the function from dual instead i.e.
    SELECT * FROM DW025H WHERE DW025H_NR= (SELECT MPPCI.ENCR%('0000000000000000') FROM dual);This also (as I learnt a couple of weeks ago) works when you're using columns in the table your selecting from as parameters to the function.
    HTH
    David

  • Dynamic cursor definition in PL/SQL

    Is it possible to have dynamic cursor definition in PL/SQL. Like
    using DBMS_SQL for dynamic SQL. If yes, how?

    Assuming I understand your question correctly, you can use a REF
    CURSOR to which you associate a VARCHAR2 which is the query text:
    DECLARE
    TYPE t_cur IS REF CURSOR ; -- define t_cur as a type
    c_cur t_cur ; -- define an actual variable of type t_cur
    r_emp emp%ROWTYPE ; -- PL/SQL record to hold row
    v_query VARCHAR2(2000) := 'SELECT * FROM emp' ; -- the query!
    BEGIN
    OPEN c_cur FOR v_query ; -- v_query could contain any valid query
    FETCH c_cur INTO r_emp ; -- get first row from dataset
    CLOSE c_cur ; -- remember to close the cursor! ;)
    END ;
    HTH

  • Can i use a environment variable inside a *.sql file?

    Hello,
    I want to create a external table.
    So i am using the command
    create or replace directory abc as 'C:\folder'.... inside a sql file.
    Now i want the path "C:\folder" to be dynamic as i am using this path in many other places also inside the sql file.So i thought to create a environment variable and put this value there.I tried using as %PATH% but it gives error..... where %PATH%=C:\folder.
    Can i use a environment variable inside a *.sql file?
    But how to do that or is there any other way.
    Thanks
    Swapna
    Edited by: user11018268 on Feb 19, 2010 1:03 AM

    user11018268 wrote:
    Actually what i want is the path "C:\folder" is not fixed it can be anything which i may not know the user may decide it later. Not supported. A directory object refers to a specific physical location (directory/folder) on a file system. Not a path.
    You can work around it by (creating and) using a function (running under a super user schema with authid definer privs). The caller (e.g. schema scott ) calls it with a physical path. E.g. GetDirectoryObject( 'C:\folder\2010\feb\week4' ).
    This function determines if there is an existing directory object for the path. If not, it uses a wildcard search to determine if there are any directory objects for parents in the path (e.g. for C:\folder\2010\feb or C:\folder\2010 or C:\folder ).
    If it finds a directory object, it interrogates the data dictionary to determine if the caller, schema scott for example, has read/write access on that directory object. If it has, it creates a new directory object and grants the caller read/write access to it. The function then returns the name of the directory object to the caller.
    The caller thus do not deal directly with directory objects. The function returns the object name given a physical path as input. Also, only a single base directory needs to be created (e.g. for C:\folder ) and access granted to the schema on it. Any sub-directory in that base directory can now be dynamically accessed by the schema.

  • Select statements inside a SQL Expression field

    Hello
    Why cannot we use the Select statements inside a SQL expression field in Crystal Reports ?
    Any alternatives for this...
    SELECT Top(1) "SomePrivateDatabase"."SPDname" FROM "SomePrivateDatabase"
    inner join "Subscriber" on
    "Subscriber"."SPDID" = "SomePrivateDatabase"."SPDID"
    inner join "UserDetails" on
    "UserDetails"."SPDID" = "SubscriberCore"."SPDID"
    Regards
    Srivatsa
    Edited by: Srivatsa Haridas on Dec 3, 2008 12:17 PM

    Hi Srivatsa,
    SQL Expressions is something the Database supports. We query the Client engine for a list of functions they make available. If the SQL Statement is not list it's not an option and therefore it won't work.
    Your work arounds are to use either a Stored Procedure, this is the most efficient way, all processing is done server side and CR simply waits for the data to format in the report. Another option is to use a
    Command Object, use one CO per report so try to get all data within the SQL statement. We simply pass the SQL to the server and wait for the result set, if you get an error it will be the SQL you typed in. Test in a SQL test tool first to confirm you are getting the data correctly.
    For more assistance in designing reports please post your report deisgn questions to the Reprot Design forums. I am moving this one to that queue.
    Thank you
    Don

  • Autocommit inside one SQL command

    Hi,
    I have 2 tables A and B each have two columns id and name. I used "update A set A.name = (Select B.name from B where A.id=B.id)" to update table A's name. However, when both tables are very large( say 5M rows), Since Oracle will commit only after a command, so, the DB will hold the 5M rows in the rollback segments, if the rollback segments are not large enough, the updating will be very slow. Is there any way to let Oracle commit inside one SQL command? For exemple, auto commit after every 10000 rows get updated.
    Thanks.

    Thanks for your comments. We have done some tests:
    1. We used a flag to limit the number of rows for updating in 2000, 5000, 10000 and 50000 rows. We found that the time/rows in 2000 rows was much lower than in 50000 rows. The higher the testing rows, the higher time/rows was.
    2. We used single SQL (update ... select .. from) command to update whole table vs used one select SQL and a seperate update SQL to update table A one record by one record using Java. I thought first one should be much fast than second one. But there were not big diferrence.
    Do you have any ideal for tuning this DML?
    Thanks.

  • CFIF inside a SQL statment

    I have a search page that has 3 possible entries. Service,
    City, & Keywords.
    Service and City are list/menus and cannot be null, but
    Keywords is a text
    box and can be null.
    I need to write a SQL statement to take the 3 possible
    parameters and test
    them against the database. Since the first 2 are never null,
    I can write
    them right inside the SQL string, but how can I only check
    for the keywords
    if there is something inside the box?
    Can I use a <cfif> statement inside the sql string to
    only check the 3rd
    parameter if it is not NULL?
    I wrote this:
    Select company, name, phone, city, state, username FROM
    members WHERE
    city = Form.City AND state = Form.state AND keywords LIKE
    Form.keywords
    ORDER BY company ASC
    Also, since I am passing it from a search page to a results
    page, would it
    be URL.City verses FORM.City, etc.
    Also would like to do this in a component and pass the 3
    variables as
    arguments with the city and service being required and the
    keywords not.
    However, I have no idea on what the procedure is for this.
    I wrote:
    <cfcomponent>
    <cffunction name="ServiceSearch" access="remote"
    returntype="query">
    <cfargument name="service" type="numeric"
    required="true">
    <cfargument name="city" type="numeric"
    required="true">
    <cfargument name="keywords" type="string"
    required="false">
    Select company, name, phone, city, state, username FROM
    members WHERE
    city = Form.City AND state = Form.state AND keywords LIKE
    Form.keywords
    ORDER BY company ASC
    <cfreturn ServiceResults>
    </cffunction>
    </cfcomponent>
    Do I invoke the component from the results page?
    Well, I need to solve the first issue before I attempt the
    second. Thanks!
    Wally Kolcz
    Developer / Support
    ProjectProofing.com

    Yes you can put <cfif ...> statements inside a
    <cfquery...> tag to
    modify the SQL string.
    WHERE this = that AND
    <cfif len(trim(form.something))>
    AnotherThing = '#form.something#'
    </cfif>
    Is valid.
    Whether the form variables on the action page are URL or FORM
    depends on
    the method of your <form ...> tag. method="post"
    creates form variables
    on the action page, method="get" creates URL variables on the
    action page.
    You write <cfargument ...> tags for each argument you
    want to pass into
    a function.
    <cfargument name="city" required="true" ...>
    OR
    <cfargument name="foobar" required="false" default=""
    ...>
    You then use these in the function with the arguments scope.
    #arguments.city# and #arguments.foobar#
    You then pass these into the function from your calling page.
    There are
    numerous ways this can be done, here are a few.
    <cfinvoke .... city="Sacramento" foobar="george"/>
    <finvoke ... >
    <cfinvokeArgument name="city" value="Sacramento">
    <cfinvokeArgument name="foobar" value="george">
    </cfinvoke>
    <cfset myComponent =
    createObject("component","my.component.path.andName)>
    ...myComponent.aFunction("Sacramento","george")...
    ...myComponent.aFunction(city:"Sacrament",foobar:"george")...o
    Wally Kolcz wrote:
    > I have a search page that has 3 possible entries.
    Service, City, & Keywords.
    >
    > Service and City are list/menus and cannot be null, but
    Keywords is a text
    > box and can be null.
    >
    > I need to write a SQL statement to take the 3 possible
    parameters and test
    > them against the database. Since the first 2 are never
    null, I can write
    > them right inside the SQL string, but how can I only
    check for the keywords
    > if there is something inside the box?
    >
    > Can I use a <cfif> statement inside the sql string
    to only check the 3rd
    > parameter if it is not NULL?
    >
    > I wrote this:
    >
    > Select company, name, phone, city, state, username FROM
    members WHERE
    > city = Form.City AND state = Form.state AND keywords
    LIKE Form.keywords
    > ORDER BY company ASC
    >
    > Also, since I am passing it from a search page to a
    results page, would it
    > be URL.City verses FORM.City, etc.
    >
    > Also would like to do this in a component and pass the 3
    variables as
    > arguments with the city and service being required and
    the keywords not.
    > However, I have no idea on what the procedure is for
    this.
    >
    > I wrote:
    > <cfcomponent>
    > <cffunction name="ServiceSearch" access="remote"
    returntype="query">
    > <cfargument name="service" type="numeric"
    required="true">
    > <cfargument name="city" type="numeric"
    required="true">
    > <cfargument name="keywords" type="string"
    required="false">
    > Select company, name, phone, city, state, username FROM
    members WHERE
    > city = Form.City AND state = Form.state AND keywords
    LIKE Form.keywords
    > ORDER BY company ASC
    > <cfreturn ServiceResults>
    > </cffunction>
    > </cfcomponent>
    >
    > Do I invoke the component from the results page?
    >
    > Well, I need to solve the first issue before I attempt
    the second. Thanks!
    >

  • Viewing table relations inside Oracle SQL Developer

    Hi,
    I'm a PL/SQL beginner and I need to control the table relations for an Oracle database. I'm using the Oracle SQL developer tool.
    Now, how can I see the table relation inside Oracle SQL developer tool?
    Thanks

    itshak wrote:
    When working with tables based on user defined types, the FK relations between the tables are not displayed at the data modeler (and also at the worksheet query builder)
    I don't think that applies here 1041141 mentioned he is a beginner and did not mention any usage of object types.
    If you want to report an issue or possible bug, then please open an extra thread for that. In such a case it helps tremendously if you provide a working test case as well.

  • Creating an OLAP cursor with a dynamic SQL

    The create sql cursor command
    SQL declare cursor_name cursor for Select col_name from table_name does not take a dynamic sql.
    Is there a way to execute a sql dynamically like
    SQL declare cursor_name cursor for 'Select col_name from table_name'
    I tried using the prepare statement command but i could not get the statement execution to the cursor. I am working on Oracle OLAP version 9.2.0.5.0
    Thanks in advance
    Ajesh A

    One method I'm familiar with is OPEN...FOR. You can do something like this (untested but should be close in any case):
    DECLARE
      tabname VARCHAR2(100) := 'mytable';
      colaval VARCHAR2(100);
      colbval VARCHAR2(100);
      colcval VARCHAR2(100) := 'somesearchval';
      TYPE MyCurTyp IS REF CURSOR;
      my_cur MyCurTyp;
    BEGIN
      OPEN my_cur
        FOR 'SELECT cola, colb FROM ' || tabname || ' WHERE colc=:1'
        USING colcval;
      LOOP
        FETCH my_cur INTO colaval, colvbal;
        EXIT WHEN my_cur%NOTFOUND;
        DBMS_OUTPUT.PUTLINE('cola: ' || colaval || ' colb: ' || colbval);
      END LOOP;
    END;
    /The PL/SQL User's Guide is invaluable when working in PL/SQL. Here's the section on ref cursors:
    http://download-east.oracle.com/docs/cd/B19306_01/appdev.102/b14261/sqloperations.htm#sthref1392
    For problems not covered by the documentation, you may find that for general SQL and PL/SQL programming advice not specifically related to OLAP that there will be more knowledge in some of the more general forums here.

Maybe you are looking for

  • Unable to convert the sender service BS_PARTNER to an ALE logical system..!

    Hi All, File to IDoc scenario. 1. Business system is correct because its working for other scenarios. 2. I checked Adapter Specific attributes in Business service and given Partner number which in maintained in WE20 for the partner in R/3. 3. Refresh

  • Datagram socket and security manager

    I have subclassed the security manager to implement my own network security rules. However when the receive(datagramPacket) method is called by the my datagram socket, the host parameter passed to the checkAccept(host, port) method does not belong to

  • When my pc boots, how can I get Firefox to open automatically?

    When my pc boots I would like Firefox to open automatically at my home page without intervention from me. Is it possible? XP Professional. SP3.

  • I can't click and drag anymore . . .

    and I think this might be an AppleScript problem? When I click on icons I can't drag them anywhere. I've shut down and started, restarted, and logged out and logged back in, and nothing has worked. A day or two ago, I got an error message about Apple

  • How to make published calendar show month view by default?

    I have a published calendar that I put into an iframe on a website. Unfortunately, it comes up in week view by default. I know that if you click on month view, it gives you a new URL that you could copy and use, but that URL is specific to a month an