Please help on PL/SQL

Please help me to this PL/SQL command. I want to count(*) from table i got on DEVCHG.REFRESH_TBL_LIST.
declare
cnt NUMBER;
begin
for tbl in (
     select table_name from DEVCHG.REFRESH_TBL_LIST
loop
     select count(*) into cnt from tbl;
     DBMS_OUTPUT.PUT_LINE(tbl.table_name||':'||cnt);
end loop;
end;
/

Hi, try this PL/SQL block. I hope your problem will resolved by this. Revert back with query if any....
set serveroutput on
declare
cnt NUMBER;
begin
select count(*) into cnt from DEVCHG.REFRESH_TBL_LIST;
IF SQL%FOUND THEN
DBMS_OUTPUT.PUT_LINE('Total count of table is ' || cnt);
ELSE
DBMS_OUTPUT.PUT_LINE('No record found');
END IF;
end;
/

Similar Messages

  • Please help with an sql to show more than one records into single row for each student

    From the following data I would like to create an sql to get the information  as the following layout
    studentid,  firstTerm,  EnglishMark1,ScienceMark1,MathsMark1, Secondterm,EnglishMark2,ScienceMark2,MathsMark2,
    ThirdTerm,EnglishMark3,ScienceMark3,MathsMark3 // As single rows for each student
    Example
    1 First, 30,40,20,Sec,30,40,20,  simillarly next row for next row for another sudent. Please help to generate the sql for the same.
    Please help it would be very appreciate.
    With Thanks
    Pol
    polachan

    create table yourdata (studentid int, term varchar(10), section varchar(50), Mark int)
    insert into yourdata values
    (1,'First','Math',20),(1,'First','English',30),(1,'First','Science',40),
    (2,'First','Math',20),(2,'First','English',30),(2,'First','Science',40),
    (3,'First','Math',20),(3,'First','English',30),(3,'First','Science',40),
    (1,'Sec','Math',20),(1,'Sec','English',30),(1,'Sec','Science',40),
    (2,'Sec','Math',20),(2,'Sec','English',30),(2,'Sec','Science',40),
    (3,'Sec','Math',20),(3,'Sec','English',30),(3,'Sec','Science',40)
    Select studentid
    ,max(case when term='First' and section='English' Then Mark End) as EnglishMark1
    ,max(case when term='First' and section='Science' Then Mark End) as ScienceMark1
    ,max(case when term='First' and section='Math' Then Mark End) as MathMark1
    ,max(case when term='Sec' and section='English' Then Mark End) as EnglishMark2
    ,max(case when term='Sec' and section='Science' Then Mark End) as ScienceMark2
    ,max(case when term='Sec' and section='Math' Then Mark End) as MathMark2
    ,max(case when term='Third' and section='English' Then Mark End) as EnglishMark3
    ,max(case when term='Third' and section='Science' Then Mark End) as ScienceMark3
    ,max(case when term='Third' and section='Math' Then Mark End) as MathMark3
    From yourdata
    Group by studentid
    drop table yourdata

  • Please help: WebLogic + BI + SQL Group Authenticator

    Hi all, i have big problem with solution on my company project. I please somebody help me.
    This is my problem:
    I have bifoundation_domain :
    WebLogic Server Version: 10.3.5.0
    EM 11g
    Oracle Business Intelligence 11.1.1.7.0
    with this structure:
    bifoundation_domain
    |- AdminServer
    |- bi_cluster
      |- bi_server1
    So and i need use Weblogic embedded LDAP (DefaultAuthenticator in realms security providers) and i need loading GROUPS from DATABASE. I read and tried a lot of articles, blogs, manuals but
    within positive result.
    My procedure is:
    In WLS console :
    - create jdbc datasource with name "bip_apps_DS"
    - create BI SQL Group provider (with name BIGroupLoader) with this settings
    <sec:authentication-provider xmlns:ext="http://xmlns.oracle.com/weblogic/security/extension" xsi:type="ext:bisql-group-providerType">
      <sec:name>BIGroupLoader</sec:name>
      <sec:control-flag>OPTIONAL</sec:control-flag>
      <ext:data-source-jndi-name>bip_apps_DS</ext:data-source-jndi-name>
      <ext:sql-list-member-groups>SELECT ROLE_NAME FROM V_SYS_AUTH_ROLES WHERE LOGIN_NAME = ?</ext:sql-list-member-groups>
      <ext:sql-list-groups>SELECT NAME FROM UA_ROLES WHERE NAME LIKE ?</ext:sql-list-groups>
      <ext:sql-group-exists>SELECT NAME FROM UA_ROLES WHERE NAME = ?</ext:sql-group-exists>
      <ext:sql-is-member>SELECT LOGIN_NAME FROM V_SYS_AUTH_ROLES WHERE ROLE_NAME = ? AND LOGIN_NAME = ?</ext:sql-is-member>
      <ext:sql-get-group-description>SELECT DESCRIPTION FROM UA_ROLES WHERE NAME = ?</ext:sql-get-group-description>
    </sec:authentication-provider>
    (my DB schema is correct)
    and i move him on first place in providers list.
    So after these steps in WLS console i see in security realm->groups my groups from DB. Everything is OK.
    Now i need use GROUPS from my database in EM in the context of create BI users roles (maping BI application roles on GROUPS (enterprise roles)).
    So i created a database adapter for the Virtualized Identity Store
    this is it:
    <?xml version = '1.0' encoding = 'UTF-8'?>
    <adapters schvers="303" version="1" xmlns="http://www.octetstring.com/schemas/Adapters" xmlns:adapters="http://www.w3.org/2001/XMLSchema-instance">
      <dataBase id="directoryType" version="0">
      <root>%ROOT%</root>
      <active>true</active>
      <serverType>directoryType</serverType>
      <routing>
      <critical>true</critical>
      <priority>50</priority>
      <inclusionFilter/>
      <exclusionFilter/>
      <plugin/>
      <retrieve/>
      <store/>
      <visible>Yes</visible>
      <levels>-1</levels>
      <bind>true</bind>
      <bind-adapters/>
      <views/>
      <dnpattern/>
      </routing>
      <pluginChains xmlns="http://xmlns.oracle.com/iam/management/ovd/config/plugins">
      <plugins>
      <plugin>
      <name>VirtualAttribute</name>
      <class>oracle.ods.virtualization.engine.chain.plugins.virtualattr.VirtualAttributePlugin</class>
      <initParams>
      <param name="ReplaceAttribute" value="uniqueMember={cn=%uniquemember%,ou=people,ou=myrealm,dc=bifoundation_domain}"/>
      </initParams>
      </plugin>
      </plugins>
      <default>
      <plugin name="VirtualAttribute"/>
      </default>
      <add/>
      <bind/>
      <delete/>
      <get/>
      <modify/>
      <rename/>
      </pluginChains>
      <driver>oracle.jdbc.driver.OracleDriver</driver>
      <url>%URL%</url>
      <user>%USER%</user>
      <password>%PASSWORD%</password>
      <ignoreObjectClassOnModify>false</ignoreObjectClassOnModify>
      <includeInheritedObjectClasses>true</includeInheritedObjectClasses>
      <maxConnections>10</maxConnections>
      <mapping>
      <joins/>
      <objectClass name="groupofuniquenames" rdn="cn">
      <attribute ldap="cn" table="V_SYS_AUTH_ROLES" field="ROLE_NAME" type=""/>
      <attribute ldap="description" table="V_SYS_AUTH_ROLES" field="ROLE_NAME" type=""/>
      <attribute ldap="uniquemember" table="V_SYS_AUTH_ROLES" field="LOGIN_NAME" type=""/>
      </objectClass>
      </mapping>
      <useCaseInsensitiveSearch>true</useCaseInsensitiveSearch>
      <connectionWaitTimeout>10</connectionWaitTimeout>
      <oracleNetConnectTimeout>0</oracleNetConnectTimeout>
      <validateConnection>false</validateConnection>
      </dataBase>
    </adapters>
    and run command to register:
    ./libovdadapterconfig.sh -adapterName BIGroupLoader -adapterTemplate bi_sql_groups_adapter_template.xml
    -host localhost -port 7001 -userName weblogic -domainPath /OFM/BI/user_projects/domains/bifoundation_domain
    -dataStore DB -root ou=people,ou=myrealm,dc=bifoundation_domain -contextName default -dataSourceJNDIName bip_apps_DS
    Adapter is creatted successfully within errors!
    I restarted managed server(bi_server1) and AdminServer, all bi commponets etc. BUT WITHOUT RESULT. I still dont see GROUPS in Enterprise manager in
    BI->coreapplication->security->application roles
    I tried set in security setting of webLogic domain in EM virtualize=true.
    This procedure is described on all sites but not funkcionaly for me. Do you know somebody where is mistake? Etc. need i installing OVD server? I dont know. Please helm me. after 10 days i really hopeless :( ..so sorry for my english

    If you are still looking for sol? send me email  [email protected]

  • Please help with PL/SQL

    Hi All,
    This is driving me nuts but I can't see what I am doing wrong....
    I have a simple PL/SQL with :
    DECLARE
    xxx NUMBER;
    BEGIN
    FOR z in 1..htmldb_application.g_f02.count loop
    xxx:=htmldb_application.g_f02(z);
    select task_id into present_task from dm_process_steps where process_id=:P34_ID AND task_id = xxx;
    htp.p(xxx);
    IF htmldb_application.g_f02(z) = present_task THEN
    htp.p('PRESENT');
    ELSE
    htp.p('NOT PRESENT');
    END IF;
    END;
    The above fails with:
    ORA-01403: no data found
    However if I replace the marked xxx with the number then the code works fine.
    I do not understand the reason for this since I know that xxx has in fact a value and the select should be valid!
    Kindly asking for any help on this!
    Pawel.

    Scott,
    This will probably be a quite extended but I'll try to make it as clear as possible. I took a different approach to find the element which is causing the problem.
    I have 2 TABLES defined as:
    DM_PROCESS_STEPS
    ID Number
    PROCESS_ID Number
    TASK_ID Number
    TASK_ORDER Number
    DM_TASKS
    TASK_ID Number
    TASK_TITLE Varchar2
    ...and some more columns ...
    On the page I have a PL/SQL Region with:
    DHTML_SHUTTLE (
    pSQL_1=>'select "TASK_TITLE","TASK_ID" from "DM_TASKS"',
    pSQL_2=>'select t.task_title, p.task_id from dm_tasks t,dm_process_steps p where t.task_id = p.task_id and process_id = :P34_ID order by p.task_order',
    pID_1=>'1',
    pID_2=>'2',
    pSort1=>'N',
    pSort2=>'Y',
    pFixed1=>'Y',
    pHeight=>'300',
    pWidth=>'400',
    pImagePrefix=>v('WORKSPACE_IMAGES')
    NOTE: All above code comes from a working shuttle_sample code. The only things I modified were pSQL_1 and pSQL_2
    - In this case I want to have "All available tasks in the first list"
    - Since the syntax for pSQL_2 item must return two columns I wrote a joined queary so that I can see the Task_Title on the second list although this column doesn't directly come from DM_PROCESS_STEPS.
    I also have a After Submit Process which is fired upon pressing an apply button:
    DECLARE
    BEGIN
    -- Clean the Tasks from current Process --
    delete from dump where process_id = :P34_ID;
    -- Populate the Process with new list
    FOR z in 1..htmldb_application.g_f02.count loop
    INSERT INTO DUMP
    (ID,TASK_ID,PROCESS_ID,TASK_ORDER)
    VALUES (DM_PROCESS_STEPS_SEQ.nextval,htmldb_application.g_f02(z),:P34_ID,z);
    END LOOP;
    END;
    Now, the problem is with htmldb_application.g_f02(z) element. If understand correctly (please verify this!) the value of this element is whatever the pSQL_2 returns in the second column. In this case, htmldb_application.g_f02(z) returns the Task_Id.
    However, when I view the contents of the DM_PROCESS_STEPS table I can see that the first row (or rows) contain PROCESS_ID under TASK_ID column !!! This is were I am most confused as I cannot figure out were these htmldb_application.g_f02(z) come from !!!
    For example:
    1. I am trying to edit tasks for a process with process_id = 421:
    2. In my select list I have 3 tasks (who's task_id are 746,782 and 785)
    When executing the above update process I get the following results:
    ID TASK_ID PROCESS_ID TASK_ORDER
    1737 421 421 1
    1738 421 421 2
    1739 421 421 3
    1740 746 421 4
    1741 782 421 5
    1742 785 421 6
    If I am not mistaken the value of
    htmldb_application.g_f02(1) - should be the Task_Id of the first element on my select list
    htmldb_application.g_f02(2) - should be the Task_Id of the second element on my select list and so on....
    Why does htmldb_application.g_f02(1-3) hold a different value is beyond me !
    Questions which bother me:
    - Is there any way to lookup to 'contents' of htmldb_application.g_f02(1) from a separate SQL session or does it has to be in run-time?
    - Perhaps there is a way to flush or clean the htmldb_application.g_f02 ?
    Your help would be greatelly appriciated !
    Regards,
    Pawel.

  • Please help me with SQL query...

    I need some help to figure out how to do this query...
    Here is the data:
    OriginalMessageID MessageID(PK) ExecDate
    1 1234 10:20
    1 5FE2 10:55
    1 EA33 10:50
    2 4667 11:10
    2 98EA 10:13
    Now I need the MessageID for the latest record for each OriginalMessageID,
    so the result would be:
    MessageID(PK)
    5FE2
    4667
    What would the SQL SELECT look like to get this result....
    Thanks
    Maximu

    select
    country.country,
    count(*) Totalpostspercountry,
    count(distinct post.user_id) Totaldistincuserspercountry,
    count(*)/count(distinct post.user_id) Avgpostsperuserbycountry
    from
    country, muser, post
    where country.location_id = muser.location_id
    and muser.user_id = post.user_id
    group by country.country
    The output is like this for your sample data - hope this is what you were looking for :)
    COUNTRY,TOTALPOSTSPERCOUNTRY,TOTALDISTINCUSERSPERCOUNTRY,AVGPOSTSPERUSERBYCOUNTRY
    England,1,1,1,
    Spain,5,2,2.5,

  • Please, help me with sql sentence

    hi everybody
    i have this sentence
    UPDATE RECIBO SET RECARGO = (SELECT MONTHS_BETWEEN (SYSDATE , (SELECT F_PAGADO FROM RECIBO WHERE N_RECIBO = '0001')) / 12 FROM DUAL);
    this sentence gives no erros, but in fact i want the FLOOR of that result (somethig like this):
    UPDATE RECIBO SET RECARGO = (SELECT FLOOR((SELECT MONTHS_BETWEEN (SYSDATE , (SELECT F_PAGADO FROM RECIBO WHERE N_RECIBO = '0001')) / 12 FROM DUAL) , 0) FROM DUAL);
    but this gives the error:
    ERROR en línea 1:
    ORA-00909: número de argumentos no válido
    please, could somebody help me to get the flloor of the first sentence? thanks!

    Here you go:
    UPDATE recibo
    SET    recargo = FLOOR(MONTHS_BETWEEN(SYSDATE , (SELECT f_pagado
                                                     FROM   recibo
                                                     WHERE  n_recibo = '0001')))

  • Please help with PL/SQL compiler message

    Hi
    When I compile a procedure, I get the message
    "Expected Symbol Name is missing"
    "Procedure created"
    The procedure actually got created in the database and runs.
    Can someone please let me know the meaning of "Expected Symbol Name is missing" and any side-effects of this message?
    Thanks in advance.

    Suresh,
    I'm getting the message when I start the file that has the code for the stored procedure (like @X.sql). The first line of the code is CREATE OR REPLACE PROCEDURE .....
    Thanks

  • Please Help with the sql below for hierarchies

    Hi all.
    I have a table named stg_org_hier whose data looks like this
    i would like to build the hierarchy from BU,AREA,REGION,DISTRICT,TERR
    There are data cyles in the data below
    stg_org has this data
    QTR_CD     HIER_LVL_CD CURR_RDT_ID     DISTRICT_RDT_ID
    2007Q4     AREA     E0F7B00000000     E0F7B00000000
    2007Q4     BU     E0F7B00000000     E0F7B00000000
    2007Q4     AREA     E0F7B40000088     E0F7B40000000
    2007Q4     REGION     N0F7B40400000     E0F7B40000000
    2007Q4     REGION     E0F7B40700000     E0F7B40000000
    2007Q4     AREA     E0F7B00000088     E0F7B00000000
    2007Q4     AREA     E0F7B40000000     E0F7B00000000
    2007Q4     DISTRICT     N0F6B40405C99     N0F7B40400000
    2007Q4     REGION     N0F7B40400088     N0F7B40400000
    2007Q4     DISTRICT     N0F7B40405M99     N0F7B40400000
    2007Q4     TERR     N0F1B40405201     N0F7B40405M99
    they would like to see the output in the below in the below form
    QTR_CD     HIER_LVL_CD CURR_RDT_ID     DISTRICT_RDT_ID
    2007Q4     BU     E0F7B00000000     E0F7B00000000
    2007Q4     AREA     E0F7B00000000     E0F7B00000000
    2007Q4     AREA     E0F7B00000088     E0F7B00000000
    2007Q4     AREA     E0F7B40000000     E0F7B00000000
    2007Q4     AREA     E0F7B40000088     E0F7B40000000
    2007Q4     REGION     E0F7B40700000     E0F7B40000000
    2007Q4     REGION     N0F7B40400000     E0F7B40000000
    2007Q4     DISTRICT     N0F6B40405C99     N0F7B40400000
    2007Q4     REGION     N0F7B40400088     N0F7B40400000
    2007Q4     DISTRICT     N0F7B40405M99     N0F7B40400000
    2007Q4     TERR     N0F1B40405201     N0F7B40405M99
    Here is the sql i have written :
    select curr_terr_rdt_id,district_rdt_id,hier_lvl_cd,level from STG_ORG_QTR_SF_HCHY
    connect by prior
    curr_terr_rdt_id=district_rdt_id

    qtr_cd,hier_lvl_cd,curr_rdt_id,  district_rdt_id
    2007Q4,BU,         E0F7B00000000,E0F7B00000000
    2007Q4,AREA,       E0F7B00000000,E0F7B00000000
    2007Q4,AREA,       E0F7B00000088,E0F7B00000000
    2007Q4,AREA,       E0F7B40000000,E0F7B00000000
    2007Q4,AREA,       E0F7B40000088,E0F7B40000000
    2007Q4,REGION,     E0F7B40700000,E0F7B40000000
    2007Q4,REGION,     N0F7B40400000,E0F7B40000000
    2007Q4,DISTRICT,   N0F6B40405C99,N0F7B40400000
    2007Q4,REGION,     N0F7B40400088,N0F7B40400000
    2007Q4,DISTRICT,   N0F7B40405M99,N0F7B40400000
    2007Q4,TERR,       N0F1B40405201,N0F7B40405M99Not having a database at hand right now is helpful this time ;)
    Indenting the data clearly shows that the hierarchy rules are being violated (cycles you are mentioning do not matter in this case):
    Each node must have a unique predecessor except the root having none (in your case data on lines 3 and 4 both point to lines 1 and 2)
    2007Q4,BU,         E0F7B00000000,E0F7B00000000
    2007Q4,AREA,       E0F7B00000000,E0F7B00000000
           2007Q4,AREA,       E0F7B00000088,E0F7B00000000
           2007Q4,AREA,       E0F7B40000000,E0F7B00000000
                  2007Q4,AREA,       E0F7B40000088,E0F7B40000000
                  2007Q4,REGION,     E0F7B40700000,E0F7B40000000
                  2007Q4,REGION,     N0F7B40400000,E0F7B40000000
                         2007Q4,DISTRICT,   N0F6B40405C99,N0F7B40400000
                         2007Q4,REGION,     N0F7B40400088,N0F7B40400000
                         2007Q4,DISTRICT,   N0F7B40405M99,N0F7B40400000
                                2007Q4,TERR,       N0F1B40405201,N0F7B40405M99Removing the first data line or changing it's curr_rdt_id will make hierarhical queries work (lines 1 and 2 would better not point to themself)
    Regards
    Etbin
    Message was edited by: Etbin
    user596003

  • Please help in this sql query

    I have table a with columns ca1,ca2,ca3
    and I have a table b with columns cb1, cb2,cb3
    and a and b tables are related with a table's ca2 and b table's cb2
    ca1 not null,ca2 can be null and cb2 is a not null column, cb3 not null
    I want the output of ca1 and cb3
    If ca2 is null then the output should contain ca1 value and null for cb3
    If ca2 is not nulll comparing both it has to return cb3 value..
    Could anybody help me in tis???
    Thanks in advance..

    Hope I understood your requirement.
    SELECT NVL(ca2,ca1) ca1, DECODE(ca2,NULL,ca2,cb3) cb3 
      FROM a, b
    WHERE ca2=cb2

  • Please help with the sql logic

    The below is going to be a record set from for a view from the FROM CLAUSE
    1. Find component DOCUMENT where the document type = Square Metres (DOC.UOM_STD_ID = 'METR_MTR) If any components are found, retrieve the Document records for these components ONLY.
    2. Otherwise, if no components exist with a Document type = Square Metres, look for components with a Document type of Acres (DOC.UOM_STD_ID = 'ACRE'). If found, retrieve the Space Lease records for these components ONLY.
    3. Otherwise, if the Document does not have components with a type = Square Metres or Acres, look for components with the type of (DOC.UOM_STD_ID = 'PARK'). Then retrieve the departments associated with these parking components.
    For Space Lease records above, retrieve the associated Org ID (SPACE.SPORG).
    Return all departments where
    the associated Org Type (ORG.ORGCLASS) = 'NON'
    or the associated Org Type (ORG.ORGCLASS) = 'GD'
    Thank you

    maybe something like:
    SQL> select emp.empno, emp.ename, emp.deptno
      2    from emp,
      3         (select case when (select 1 from emp where deptno = 10 and rownum  = 1) = 1 then 1
      4                      when (select 2 from emp where deptno = 60 and rownum  = 1) = 2 then 2
      5                      else 3
      6                 end case_col
      7            from dual) d1
      8   where deptno = decode(d1.case_col,1,10,
      9                                     2,60,
    10                                     3,70);
         EMPNO ENAME          DEPTNO
          7839 KING               10
          7782 CLARK              10
          7934 MILLER             10
    SQL> in you code it will be something like:
    select ...
       from document t1,        
            (select case when (select 1 from document doc where DOC.UOM_STD_ID = 'METR_MTR' and rownum  = 1) = 1 then 1
                         when (select 1 from document doc where DOC.UOM_STD_ID = 'ACRE' and rownum  = 1) = 2 then 2
                         else 3
                    end case_col
               from dual) d1
    where t1.uom_std_id = decode(d1.case_col,1,'METR_MTR',
                                             2,'ACRE',
                                             3,'PARK',
                                               null);note: untested

  • Please help me  regarding SQl:Exception

    Hi all.
    I am not getting where i am going wrong
    java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where User_ID=0.0' at line 1
    (where 4 and 5 are the fields where i have to insert the data)
    int i=userTeam.getUserIdentification();
    float d1=userTeam.getUserBetTeam1();
    float f1=userTeam.getO1();
      float dd1=d1*f1;
      float d2=userTeam.getUserBetTeam2();
       float f2=userTeam.getO2();
      float dd2=d2*f2;
       try
            Class.forName("com.mysql.jdbc.Driver");
        con=DriverManager.getConnection("jdbc:mysql://192.168.11.250/Bidding","mysql","pennywise");
            ps=con.prepareStatement("insert into Balance values(?,?) where Balance.User_ID=?");
                      ps.setInt(1,i);
                      ps.setFloat(4,dd1);
                      ps.setFloat(5,dd2);
                      int j=ps.executeUpdate();
    .

    Again same error
    java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where User_ID=0.0' at line 1
    Is that what u r saying
    try
       Class.forName("com.mysql.jdbc.Driver");
       con=DriverManager.getConnection("jdbc:mysql://192.168.11.250/Bidding","mysql","pennywise");
       ps=con.prepareStatement("insert into Balance values(Balance.BettingTeam1=?,Balance.BettingTeam2=?) where User_ID=?");
       ps.setInt(1,i);
       ps.setFloat(2,dd1);
       ps.setFloat(3,dd2);
       int j=ps.executeUpdate();
                

  • Please help with better sql plan - full test case

    Hello,
    here is my test case:
    SQL> create table ib_auth_devices(dv_id number(12) primary key , dv_cl_id number(12));
    Table created.
    SQL> create table ib_clients (cl_id number(12) primary key);
    Table created.
    SQL> alter table ib_auth_devices add constraint fk1 foreign key(dv_cl_id) references ib_clients(cl_id);
    Table altered.
    SQL> create table ib_tokens (to_dv_id number(12) primary key);
    Table created.
    SQL> alter table ib_tokens add constraint to_dv_id foreign key(to_dv_id) references ib_auth_devices(dv_id);
    Table altered.
    SQL> create table ib_auth_cards(au_dv_id number(12) primary key);
    Table created.
    SQL>  alter table ib_auth_cards add constraint  au_dv_id foreign key(au_dv_id) references ib_auth_devices(dv_id);
    Table altered.
    SQL> insert into ib_clients values(1);
    1 row created.
    SQL> insert into ib_clients values(2);
    1 row created.
    SQL> insert into ib_clients values(3);
    1 row created.
    SQL> insert into ib_clients values(4);
    1 row created.
    SQL> insert into ib_clients values(5);
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> insert into ib_auth_devices values(1 , 1);
    1 row created.
    SQL> insert into ib_auth_devices values(2 , 2);
    1 row created.
    SQL>  insert into ib_auth_devices values(3,3);
    1 row created.
    SQL> insert into ib_auth_devices values(4,4);
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> insert into ib_tokens values(1);
    1 row created.
    SQL> insert into ib_tokens values(2);
    1 row created.
    SQL> insert into ib_tokens values(3);
    1 row created.
    SQL> insert into ib_auth_cards values(1);
    1 row created.
    SQL> insert into ib_auth_cards values(2);
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> select cl_id from ib_clients;
         CL_ID
             1
             2
             3
             4
             5
    SQL> select cl_id from ib_clients cli , ib_auth_devices ad
      2  where
      3  cli.cl_id = ad.dv_cl_id;
         CL_ID
             1
             2
             3
             4
    SQL> select * from ib_tokens;
      TO_DV_ID
             1
             2
             3
    SQL> select * from ib_auth_cards;
      AU_DV_ID
             1
             2
    SQL> select * from ib_clients;
         CL_ID
             1
             2
             3
             4
             5
    SQL> select * from ib_auth_devices;
         DV_ID   DV_CL_ID
             1          1
             2          2
             3          3
             4          4
    SQL> exec dbms_stats.gather_table_stats(user , 'IB_AUTH_DEVICES' , cascade => true);
    PL/SQL procedure successfully completed.
    SQL> exec dbms_stats.gather_table_stats(user , 'IB_TOKENS'  , cascade => true);
    PL/SQL procedure successfully completed.
    SQL>  exec dbms_stats.gather_table_stats(user , 'IB_CLIENTS' , cascade => true);
    PL/SQL procedure successfully completed.
    SQL> exec dbms_stats.gather_table_stats(user , 'IB_AUTH_CARDS' ,  cascade => true);
    PL/SQL procedure successfully completed.
    SQL> l
      1  select cli.cl_id from ib_clients cli , ib_auth_devices ad,
      2          (select dv_cl_id as cl_id
      3            from ib_auth_cards, ib_auth_devices
      4            where
      5               au_dv_id = dv_id
      6            ) cards,
      7  (       select dv_cl_id as cl_id
      8            from ib_tokens, ib_auth_devices
      9            where
    10               to_dv_id = dv_id
    11           ) tokens
    12  where
    13  cli.cl_id = ad.dv_cl_id
    14  and cards.cl_id(+)= cli.cl_id
    15  and cards.cl_id is null
    16  and tokens.cl_id(+)= cli.cl_id
    17* and tokens.cl_id is null
    SQL> r
      1  select cli.cl_id from ib_clients cli , ib_auth_devices ad,
      2          (select dv_cl_id as cl_id
      3            from ib_auth_cards, ib_auth_devices
      4            where
      5               au_dv_id = dv_id
      6            ) cards,
      7  (       select dv_cl_id as cl_id
      8            from ib_tokens, ib_auth_devices
      9            where
    10               to_dv_id = dv_id
    11           ) tokens
    12  where
    13  cli.cl_id = ad.dv_cl_id
    14  and cards.cl_id(+)= cli.cl_id
    15  and cards.cl_id is null
    16  and tokens.cl_id(+)= cli.cl_id
    17* and tokens.cl_id is null
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=5 Card=4 Bytes=128)
       1    0   FILTER
       2    1     HASH JOIN (OUTER)
       3    2       FILTER
       4    3         HASH JOIN (OUTER)
       5    4           NESTED LOOPS (Cost=1 Card=4 Bytes=24)
       6    5             TABLE ACCESS (FULL) OF 'IB_AUTH_DEVICES' (Cost=1
               Card=4 Bytes=12)
       7    5             INDEX (UNIQUE SCAN) OF 'SYS_C008299' (UNIQUE)
       8    4           VIEW (Cost=1 Card=2 Bytes=26)
       9    8             NESTED LOOPS (Cost=1 Card=2 Bytes=18)
      10    9               TABLE ACCESS (FULL) OF 'IB_AUTH_DEVICES' (Cost
              =1 Card=4 Bytes=24)
      11    9               INDEX (UNIQUE SCAN) OF 'SYS_C008303' (UNIQUE)
      12    2       VIEW (Cost=1 Card=3 Bytes=39)
      13   12         NESTED LOOPS (Cost=1 Card=3 Bytes=27)
      14   13           TABLE ACCESS (FULL) OF 'IB_AUTH_DEVICES' (Cost=1 C
              ard=4 Bytes=24)
      15   13           INDEX (UNIQUE SCAN) OF 'SYS_C008301' (UNIQUE)
    Statistics
              0  recursive calls
             12  db block gets
              9  consistent gets
              0  physical reads
              0  redo size
            364  bytes sent via SQL*Net to client
            431  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              8  sorts (memory)
              0  sorts (disk)
              1  rows processedAny ideas about rewriting this query to achive better performance ?
    Oracle version 8.1.7
    Best Regards.
    Grzegorz

    The answer to this question totally depends on the real volumes you have in your tables. Your test case is probably not showing us these volumes.
    However, I see some needless table accesses, so it's probably safe to conclude that this rewrite will speed something up:
    SQL> create table ib_auth_devices(dv_id number(12) primary key , dv_cl_id number(12));
    Tabel is aangemaakt.
    SQL> create table ib_clients (cl_id number(12) primary key);
    Tabel is aangemaakt.
    SQL> alter table ib_auth_devices add constraint fk1 foreign key(dv_cl_id) references ib_clients(cl_id);
    Tabel is gewijzigd.
    SQL> create table ib_tokens (to_dv_id number(12) primary key);
    Tabel is aangemaakt.
    SQL> alter table ib_tokens add constraint to_dv_id foreign key(to_dv_id) references ib_auth_devices(dv_id);
    Tabel is gewijzigd.
    SQL> create table ib_auth_cards(au_dv_id number(12) primary key);
    Tabel is aangemaakt.
    SQL> alter table ib_auth_cards add constraint  au_dv_id foreign key(au_dv_id) references ib_auth_devices(dv_id);
    Tabel is gewijzigd.
    SQL> insert into ib_clients values(1);
    1 rij is aangemaakt.
    SQL> insert into ib_clients values(2);
    1 rij is aangemaakt.
    SQL> insert into ib_clients values(3);
    1 rij is aangemaakt.
    SQL> insert into ib_clients values(4);
    1 rij is aangemaakt.
    SQL> insert into ib_clients values(5);
    1 rij is aangemaakt.
    SQL> insert into ib_auth_devices values(1 , 1);
    1 rij is aangemaakt.
    SQL> insert into ib_auth_devices values(2 , 2);
    1 rij is aangemaakt.
    SQL> insert into ib_auth_devices values(3,3);
    1 rij is aangemaakt.
    SQL> insert into ib_auth_devices values(4,4);
    1 rij is aangemaakt.
    SQL> insert into ib_tokens values(1);
    1 rij is aangemaakt.
    SQL> insert into ib_tokens values(2);
    1 rij is aangemaakt.
    SQL> insert into ib_tokens values(3);
    1 rij is aangemaakt.
    SQL> insert into ib_auth_cards values(1);
    1 rij is aangemaakt.
    SQL> insert into ib_auth_cards values(2);
    1 rij is aangemaakt.
    SQL> exec dbms_stats.gather_table_stats(user , 'IB_AUTH_DEVICES' , cascade => true);
    PL/SQL-procedure is geslaagd.
    SQL> exec dbms_stats.gather_table_stats(user , 'IB_TOKENS'  , cascade => true);
    PL/SQL-procedure is geslaagd.
    SQL> exec dbms_stats.gather_table_stats(user , 'IB_CLIENTS' , cascade => true);
    PL/SQL-procedure is geslaagd.
    SQL> exec dbms_stats.gather_table_stats(user , 'IB_AUTH_CARDS' ,  cascade => true);
    PL/SQL-procedure is geslaagd.
    SQL> set autotrace on explain
    SQL> select cli.cl_id
      2    from ib_clients cli
      3       , ib_auth_devices ad
      4       , ( select dv_cl_id as cl_id
      5             from ib_auth_cards
      6                , ib_auth_devices
      7            where au_dv_id = dv_id
      8         ) cards
      9       , ( select dv_cl_id as cl_id
    10             from ib_tokens
    11                , ib_auth_devices
    12            where to_dv_id = dv_id
    13         ) tokens
    14   where cli.cl_id = ad.dv_cl_id
    15     and cards.cl_id(+)= cli.cl_id
    16     and cards.cl_id is null
    17     and tokens.cl_id(+)= cli.cl_id
    18     and tokens.cl_id is null
    19  /
                                     CL_ID
                                         4
    1 rij is geselecteerd.
    Uitvoeringspan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=10 Card=4 Bytes=128)
       1    0   FILTER
       2    1     HASH JOIN (OUTER)
       3    2       FILTER
       4    3         HASH JOIN (OUTER)
       5    4           NESTED LOOPS (Cost=4 Card=4 Bytes=24)
       6    5             TABLE ACCESS (FULL) OF 'IB_AUTH_DEVICES' (Cost=3 Card=4 Bytes=12)
       7    5             INDEX (UNIQUE SCAN) OF 'SYS_C001354381' (UNIQUE) (Cost=1 Card=1 Bytes=3)
       8    4           VIEW (Cost=3 Card=2 Bytes=26)
       9    8             NESTED LOOPS (Cost=3 Card=2 Bytes=18)
      10    9               INDEX (FULL SCAN) OF 'SYS_C001354385' (UNIQUE) (Cost=2 Card=2 Bytes=6)
      11    9               TABLE ACCESS (BY INDEX ROWID) OF 'IB_AUTH_DEVICES' (Cost=2 Card=1 Bytes=6)
      12   11                 INDEX (UNIQUE SCAN) OF 'SYS_C001354380' (UNIQUE) (Cost=1 Card=1)
      13    2       VIEW (Cost=3 Card=3 Bytes=39)
      14   13         NESTED LOOPS (Cost=3 Card=3 Bytes=27)
      15   14           INDEX (FULL SCAN) OF 'SYS_C001354383' (UNIQUE) (Cost=2 Card=3 Bytes=9)
      16   14           TABLE ACCESS (BY INDEX ROWID) OF 'IB_AUTH_DEVICES' (Cost=2 Card=1 Bytes=6)
      17   16             INDEX (UNIQUE SCAN) OF 'SYS_C001354380' (UNIQUE) (Cost=1 Card=1)
    SQL> select cli.cl_id
      2    from ib_clients cli
      3       , ib_auth_devices ad
      4   where cli.cl_id = ad.dv_cl_id
      5     and not exists
      6         ( select 'dummy'
      7             from ib_auth_cards
      8            where au_dv_id = ad.dv_id
      9         )
    10     and not exists
    11         ( select 'dummy'
    12             from ib_tokens
    13            where to_dv_id = ad.dv_id
    14         )
    15  /
                                     CL_ID
                                         4
    1 rij is geselecteerd.
    Uitvoeringspan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=8 Card=1 Bytes=9)
       1    0   FILTER
       2    1     NESTED LOOPS (Cost=4 Card=1 Bytes=9)
       3    2       TABLE ACCESS (FULL) OF 'IB_AUTH_DEVICES' (Cost=3 Card=1 Bytes=6)
       4    2       INDEX (UNIQUE SCAN) OF 'SYS_C001354381' (UNIQUE) (Cost=1 Card=1 Bytes=3)
       5    1     INDEX (UNIQUE SCAN) OF 'SYS_C001354385' (UNIQUE) (Cost=1 Card=1 Bytes=3)
       6    1     INDEX (UNIQUE SCAN) OF 'SYS_C001354383' (UNIQUE) (Cost=1 Card=1 Bytes=3)Regards,
    Rob.

  • Please help with the sql

    Hi ALL,
    Test_dpnt is a table.from this i want to find the total no.of applications
    (ssc,ssa,ssb,ssd,map,maq,oet,oet)---total 8.
    parent - 2(since oet is indepentdent)
    children---4
    independent-2
    source_app is the parent applications
    dpnt_app---child application of parent
    source_app dpnt_app
    ssc ssa
    ssc ssb
    ssc ssd
    mad map
    mad maq
    oet oet
    I want the output likethis
    total parent child independent
    8 2 4 2
    How to write the sql for this

    still unclear to me on how you will be able to get the output as
    total parent child independent
    8     2      4     2based on the sample data you have posted below:
    app_srce app_dpnt app_dpnt-typ-c
    43       190      R
    43       191      R
    150      200      R
    150      201      R
    300      300      Rdo you mean by the output should look something like this:
    srce count dpnt count
    2          1        
               1        
    2          1
               1
    1          1or that it needs to count all the rows for each of the 3 columns

  • Query--please help

    Hello Forum Members,
    Can you please help me out:
    SQL> select * from quarter_test4;
    QUARTER CONFIG REP_DATE
    Q1-2007 10 12-JAN-07
    Q2-2007 10 21-APR-07
    Q3-2007 870 14-AUG-07
    Q4-2007 50 15-NOV-07
    Q1-2008 60 02-JAN-09
    Q4-2006 160 02-DEC-06
    I want the following out put:
    Please note that the future quarters should have current quarter sum(config).Please note that The current table
    does not hold future quarters.I have to genarate query on which a report is based.
    My Query:
    SELECT quarter,
    CASE
    WHEN qtr > TRUNC(SYSDATE, 'q')
    THEN LAST_VALUE(sum_config IGNORE NULLS) OVER(ORDER BY qtr)
    ELSE sum_config
    END sum_config
    FROM (SELECT qtr, q.qtrstr quarter, SUM(qt.config) sum_config
    FROM (SELECT 'Q' || TO_CHAR(qtr, 'q-yyyy') qtrstr, qtr
    FROM (SELECT ADD_MONTHS(ADD_MONTHS(TRUNC(SYSDATE, 'q'), -13), 3 *(LEVEL - 1)) qtr
    FROM DUAL
    CONNECT BY LEVEL <= 9)
    ORDER BY qtr) q,
    quarter_test4 qt
    WHERE qt.quarter(+) = q.qtrstr
    GROUP BY qtr, q.qtrstr)
    ORDER BY qtr;
    Correct Output Generated:
    QUARTER SUM_CONFIG
    Q4-2006 160
    Q1-2007 10
    Q2-2007 10
    Q3-2007 870
    Q4-2007 50
    Q1-2008 60
    Q2-2008 60
    Q3-2008 60
    Q4-2008 60
    ====================================================================================================================================
    New Requirement:Product column has been added.
    SQL> select * from quarter_test3;
    QUARTER CONFIG REP_DATE PRODUCT
    Q1-2007 10 12-JAN-07 P1
    Q2-2007 10 21-APR-07 P1
    Q3-2007 870 14-AUG-07 P1
    Q4-2007 50 15-NOV-07 P1
    Q1-2008 60 02-JAN-09 P1
    Q4-2006 160 02-DEC-06 P1
    Q4-2006 997 02-DEC-06 P2
    Q4-2007 60 14-NOV-07 P2
    Q3-2007 970 14-NOV-07 P2
    Q2-2007 20 21-APR-07 P2
    Q1-2007 20 12-JAN-07 P2
    QUARTER CONFIG REP_DATE PRODUCT
    Q1-2008 70 12-JAN-08 P2
    Expected Output:
    Q4-2006 160 P1
    Q1-2007 10 P1
    Q2-2007 10 P1
    Q3-2007 870 P1
    Q4-2007 50 P1
    Q1-2008 60 P1
    Q2-2008 60 P1
    Q3-2008 60 P1
    Q4-2008 60 P1
    Q4-2006 260 P2
    Q1-2007 20 P2
    Q2-2007 20 P2
    Q3-2007 970 P2
    Q4-2007 60 P2
    Q1-2008 70 P2
    Q2-2008 70 P2
    Q3-2008 70 P2
    Q4-2008 70 P2
    My Query:
    SELECT quarter,product,
    CASE
    WHEN qtr > TRUNC(SYSDATE, 'q')
    THEN LAST_VALUE(sum_config IGNORE NULLS) OVER(ORDER BY qtr)
    ELSE sum_config
    END sum_config
    FROM (SELECT qtr, q.qtrstr quarter,product, SUM(qt.config) sum_config
    FROM (SELECT 'Q' || TO_CHAR(qtr, 'q-yyyy') qtrstr, qtr
    FROM (SELECT ADD_MONTHS(ADD_MONTHS(TRUNC(SYSDATE, 'q'), -13), 3 *(LEVEL - 1)) qtr
    FROM DUAL
    CONNECT BY LEVEL <= 9)
    ORDER BY qtr) q,
    quarter_test3 qt
    WHERE qt.quarter(+) = q.qtrstr
    GROUP BY qtr,product, q.qtrstr)
    ORDER BY substr(qtr,-4),substr(QTR,2,1)
    Output:
    QUARTER PRODUCT SUM_CONFIG
    Q4-2006 P1 160
    Q4-2006 P2 997
    Q4-2007 P1 50
    Q4-2007 P2 60
    Q4-2008 70
    Q2-2007 P1 10
    Q2-2007 P2 20
    Q2-2008 70
    Q3-2007 P1 870
    Q3-2007 P2 970
    Q3-2008 70
    QUARTER PRODUCT SUM_CONFIG
    Q1-2007 P1 10
    Q1-2007 P2 20
    Q1-2008 P1 70
    Q1-2008 P2 70
    The query had not generated q2-2008,q3-2008,q4-2008 values [60]for P1...it had only generated q2-2008,q3-2008,q4-2008 values[70] for product P2.
    Can you please advise me.

    You can make up the data using the model clause:
    SQL> create table quarter_test3 (quarter, config, product)
      2  as
      3  select 'Q1-2007', 10, 'P1' from dual union all
      4  select 'Q2-2007', 10, 'P1' from dual union all
      5  select 'Q3-2007', 870, 'P1' from dual union all
      6  select 'Q4-2007', 50, 'P1' from dual union all
      7  select 'Q1-2008', 60, 'P1' from dual union all
      8  select 'Q4-2006', 160, 'P1' from dual union all
      9  select 'Q4-2006', 997, 'P2' from dual union all
    10  select 'Q1-2007', 60, 'P2' from dual union all
    11  select 'Q2-2007', 970, 'P2' from dual union all
    12  select 'Q3-2007', 20, 'P2' from dual union all
    13  select 'Q4-2007', 20, 'P2' from dual union all
    14  select 'Q1-2008', 70, 'P2' from dual
    15  /
    Tabel is aangemaakt.
    SQL> select 'Q' || to_char(mod(q,4) + 1) || '-' || to_char(trunc(q/4)) quarter
      2       , config
      3       , product
      4    from quarter_test3
      5   model
      6         partition by (product)
      7         dimension by (to_number(substr(quarter,4))*4 + to_number(substr(quarter,2,1)) - 1 q)
      8         measures (config)
      9         rules
    10         ( config[for q from 2006*4 + 3 to 2008*4 + 3 increment 1]
    11           = nvl(config[cv()],config[cv()-1])
    12         )
    13   order by product
    14       , q
    15  /
    QUARTER                                                                                CONFIG PR
    Q4-2006                                                                                   160 P1
    Q1-2007                                                                                    10 P1
    Q2-2007                                                                                    10 P1
    Q3-2007                                                                                   870 P1
    Q4-2007                                                                                    50 P1
    Q1-2008                                                                                    60 P1
    Q2-2008                                                                                    60 P1
    Q3-2008                                                                                    60 P1
    Q4-2008                                                                                    60 P1
    Q4-2006                                                                                   997 P2
    Q1-2007                                                                                    60 P2
    Q2-2007                                                                                   970 P2
    Q3-2007                                                                                    20 P2
    Q4-2007                                                                                    20 P2
    Q1-2008                                                                                    70 P2
    Q2-2008                                                                                    70 P2
    Q3-2008                                                                                    70 P2
    Q4-2008                                                                                    70 P2
    18 rijen zijn geselecteerd.Regards,
    Rob.

  • Please help me to tune this PL/SQL...

    Hi everyone,
        I have a SQL query which runs ok when i run it individually but the same query if
    i use it in a procedure.The procedure is hanging up.Could someone please help to tune this
    SQL query and please check my procedure why is it hanging up.
    SQL Query
    =========
    SELECT active_members.member_nbr,
      active_members.name_last,
      active_members.name_first,
      active_members.name_middle,
      active_members.dob,
      active_members.sex,
      active_members.subsciber_nbr,
      active_members.ssn,
      active_members.name_suffix,
      active_members.class_x,
      active_members.aff_nbr,
    CASE
    WHEN TRIM(active_members.class_x) = 'SE' THEN
        (SELECT DISTINCT(mssp.member_nbr)
         FROM member_span mssp
         WHERE SUBSTR(mssp.member_nbr,    1,    9) = SUBSTR(active_members.member_nbr,    1,    9)
         AND mssp.class_x = 'SP'
         AND rownum = 1)
       WHEN TRIM(active_members.class_x) = 'SP' THEN
          (SELECT DISTINCT(mssp.member_nbr)
           FROM member_span mssp
           WHERE SUBSTR(mssp.member_nbr,    1,    9) = SUBSTR(active_members.member_nbr,    1,    9)
           AND mssp.class_x = 'SE'
           AND rownum = 1)
      ELSE
        NULL
       END)
    spouse_member_nbr,
      active_members.division_nbr,
      active_members.ymdeff,
      active_members.ymdend,
      active_members.actual_ymd_enddt,
      active_members.email_id,
      active_members.network_id,
      active_members.insurance_company_code,
      active_members.cob_flag,
      active_members.vip_flag,
      active_members.pre_x_flag,
      active_members.region,
      active_contracts.language_x,
      active_contracts.corp_nbr,
      active_members.group_nbr,
      active_members.non_erisa_status
    FROM
      (SELECT mb_active.member_nbr,
         mb_active.contract_nbr,
         mb_active.name_last,
         mb_active.name_first,
         mb_active.name_middle,
         ms_active.ymdeff,
         ms_active.ymdend,
         to_char(to_date(
       CASE
       WHEN LENGTH(mb_active.ymdbirth) = 8 THEN mb_active.ymdbirth
       ELSE NULL
       END,    'YYYYMMDD'),    'MM/DD/YYYY') dob,
         mb_active.sex,
         to_char(to_date(ms_active.ymdeff,    'YYYYMMDD'),    'MM/DD/YYYY') ymdeff_formatted,
         to_char(to_date(ms_active.ymdend,    'YYYYMMDD'),    'MM/DD/YYYY') ymdend_formatted,
         ms_active.void,
       CASE
       WHEN SUBSTR(mb_active.member_nbr,    10,    2) = '00' THEN mb_active.member_nbr
       ELSE SUBSTR(mb_active.member_nbr,    1,    9) || '00'
       END) subsciber_nbr,
         mb_active.ssn,
         mb_active.name_suffix,
         ms_active.class_x,
         ms_active.aff_nbr,
         ms_active.division_nbr,
       CASE
       WHEN TRIM(ms_active.ymdend) = '99991231' THEN NULL
       ELSE to_char(to_date(ms_active.ymdend,    'YYYYMMDD'),    'MM/DD/YYYY')
       END) actual_ymd_enddt,
       CASE
       WHEN TRIM(ms_active.business_unit) = '01' THEN ms_active.business_unit || '-' || ms_active.prog_nbr
       WHEN TRIM(ms_active.business_unit) = '03' THEN ms_active.business_unit || '-' || ms_active.prog_nbr || '-' || ms_active.carrier
       ELSE NULL
       END) network_id,
         ms_active.business_unit || '-' || ms_active.prog_nbr || '-' || ms_active.carrier insurance_company_code,
          (SELECT DISTINCT(email)
         FROM dbo.av_mem_email
         WHERE dbo.av_mem_email.member_nbr = mb_active.member_nbr
         AND rownum = 1)
      email_id,
         mb_active.lr_response cob_flag,
         mb_active.record_nbr vip_flag,
         ms_active.pre_exist pre_x_flag,
         ms_active.region region,
         ms_active.group_nbr,
       CASE
       WHEN
        (SELECT TRIM(div.div_status)
         FROM division div
         WHERE TRIM(div.division_nbr) = TRIM(ms_active.division_nbr)) = 'NULL' THEN
          'Y'
         ELSE
          'N'
         END)
      non_erisa_status
       FROM member mb_active,
         member_span ms_active
       WHERE mb_active.member_nbr = ms_active.member_nbr
       AND(20090707 BETWEEN ms_active.ymdeff
       AND ms_active.ymdend
       AND TRIM(ms_active.void) IS NULL
    active_members,
        (SELECT DISTINCT(contract.contract_nbr),
         contract.language_x,
         contract_span.corp_nbr
       FROM contract,
         contract_span
       WHERE contract.contract_nbr = contract_span.contract_nbr
       AND(20090707 BETWEEN contract_span.ymdeff
       AND contract_span.ymdend)
       AND TRIM(contract_span.void) IS
      NULL)
    active_contracts
    WHERE TRIM(active_members.contract_nbr) = TRIM(active_contracts.contract_nbr);
    Taking around 6 minute to run and it returns """"268267"""" records
    Explain Plan for the above SQL:
    ===============================
    "PLAN_TABLE_OUTPUT"
    "Plan hash value: 379550299"
    "| Id  | Operation                      | Name          | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |"
    "|   0 | SELECT STATEMENT               |               |  2609K|   659M|       | 91679   (3)| 00:18:21 |"
    "|   1 |  HASH UNIQUE                   |               |     1 |    16 |       | 54461   (2)| 00:10:54 |"
    "|*  2 |   COUNT STOPKEY                |               |       |       |       |            |          |"
    "|*  3 |    TABLE ACCESS FULL           | MEMBER_SPAN   | 12891 |   201K|       | 54459   (2)| 00:10:54 |"
    "|   4 |    HASH UNIQUE                 |               |     1 |    16 |  2424K| 54736   (2)| 00:10:57 |"
    "|*  5 |     COUNT STOPKEY              |               |       |       |       |            |          |"
    "|*  6 |      TABLE ACCESS FULL         | MEMBER_SPAN   | 51541 |   805K|       | 54459   (2)| 00:10:54 |"
    "|   7 |  HASH UNIQUE                   |               |     1 |    50 |       |    64   (4)| 00:00:01 |"
    "|*  8 |   COUNT STOPKEY                |               |       |       |       |            |          |"
    "|*  9 |    TABLE ACCESS FULL           | AV_MEM_EMAIL  |     1 |    50 |       |    63   (2)| 00:00:01 |"
    "|* 10 |  TABLE ACCESS FULL             | DIVISION      |     1 |    14 |       |     3   (0)| 00:00:01 |"
    "|* 11 |  HASH JOIN                     |               |  2609K|   659M|       | 91679   (3)| 00:18:21 |"
    "|  12 |   VIEW                         |               |   581 | 12782 |       |  8184   (4)| 00:01:39 |"
    "|  13 |    HASH UNIQUE                 |               |   581 | 26145 |       |  8184   (4)| 00:01:39 |"
    "|  14 |     TABLE ACCESS BY INDEX ROWID| CONTRACT      |     1 |    14 |       |     2   (0)| 00:00:01 |"
    "|  15 |      NESTED LOOPS              |               |   581 | 26145 |       |  8183   (4)| 00:01:39 |"
    "|* 16 |       TABLE ACCESS FULL        | CONTRACT_SPAN |   581 | 18011 |       |  7019   (5)| 00:01:25 |"
    "|* 17 |       INDEX RANGE SCAN         | CONTRACT_IX1  |     1 |       |       |     1   (0)| 00:00:01 |"
    "|* 18 |   HASH JOIN                    |               |   449K|   104M|    39M| 83466   (2)| 00:16:42 |"
    "|* 19 |    TABLE ACCESS FULL           | MEMBER_SPAN   |   449K|    34M|       | 54964   (3)| 00:11:00 |"
    "|  20 |    TABLE ACCESS FULL           | MEMBER        |  1436K|   221M|       | 14664   (2)| 00:02:56 |"
    "Predicate Information (identified by operation id):"
    "   2 - filter(ROWNUM=1)"
    "   3 - filter(SUBSTR("MSSP"."MEMBER_NBR",1,9)=SUBSTR(:B1,1,9) AND "MSSP"."CLASS_X"='SP')"
    "   5 - filter(ROWNUM=1)"
    "   6 - filter(SUBSTR("MSSP"."MEMBER_NBR",1,9)=SUBSTR(:B1,1,9) AND "MSSP"."CLASS_X"='SE')"
    "   8 - filter(ROWNUM=1)"
    "   9 - filter("AV_MEM_EMAIL"."MEMBER_NBR"=:B1)"
    "  10 - filter(TRIM("DIV"."DIVISION_NBR")=TRIM(:B1))"
    "  11 - access(TRIM("MB_ACTIVE"."CONTRACT_NBR")=TRIM("ACTIVE_CONTRACTS"."CONTRACT_NBR"))"
    "  16 - filter("CONTRACT_SPAN"."YMDEFF"<=20090707 AND TRIM("CONTRACT_SPAN"."VOID") IS NULL AND "
    "              "CONTRACT_SPAN"."YMDEND">=20090707)"
    "  17 - access("CONTRACT"."CONTRACT_NBR"="CONTRACT_SPAN"."CONTRACT_NBR")"
    "  18 - access("MB_ACTIVE"."MEMBER_NBR"="MS_ACTIVE"."MEMBER_NBR")"
    "  19 - filter(TRIM("MS_ACTIVE"."VOID") IS NULL AND "MS_ACTIVE"."YMDEFF"<=20090707 AND "
    "              "MS_ACTIVE"."YMDEND">=20090707)"
    SAME SQL IN A PROCEDURE..IT IS HANGING UP
    ========================================
    create or replace PROCEDURE TEST_CURRENT_PCP_SPAN is
    EXTRACTED_STRING VARCHAR2(32767);
    FILEHANDLER UTL_FILE.FILE_TYPE;
    test_str varchar2(100);
    pcp_eff_date number(10);
    file_name varchar2(50);
       CURSOR MEMBERS
       IS
    SELECT active_members.member_nbr,
      active_members.name_last,
      active_members.name_first,
      active_members.name_middle,
      active_members.dob,
      active_members.sex,
      active_members.subsciber_nbr,
      active_members.ssn,
      active_members.name_suffix,
      active_members.class_x,
      active_members.aff_nbr,
    CASE
    WHEN TRIM(active_members.class_x) = 'SE' THEN
        (SELECT DISTINCT(mssp.member_nbr)
         FROM member_span mssp
         WHERE SUBSTR(mssp.member_nbr,    1,    9) = SUBSTR(active_members.member_nbr,    1,    9)
         AND mssp.class_x = 'SP'
         AND rownum = 1)
       WHEN TRIM(active_members.class_x) = 'SP' THEN
          (SELECT DISTINCT(mssp.member_nbr)
           FROM member_span mssp
           WHERE SUBSTR(mssp.member_nbr,    1,    9) = SUBSTR(active_members.member_nbr,    1,    9)
           AND mssp.class_x = 'SE'
           AND rownum = 1)
      ELSE
        NULL
       END)
    spouse_member_nbr,
      active_members.division_nbr,
      active_members.ymdeff,
      active_members.ymdend,
      active_members.actual_ymd_enddt,
      active_members.email_id,
      active_members.network_id,
      active_members.insurance_company_code,
      active_members.cob_flag,
      active_members.vip_flag,
      active_members.pre_x_flag,
      active_members.region,
      active_contracts.language_x,
      active_contracts.corp_nbr,
      active_members.group_nbr,
      active_members.non_erisa_status
    FROM
      (SELECT mb_active.member_nbr,
         mb_active.contract_nbr,
         mb_active.name_last,
         mb_active.name_first,
         mb_active.name_middle,
         ms_active.ymdeff,
         ms_active.ymdend,
         to_char(to_date(
       CASE
       WHEN LENGTH(mb_active.ymdbirth) = 8 THEN mb_active.ymdbirth
       ELSE NULL
       END,    'YYYYMMDD'),    'MM/DD/YYYY') dob,
         mb_active.sex,
         to_char(to_date(ms_active.ymdeff,    'YYYYMMDD'),    'MM/DD/YYYY') ymdeff_formatted,
         to_char(to_date(ms_active.ymdend,    'YYYYMMDD'),    'MM/DD/YYYY') ymdend_formatted,
         ms_active.void,
       CASE
       WHEN SUBSTR(mb_active.member_nbr,    10,    2) = '00' THEN mb_active.member_nbr
       ELSE SUBSTR(mb_active.member_nbr,    1,    9) || '00'
       END) subsciber_nbr,
         mb_active.ssn,
         mb_active.name_suffix,
         ms_active.class_x,
         ms_active.aff_nbr,
         ms_active.division_nbr,
       CASE
       WHEN TRIM(ms_active.ymdend) = '99991231' THEN NULL
       ELSE to_char(to_date(ms_active.ymdend,    'YYYYMMDD'),    'MM/DD/YYYY')
       END) actual_ymd_enddt,
       CASE
       WHEN TRIM(ms_active.business_unit) = '01' THEN ms_active.business_unit || '-' || ms_active.prog_nbr
       WHEN TRIM(ms_active.business_unit) = '03' THEN ms_active.business_unit || '-' || ms_active.prog_nbr || '-' || ms_active.carrier
       ELSE NULL
       END) network_id,
         ms_active.business_unit || '-' || ms_active.prog_nbr || '-' || ms_active.carrier insurance_company_code,
          (SELECT DISTINCT(email)
         FROM dbo.av_mem_email
         WHERE dbo.av_mem_email.member_nbr = mb_active.member_nbr
         AND rownum = 1)
      email_id,
         mb_active.lr_response cob_flag,
         mb_active.record_nbr vip_flag,
         ms_active.pre_exist pre_x_flag,
         ms_active.region region,
         ms_active.group_nbr,
       CASE
       WHEN
        (SELECT TRIM(div.div_status)
         FROM division div
         WHERE TRIM(div.division_nbr) = TRIM(ms_active.division_nbr)) = 'NULL' THEN
          'Y'
         ELSE
          'N'
         END)
      non_erisa_status
       FROM member mb_active,
         member_span ms_active
       WHERE mb_active.member_nbr = ms_active.member_nbr
       AND(20090707 BETWEEN ms_active.ymdeff
       AND ms_active.ymdend
       AND TRIM(ms_active.void) IS NULL
    active_members,
        (SELECT DISTINCT(contract.contract_nbr),
         contract.language_x,
         contract_span.corp_nbr
       FROM contract,
         contract_span
       WHERE contract.contract_nbr = contract_span.contract_nbr
       AND(20090707 BETWEEN contract_span.ymdeff
       AND contract_span.ymdend)
       AND TRIM(contract_span.void) IS
      NULL)
    active_contracts
    WHERE TRIM(active_members.contract_nbr) = TRIM(active_contracts.contract_nbr);
      TYPE MEM IS TABLE OF MEMBERS%ROWTYPE INDEX BY PLS_INTEGER;
      TABLE_MEM MEM;
    MEMBER_ADDR   MGONZALEZ.CPKG_UTIL.ADDR;
    BEGIN 
       test_str := '''A10000213'''||','||'''A10000213''';
       insert into test_number_char(str) values ('start time of MEMBER_LOAD_CURRENT_PCP_SPAN '||to_char(sysdate,'MM/DD/YYYY HH24:MI:SS'));
       commit;
       file_name := 'member_load'||to_char(sysdate,'YYYYMMDDHH24MI')||'.txt';
       FILEHANDLER := UTL_FILE.FOPEN('AVMED_UTL_FILE',file_name, 'W',10000);
       insert into test_number_char(str) values ('start time of opening members cursor(before open members command) '||to_char(sysdate,'MM/DD/YYYY HH24:MI:SS'));
       commit;
       OPEN MEMBERS;
    LOOP
          FETCH MEMBERS
             BULK COLLECT INTO TABLE_MEM LIMIT 1000 ;
           EXIT WHEN TABLE_MEM.COUNT = 0;
    insert into test_number_char(str) values ('start time of outer loop '||to_char(sysdate,'MM/DD/YYYY HH24:MI:SS'));
    commit;
          FOR i IN 1 .. TABLE_MEM.COUNT
          LOOP
          EXTRACTED_STRING := TRIM(TABLE_MEM(i).MEMBER_NBR)||'| '||     
                              TRIM(TABLE_MEM(i).NAME_LAST)||'| '||      
                            TRIM(TABLE_MEM(i).NAME_FIRST)||'| '||      
                             TRIM(TABLE_MEM(i).NAME_MIDDLE)||'| '||   
                             TRIM(TABLE_MEM(i).ssn)||'| '||            
                             TABLE_MEM(i).subsciber_nbr||'| '||        
                             TRIM(TABLE_MEM(i).class_x)||'| '||         
                             TRIM(TABLE_MEM(i).DOB)||'| '||             
                             TRIM(TABLE_MEM(i).SEX)||'| ' ;             
              EXTRACTED_STRING   :=
                    EXTRACTED_STRING ||
                  TRIM(TABLE_MEM(i).aff_nbr)||'| '||                         
                                pcp_eff_date||'| '||                 
              TABLE_MEM(i).actual_ymd_enddt||'| '||                        
                  TRIM(TABLE_MEM(i).division_nbr)||'| '||                    
                  ' '||'| '||                                               
                  ' '||'| '||                                                  
                  ' '||'| '||                                                 
                  TABLE_MEM(i).network_id||'| '||                              
                  ' '||'| '||                                                  
                  ' '||'| '||                                                  
                  ' '||'| '||                                                  
                  ' '||'| '||                                                 
                  ' '||'| '||                                                  
                 TRIM(TABLE_MEM(i).name_suffix)||'| '||                       
                 ' '||'| '||                                                   
                 TRIM(TABLE_MEM(i).spouse_member_nbr)||'| '||                  
                 ' '||'| '||                                                   
                 ' '||'| '||                                                   
                 ' '||'| '||                                                  
                 ' '||'| '||                                                   
                 ' '||'| '||                                                  
                 ' '||'| '||                                                   
                 ' '||'| '||                                                   
                 ' '||'| '||                                                   
                 ' '||'| '||                                                   
                 ' '||'| '||                                                   
                 ' '||'| '||                                                   
                 ' '||'| '||                                                  
                 ' '||'| '||                                                   
                TRIM(TABLE_MEM(i).email_id)||'| '||                                
                TABLE_MEM(i).Insurance_company_code||'| '||                    
                TABLE_MEM(i).group_nbr||'| '||                                 
                TABLE_MEM(i).language_x||'| '||                               
                TABLE_MEM(i).region||'| '||                                    
                TABLE_MEM(i).corp_nbr||'| '||                                  
                TABLE_MEM(i).non_erisa_status||'| '||                          
                TABLE_MEM(i).cob_flag||'| '||                                  
                TABLE_MEM(i).pre_x_flag||'| '||                                
                TABLE_MEM(i).vip_flag                                       
                 EXTRACTED_STRING   := rtrim(EXTRACTED_STRING,' ');
            UTL_FILE.PUT_LINE(FILEHANDLER,EXTRACTED_STRING,TRUE);
            EXTRACTED_STRING := NULL;
            pcp_eff_date := NULL;
          END LOOP;
          insert into test_number_char(str) values ('end time of outer loop '||to_char(sysdate,'MM/DD/YYYY HH24:MI:SS'));
    commit;
    END LOOP;
    close members;
    insert into test_number_char(str) values ('end time of opening members cursor '||to_char(sysdate,'MM/DD/YYYY HH24:MI:SS'));
    commit;
    commit;
       UTL_FILE.FCLOSE(FILEHANDLER);
       insert into test_number_char(str) values ('End time of MEMBER_LOAD_CURRENT_PCP_SPAN '||to_char(sysdate,'MM/DD/YYYY HH24:MI:SS'));
       commit;
       EXCEPTION
          WHEN OTHERS
          THEN
             DBMS_OUTPUT.put_line(   'ERROR getting members '
                                  || SQLCODE
                                  || ' '
                                  || SQLERRM);
    END ;
    In my Test table which i am inserting to check the times...
    I am geting on these 2 records after that it hangs up...
    start time of MEMBER_LOAD_CURRENT_PCP_SPAN 07/08/2009 11:41:21
    start time of opening members cursor(before open members command) 07/08/2009 11:41:21I have to call some other functions for each member to get additional details thats the reason i am going for Procedure.Instead it is just a simple SQL
    Thanks in advance

    It is taking lot of timeYou could perhaps split it up in smaller, isolated parts.
    Running certain steps separate.
    ..is it possible to find out the issues without running the proc?Other than have other people on OTN give their ideas/share experiences?
    Not that I'm aware of.
    There are lots of statistical views, you might be able to deduct from their data, but I personally prefer running the procedure and just trace it. But I'm always willing to learn new approaches, btw.
    Still, you have 2 things to look at, at least:
    - avoid loops in loops if possible
    - check your predicates, if you apply a function, you lose the index, unless you create a function based index.
    edit
    One more thing (how could I overlook that):
    You commit your instrumentation code ( insert into test_number_char(str) ) IN the loop.
    Please remove commit in your loops...
    Commit only once, at the end of your transaction.
    Never commit in a loop.
    (Preferrably the client commits)
    And remove every commit in your loop...
    Edited by: hoek on Jul 8, 2009 8:03 PM

Maybe you are looking for

  • Old IPhone vs. New IPhone

    So I'm hoping there would be some form of special rate for the loyal customers before the IPHONE 3G but it doesn't seem to be coming around. I understand that this one will be ALOT cheaper but I don't want to have to deal with paying for anything. Wh

  • Difference between J2SE and J2EE...

    Hi all. I was wondering what the difference between J2SE and J2EE were. I mean in the code structure. Are the packages the same, like Swing, IO, things like that. I'm a bit of a beginner in Java, only been messing around with it for about 6 months no

  • ORA-03013 end-of-communication channel.

    Hi all, When I am starting ORACLE database, I am gettting this error. Database and client in same M/C. This my trace files. File is here. +++++++++++++++++++++++++++++++++++++++++++++ Dump file /ora/app/oracle/admin/dbcss2/bdump/lgwr_1377.trc Oracle8

  • Photoshop CS6 spacebar shortcut for hand tool stopped working. How do I get it to work?

    I just bought a new IMac and finshed downloading my new cs6 photoshop. I notice my spacebar no longer scrolls/ pans anymore. A bit annoying, that how I am use to doing my work. How Do I fix the problem?

  • OIM-AD-Exchange prepopulate query

    Hi, We have OIM-AD-Exchange in our environment Exchange is dependent on AD When Exchange is provisioned we want to pre-popopulate "alias name" attribute with respective AD user samAccountName. To this end i will have to create a pre-populate adapter.