Multiple record insert problem in Oracle Procedure that uses a cursor

Dear X-pert guies,
I have a oracle procedure that use a cursor, I repeatedly make query on 1st table using cursor value and insert that queried value(of 1st table) to 2nd table
y_summary. y_summary has composite  primary key :PK_Y_SUM (BILL_DATE, TRUNK_MGR, IDD_FLAG, PK_FLAG, PREFIX).*
when i run the procedure explicit2('201001'); the it gives me the error:::: begin explicit2('201001'); end;_
ORA-00001: unique constraint (PRM.PK_Y_SUM) violated_
ORA-06512: at "PRM.EXPLICIT2", line 413_
ORA-06512: at line 1_
but when i remove the composite primary key from y_summary table then, the procedure runs ok and make so many duplicate entries in y_summary.
but i want the single record  to be inserted for single time in y_summary ,so You guies are honorly requested to make the required help .
the structure of y_summary Table and Procdure code is given below.
Table:
-- Create table
create table Y_SUMMARY
BILL_DATE VARCHAR2(10) not null,
TRUNK_MGR VARCHAR2(20) not null,
IDD_FLAG VARCHAR2(10) not null,
PK_FLAG NUMBER(2) not null,
OUTCALLS NUMBER(20,2),
OUTDUR NUMBER(20,2),
PREFIX VARCHAR2(10) not null
tablespace TBS_PRM_D01
pctfree 10
pctused 40
initrans 1
maxtrans 255
storage
initial 64K
minextents 1
maxextents unlimited
-- Create/Recreate primary, unique and foreign key constraints
alter table Y_SUMMARY
add constraint PK_Y_SUM primary key (BILL_DATE, TRUNK_MGR, IDD_FLAG, PK_FLAG, PREFIX)
using index
tablespace TBS_PRM_D01
pctfree 10
initrans 2
maxtrans 255
storage
initial 64K
minextents 1
maxextents unlimited
Procedure:
create or replace procedure explicit2( month_val in varchar2) is
cursor explicit_cur is select dest_code from y_table where dest_code like '44%' order by dest_code desc;
dummy varchar2(100);
lv_length Number(9);
sqlstr varchar2(2500);
rec_count1 number;
rec_count2 number;
rec_count3 number;
begin
open explicit_cur;
LOOP
fetch explicit_cur into dummy;
EXIT WHEN explicit_cur%NOTFOUND;
rec_count1 :=0;
rec_count2 :=0;
rec_count3 :=0;
lv_length := length(dummy);
sqlstr := 'select count(*) from y_table_data1 t where t.fee_dur_1_1 <> 0
and t.out_trunk in (''MHISRM'', ''GEISRM'', ''GEIMRP'', ''MHIMRP'', ''13'', ''ITAX1B'', ''ITAX3B'',''ITAX5B'', ''ITAX6B'', ''ITAX7B'', ''BTIMRP'', ''BTI5RP'', ''BTI6RP'', ''BTI7RP'')
and t.service_code = ''00'' and substr(t.orig_called_num,1,'||lv_length||')='||''''||dummy||'''';
execute immediate sqlstr into rec_count1;
sqlstr := 'select count(*) from y_table_data1 t where t.fee_dur_1_2 <> 0
and t.out_trunk in (''MHISRM'', ''GEISRM'', ''GEIMRP'', ''MHIMRP'', ''13'',
''ITAX1B'',''ITAX3B'',''ITAX5B'', ''ITAX6B'', ''ITAX7B'', ''BTIMRP'', ''BTI5RP'', ''BTI6RP'', ''BTI7RP'')
and t.service_code = ''00'' and substr(t.orig_called_num,1,'||lv_length||')='||''''||dummy||'''';
execute immediate sqlstr into rec_count2;
sqlstr := 'select count(*) from y_table_data1 t where t.fee_dur_1_1 <> 0
and t.out_trunk in (''MHISRM'', ''GEISRM'', ''GEIMRP'', ''MHIMRP'', ''13'',
''ITAX1B'', ''ITAX3B'',''ITAX5B'', ''ITAX6B'', ''ITAX7B'', ''BTIMRP'', ''BTI5RP'', ''BTI6RP'', ''BTI7RP'')
and t.service_code = ''012'' and substr(t.orig_called_num,1,'||lv_length||')='||''''||dummy||'''';
execute immediate sqlstr into rec_count3;
if(rec_count1>0) then
sqlstr := 'insert into y_summary(BILL_DATE ,PREFIX, TRUNK_MGR,OUTCALLS , OUTDUR , IDD_FLAG , PK_FLAG )
select '|| month_val||' ,substr(t.orig_called_num,1,'||lv_length||'),t.trunkout_operator ,count(*) , round(sum(ceil(t.duration / 15) * 15) / 60, 0),''00'',''1'' from y_table_data1 t where t.fee_dur_1_1 <> 0
and t.out_trunk in (''MHISRM'', ''GEISRM'', ''GEIMRP'', ''MHIMRP'', ''13'', ''ITAX1B'', ''ITAX3B'',''ITAX5B'', ''ITAX6B'', ''ITAX7B'', ''BTIMRP'', ''BTI5RP'', ''BTI6RP'', ''BTI7RP'')
and t.service_code = ''00'' and substr(t.orig_called_num,1,'||lv_length||')='||''''||dummy||''''|| ' group by t.trunkout_operator,substr(t.orig_called_num,1,'||lv_length||')';
execute immediate sqlstr;
commit;
sqlstr :='DELETE from y_table_data1 t where t.fee_dur_1_1 <> 0
and t.out_trunk in (''MHISRM'', ''GEISRM'', ''GEIMRP'', ''MHIMRP'', ''13'', ''ITAX1B'', ''ITAX3B'',''ITAX5B'', ''ITAX6B'', ''ITAX7B'', ''BTIMRP'', ''BTI5RP'', ''BTI6RP'', ''BTI7RP'')
and t.service_code = ''00'' and substr(t.orig_called_num,1,'||lv_length||')='||''''||dummy||'''';
execute immediate sqlstr;
commit;
end if ;
if(rec_count2>0) then
sqlstr :='insert into y_summary(BILL_DATE ,PREFIX, TRUNK_MGR,OUTCALLS , OUTDUR , IDD_FLAG , PK_FLAG )
select '|| month_val||' ,substr(t.orig_called_num,1,'||lv_length||'),t.trunkout_operator ,count(*) , round(sum(ceil(t.duration / 15) * 15) / 60, 0),''00'',''0'' from y_table_data1 t where t.fee_dur_1_2 <> 0
and t.out_trunk in (''MHISRM'', ''GEISRM'', ''GEIMRP'', ''MHIMRP'', ''13'', ''ITAX1B'', ''ITAX3B'',''ITAX5B'', ''ITAX6B'', ''ITAX7B'', ''BTIMRP'', ''BTI5RP'', ''BTI6RP'', ''BTI7RP'')
and t.service_code = ''00'' group by t.trunkout_operator,substr(t.orig_called_num,1,'||lv_length||')';
execute immediate sqlstr;
commit;
sqlstr :='DELETE from y_table_data1 t where t.fee_dur_1_2 <> 0
and t.out_trunk in (''MHISRM'', ''GEISRM'', ''GEIMRP'', ''MHIMRP'', ''13'', ''ITAX1B'', ''ITAX3B'',''ITAX5B'', ''ITAX6B'', ''ITAX7B'', ''BTIMRP'', ''BTI5RP'', ''BTI6RP'', ''BTI7RP'')
and t.service_code = ''00'' and substr(t.orig_called_num,1,'||lv_length||')='||''''||dummy||'''';
execute immediate sqlstr;
commit;
end if;
if(rec_count3>0) then
sqlstr :='insert into y_summary(BILL_DATE ,PREFIX, TRUNK_MGR,OUTCALLS , OUTDUR , IDD_FLAG , PK_FLAG )
select '|| month_val||',substr(t.orig_called_num,1,'||lv_length||'),t.trunkout_operator ,count(*) , round(sum(ceil(t.duration / 15) * 15) / 60, 0),''012'',''0'' from y_table_data1 t where t.fee_dur_1_1 <> 0
and t.out_trunk in (''MHISRM'', ''GEISRM'', ''GEIMRP'', ''MHIMRP'', ''13'', ''ITAX1B'', ''ITAX3B'',''ITAX5B'', ''ITAX6B'', ''ITAX7B'', ''BTIMRP'', ''BTI5RP'', ''BTI6RP'', ''BTI7RP'')
and t.service_code = ''012'' group by t.trunkout_operator,substr(t.orig_called_num,1,'||lv_length||')';
execute immediate sqlstr;
commit;
sqlstr :='DELETE from y_table_data1 t where t.fee_dur_1_1 <> 0
and t.out_trunk in (''MHISRM'', ''GEISRM'', ''GEIMRP'', ''MHIMRP'', ''13'', ''ITAX1B'', ''ITAX3B'',''ITAX5B'', ''ITAX6B'', ''ITAX7B'', ''BTIMRP'', ''BTI5RP'', ''BTI6RP'', ''BTI7RP'')
and t.service_code = ''012'' and substr(t.orig_called_num,1,'||lv_length||')='||''''||dummy||'''';
execute immediate sqlstr;
commit;
end if;
end loop;
close explicit_cur;
end explicit2;
Edited by: user10951541 on 25.4.2010 12.08

Dear concern
Really sorry not to make format listing because i am amature to this blog.
my anwser to your way .
1. I have Tested my SQL statements manually in SQL*Plus. this runs ok
2. "Cursor loops, such as the one you have coded here, have been obsolete in Oracle since version 8i 12+ years ago.
Look up BULK COLLECT and FORALL in the docs and use them instead."
I am trying to make use of the BULK COLLECT and FORALL statement in proper location.
3. "Your procedure never performs a commit so no work actually takes place" i need to get the anwser why........................?
4. "On what basis was the decision made to use the default PCTFREE and PCTUSED values of 10 and 40?"
is there any problem if default is used..? if any suggestion........pls
5." You did not format your listing using the CODE tags as explained in the FAQ making your listing unreadable ... so I've not read it.
Please read the FAQ and use the proper way to post code so we can understand it. Then perhaps we can help you further. " really sorry not to make understandable to you..? but i will try from next post..
I really will try to be synced..
My aim is to make query to Table A using the cursor value like( '4422','442','4411','441','44') and get some data in accordance of these values.Then i put the data into another Table B. same time i need to delete the record from Table A containing the prefix value in accordance for example- i compute value for '4422' from Table A and put the computed value to Table B .Then i delete the record from Table A where prefix is '4422' .so that computed value for the next prefix '442' should contain the computed value for 442[0-1] and 442[3-9] .Same way it will be happened for ('4411','441','44'....bla...bla).
Thanks in advance..

Similar Messages

  • Call procedure that uses REF CURSOR?

    Can someone tell me how to call a procedure that uses a REF CURSOR?
    Procedure is something like this:
    PROCEDURE my_proc
    P_PROG_ID IN VARCHAR2,
    P_CRITERIA IN VARCHAR2,
    P_TASKCURSOR OUT MYREFCUR
    IS
    blah, blah blah
    I tried this to call the procedure:
    exec my_proc(variable1,variable2,variable3)
    but I don't know how to define variable3.
    Can someone help me out?

    Based on the parameters for the procedure, it looks like you have a cursor (myrefcursor) defined in a package somewhere. So, in sqlplus, you would need to do it in an anonymous block, something like:
    DECLARE
       l_cur package_name,myrefcur;
       variables to hold cursor fields
    BEGIN
       my_proc('ID', 'Criteria', l_cur);
       LOOP
          FETCH l_cur INTO variables to hold cursor fields
          EXIT WHEN l_cur%NOTFOUND;
          Do something with variables
       END LOOP;
       CLOSE l_cur;
    END;If you are on Oracle 9 or higher, assuming that myrefcursor is weakly typed,
    you could change the definition of the procedure to:
    PROCEDURE my_proc (p_prog_id    IN  VARCHAR2,
                       p_criteria   IN  VARCHAR2,
                       P_TASKCURSOR OUT SYS_REFCURSOR)then you could call it in sql plus like:
    -- Define the variables
    var var1 VARCHAR2(100);
    var var2 VARCHAR2(100);
    var cur  SYS_REFCURSOR;
    -- Assign Vlaues to the IN parameters
    EXEC :var1 := 'ID'; :var2 := 'Criteria';
    EXEC my_proc(:var1, :var2, :cur);
    -- See the contents of the cursor
    print curHTH
    John

  • Insert multiple records into a table(Oracle 9i) from a single PHP statement

    How can I insert multiple records into a table(Oracle 9i) from a single PHP statement?
    From what all I've found, the statement below would work if I were using MySQL:
         insert into scen
         (indx,share,expire,pitch,curve,surface,call)
         values
         (81202, 28, 171, .27, 0, 0, 'C' ),
         (81204, 28, 501, .25, 0, 0, 'C' ),
         (81203, 17, 35, .222, 0, 0, 'C' ),
         (81202, 28, 171, .27, 2, 0, 'C' ),
         (81204, 28, 501, .20, 0, 1, 'C' ),
         (81203, 28, 135, .22, 1, 0, 'C' )
    The amount of records varies into the multiple-dozens. My aim is to utilize the power of Oracle while avoiding the i/o of dozens of single-record inserts.
    Thank you,
    Will

    You could look at the INSERT ALL statement found in the documentation here:
    http://download.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_913a.htm#2133161
    My personal opinion is that you probably won't see any benefit because under the hood I think Oracle will still be doing single row inserts. I could be wrong though.
    The only way to confirm was if you did a test of multiple inserts vs an INSERT ALL, that is if the INSERT ALL met your requirements.
    HTH.

  • Using XI - RFC table and an Oracle stored procedure that returns a cursor.

    I need to create an interface using XI between an RFC table and an Oracle stored procedure that returns a cursor.  We are on oarcle 9.2 and  SP12.
    My stored procedure looks something like this:
    CREATE OR REPLACE
    PROCEDURE testproc_xi2 (p_recordset1 OUT SYS_REFCURSOR,
                                             in_quoteid IN varchar2 )
    AS
    BEGIN
      OPEN p_recordset1 FOR
       SELECT  q.quote_id,
                     q.modified_by,
                     q.quote_status,
                     q.total_cost
                FROM quote q
               WHERE q.quote_id = in_quoteid
                 AND q.total_cost > 0 ; 
    END testproc_xi2 ;
    My RFC has table and  one import parameter .
    I wanted to know how to create the data type for the ref cursor? and also for the table type in the RFC?
    CAN XI handle multi rows coming from a Stored procedure? Are there any other alternative methods if this is not supported?Any pointers to this would be helpful.
    I have called a Oracle SP from an RFC before, but that interface had one input parameter going to the stored procedure from the RFC and about 6 o/p parameters coming from the Stored procedure. This works fine.
    Thanks for the help.
    Mala

    Mala,
    i dont think there is anything called an rfc table...RFC stands for remote function call. That in essence would imply you need a rfc to jdbc connection.
    yes XI can handle multiple rows cooming from the the stored procedure if you have them mapped appropriately.
    Now as to how to create the data type within xi , you need to know what fields are going to be returned and whether they are nested and then just create them as you would for an xml
    for ex
    <Details>
      <FirstName>
    <LastName>
    </Details>
    that in xi would be smthing like
    Details  type of data occurence
    FirstName type of data occurence
    LastName type of data occurence.
    Hope that helps.
    If it does dont forget the points..:-)

  • Problem with Oracle procedure

    Hi,
    We have a problem with a Oracle procedure call using the Sql Execute
    Procedure statement.
    The call gives us this error :
    SYSTEM ERROR: (This error was converted)
    (This error was converted)
    OpenCursor failed for SQL statement in project LFB010, class
    ClsDemarreLFB010,
    method Demarre, methodId 4, line 32, error from database is:
    ORA-01036: illegal variable name/num
    Class: qqdb_ResourceException
    Distributed method called: qqdb_SessionProxy.OpenCursor!22 (object
    name
    instance/d4745a10-c8e4-11d1-97fd-90cad1e7aa77:0x196:0x4/lfb010_cl0/lfb010_cl
    0-fonctiondbservice0x196:0x2)
    from partition "LFB010_CL0_Client", (partitionId =
    D4745A10-C8E4-11D1-97FD-90CAD1E7AA77:0x196:0x4, taskId =
    [D4745A10-C8E4-11D1-97FD-90CAD1E7AA77:0x196.3]) in application
    "FTLaunch_cl0", pid 4290975297 on node LAXOU146 in environment
    CentralEnv
    Oracle error: 1036, Server: sipre_tcp, UserName: forte
    Database Statement: begin
    :qqReturnValue := AID_CUMUL_ELTVAL;
    end;
    Class: qqdb_ResourceException ..........
    And this is the TOOL code :
    BEGIN TRANSACTION
    TmpEtat : IntegerData = new;
    TmpEtat.SetValue (( SQL EXECUTE PROCEDURE AID_CUMUL_ELTVAL ON SESSION
    FonctionDBService ));
    Etat = TmpEtat.Value;
    END TRANSACTION;
    Our procedure has no parameter and when we put a dummy parameter to the
    procedure and pass it in the TOOL SQL statement, it works fine althoug the
    Fort&eacute; help says the parameter list is optionnal !
    We tried to execute the procedure in a "SQL Select OurProdecure Into ..."
    statement, but it does'nt work because there is a SQL update in the
    procedure and it is forbidden by Oracle.
    Has anyone seen this error before ?
    Any ideas would be greatly appreciated.
    Many thanks and regards,
    Manuel DEVEAUX
    Previade, France
    e-mail : deveauxpreviade.fr

    Hi,
    We have a problem with a Oracle procedure call using the Sql Execute
    Procedure statement.
    The call gives us this error :
    SYSTEM ERROR: (This error was converted)
    (This error was converted)
    OpenCursor failed for SQL statement in project LFB010, class
    ClsDemarreLFB010,
    method Demarre, methodId 4, line 32, error from database is:
    ORA-01036: illegal variable name/num
    Class: qqdb_ResourceException
    Distributed method called: qqdb_SessionProxy.OpenCursor!22 (object
    name
    instance/d4745a10-c8e4-11d1-97fd-90cad1e7aa77:0x196:0x4/lfb010_cl0/lfb010_cl
    0-fonctiondbservice0x196:0x2)
    from partition "LFB010_CL0_Client", (partitionId =
    D4745A10-C8E4-11D1-97FD-90CAD1E7AA77:0x196:0x4, taskId =
    [D4745A10-C8E4-11D1-97FD-90CAD1E7AA77:0x196.3]) in application
    "FTLaunch_cl0", pid 4290975297 on node LAXOU146 in environment
    CentralEnv
    Oracle error: 1036, Server: sipre_tcp, UserName: forte
    Database Statement: begin
    :qqReturnValue := AID_CUMUL_ELTVAL;
    end;
    Class: qqdb_ResourceException ..........
    And this is the TOOL code :
    BEGIN TRANSACTION
    TmpEtat : IntegerData = new;
    TmpEtat.SetValue (( SQL EXECUTE PROCEDURE AID_CUMUL_ELTVAL ON SESSION
    FonctionDBService ));
    Etat = TmpEtat.Value;
    END TRANSACTION;
    Our procedure has no parameter and when we put a dummy parameter to the
    procedure and pass it in the TOOL SQL statement, it works fine althoug the
    Fort&eacute; help says the parameter list is optionnal !
    We tried to execute the procedure in a "SQL Select OurProdecure Into ..."
    statement, but it does'nt work because there is a SQL update in the
    procedure and it is forbidden by Oracle.
    Has anyone seen this error before ?
    Any ideas would be greatly appreciated.
    Many thanks and regards,
    Manuel DEVEAUX
    Previade, France
    e-mail : deveauxpreviade.fr

  • Issue with a stored procedure that uses a sys refcursor to output dataset..

    Hi All:
    I create a stored procedure that uses an in out sys ref cursor:
    create or replace procedure FIRE_SALES_100_CALLS_REPORT
    ( p_cursor in out sys_refcursor)
    IS
    BEGIN
    --Insert into the temp table the records for the rep sales
    EXECUTE IMMEDIATE '
    INSERT INTO TMP_SALES_CNT_BY_USER
    TOTALPRODUCTSSOLD,
    NUMBEROFCALLS,
    SALESPER100CALLS,
    SERVICEORDERNUM,
    PRODUCT,
    LOGIN,
    FST_NAME,
    LAST_NAME,
    NAME,
    POSITIONHELD,
    CURRENTPARPARTYID,
    QUERY_DATE,
    CREATED_BY
    SELECT e.TotalProductsSold,
    e.NumberOfCalls,
    ((e.TotalProductsSold/e.NumberOfCalls)*100) AS SalesPer100Calls,
    e.ServiceOrderNum,
    e.Product,
    e.login,
    e.fst_name,
    e.last_name,
    e.name,
    e.PositionHeld,
    e.CurrentParPartyID,
    e.query_date,
    e.created_by
    FROM (
    SELECT COUNT(o.order_num) over ( partition by u.login
    order by u.login) AS TotalProductsSold,
    SUM(NVL(x.n_inbound,1) + NVL(x.n_outbound,1)) over (partition by u.login
    order by u.login) AS NumberOfCalls,
    o.order_num AS ServiceOrderNum,
    pi.name as Product,
    u.login,
    c.fst_name,
    c.last_name,
    postn.name,
    c.pr_held_postn_id as PositionHeld,
    p.par_party_id as CurrentParPartyID,
    NVL(x.query_date,NVL(o.last_upd, null)) AS query_date,
    o.created_by
    FROM firestg.SEB_S_order o
    INNER join firestg.seb_s_order_item oi ON o.row_id = oi.order_id
    INNER join firestg.seb_s_prod_int pi ON oi.prod_id = pi.row_id
    INNER join firestg.SEB_s_contact c on c.Row_Id = o.created_by
    INNER join firestg.SEB_s_user u on u.row_id = o.created_By
    INNER join firestg.SEB_s_party p on p.row_id = c.pr_held_postn_id
    INNER join firestg.SEB_s_postn postn on postn.row_id = c.pr_held_postn_id
    LEFT OUTER JOIN (
    SELECT taw.QUERY_DATE,
    vaw.n_inbound,
    vaw.n_outbound,
    oaw.object_name, oaw.object_id
    FROM GEN_T_AGENT_WEEK taw
    INNER JOIN GEN_V_AGENT_WEEK vaw ON taw.time_key = vaw.time_key
    INNER JOIN GEN_O_AGENT_WEEK oaw ON oaw.object_id = vaw.object_id) x
    ON u.cti_acd_userid = x.object_name
    WHERE NVL(x.query_date,NVL(o.last_upd, null)) BETWEEN (TRUNC (next_day (sysdate, ''SUN''))-14)
    AND (TRUNC (next_day (sysdate, ''SUN''))-8)
    AND o.status_cd IN (''Complete''))e';
    --Lookup the first level to see if there is a higher level person
    EXECUTE IMMEDIATE '
    UPDATE TMP_SALES_CNT_BY_USER a
    SET (ParPartyID_1ST, LOGIN_1ST,FST_NAME_1ST,LST_NAME_1ST,TITLE_1ST) =
    (SELECT pa.par_party_id,
    U.Login,
    C.FST_NAME,
    C.Last_Name,
    p.name
    FROM firestg.seb_s_postn p
    inner join firestg.seb_s_user U on u.Row_Id = p.pr_emp_id
    inner join firestg.seb_s_contact c on c.Row_Id = p.pr_emp_id
    INNER join firestg.SEB_s_party pa on pa.row_id = c.pr_held_postn_id
    WHERE p.row_id = a.currentparpartyid)
    WHERE CurrentParPartyID IS NOT NULL';
    --Lookup the second level to see if there is a higher level person
    EXECUTE IMMEDIATE '
    UPDATE TMP_SALES_CNT_BY_USER a
    SET (ParPartyID_2ND, LOGIN_2ND,FST_NAME_2ND,LST_NAME_2ND,TITLE_2ND) =
    (SELECT pa.par_party_id,
    U.Login,
    C.FST_NAME,
    C.Last_Name,
    p.name
    FROM firestg.seb_s_postn p
    inner join firestg.seb_s_user U on u.Row_Id = p.pr_emp_id
    inner join firestg.seb_s_contact c on c.Row_Id = p.pr_emp_id
    INNER join firestg.SEB_s_party pa on pa.row_id = c.pr_held_postn_id
    WHERE p.row_id = a.ParPartyID_1ST)
    WHERE a.ParPartyID_1ST IS NOT NULL';
    --Lookup the third level to see if there is a higher level person
    EXECUTE IMMEDIATE '
    UPDATE TMP_SALES_CNT_BY_USER a
    SET (ParPartyID_3RD, LOGIN_3RD,FST_NAME_3RD,LST_NAME_3RD,TITLE_3RD) =
    (SELECT pa.par_party_id,
    U.Login,
    C.FST_NAME,
    C.Last_Name,
    p.name
    FROM firestg.seb_s_postn p
    inner join firestg.seb_s_user U on u.Row_Id = p.pr_emp_id
    inner join firestg.seb_s_contact c on c.Row_Id = p.pr_emp_id
    INNER join firestg.SEB_s_party pa on pa.row_id = c.pr_held_postn_id
    WHERE p.row_id = a.ParPartyID_2ND)
    WHERE a.ParPartyID_2ND IS NOT NULL';
    --Lookup the fourth level to see if there is a higher level person
    EXECUTE IMMEDIATE '
    UPDATE TMP_SALES_CNT_BY_USER a
    SET (ParPartyID_4TH, LOGIN_4TH,FST_NAME_4TH,LST_NAME_4TH,TITLE_4TH) =
    (SELECT pa.par_party_id,
    U.Login,
    C.FST_NAME,
    C.Last_Name,
    p.name
    FROM firestg.seb_s_postn p
    inner join firestg.seb_s_user U on u.Row_Id = p.pr_emp_id
    inner join firestg.seb_s_contact c on c.Row_Id = p.pr_emp_id
    INNER join firestg.SEB_s_party pa on pa.row_id = c.pr_held_postn_id
    WHERE p.row_id = a.ParPartyID_3RD)
    WHERE a.ParPartyID_3RD IS NOT NULL';
    --Lookup the fifth level to see if there is a higher level person
    EXECUTE IMMEDIATE '
    UPDATE TMP_SALES_CNT_BY_USER a
    SET (ParPartyID_5TH, LOGIN_5TH,FST_NAME_5TH,LST_NAME_5TH,TITLE_5TH) =
    (SELECT pa.par_party_id,
    U.Login,
    C.FST_NAME,
    C.Last_Name,
    p.name
    FROM firestg.seb_s_postn p
    inner join firestg.seb_s_user U on u.Row_Id = p.pr_emp_id
    inner join firestg.seb_s_contact c on c.Row_Id = p.pr_emp_id
    INNER join firestg.SEB_s_party pa on pa.row_id = c.pr_held_postn_id
    WHERE p.row_id = a.ParPartyID_4TH)
    WHERE a.ParPartyID_4TH IS NOT NULL';
    -- If there was no 1st place then the rep is a VP
    EXECUTE IMMEDIATE '
    UPDATE TMP_SALES_CNT_BY_USER a
    SET a.vp = a.last_name || '', '' || a.fst_name,
    a.vp_login = a.login
    WHERE a.login_1st IS NULL';
    --If there is no second place then the rep has a VP and is a Director
    EXECUTE IMMEDIATE '
    UPDATE TMP_SALES_CNT_BY_USER a
    SET a.vp = a.lst_name_1st || '', '' || a.fst_name_1st,
    a.vp_login = a.login_1st,
    a.director = a.last_name || '', '' || a.fst_name,
    a.director_login = a.login
    WHERE a.login_1st IS NOT NULL
    AND a.login_2ND IS NULL';
    --IF there is no third place then the rep has a VP, Director & is a Manager
    EXECUTE IMMEDIATE '
    UPDATE TMP_SALES_CNT_BY_USER a
    SET a.vp = a.lst_name_2ND || '', '' || a.fst_name_2ND,
    a.vp_login = a.login_2ND,
    a.director = a.lst_name_1st || '', '' || a.fst_name_1st,
    a.director_login = a.login_1st,
    a.manager = a.last_name || '', '' || a.fst_name,
    a.manager_login = a.login
    WHERE a.login_1st IS NOT NULL
    AND a.login_2ND IS NOT NULL
    AND a.login_3rd IS NULL';
    --If there is no fourth place then the rep has a VP, Dir, Manager, and is a Supervisor
    EXECUTE IMMEDIATE '
    UPDATE TMP_SALES_CNT_BY_USER a
    SET a.vp = a.lst_name_3RD || '', '' || a.fst_name_3RD,
    a.vp_login = a.login_3RD,
    a.director = a.lst_name_2ND || '', '' || a.fst_name_2ND,
    a.director_login = a.login_2ND,
    a.manager = a.lst_name_1st || '', '' || a.fst_name_1st,
    a.manager_login = a.login_1st,
    a.supervisor = a.last_name || '', '' || a.fst_name,
    a.supervisor_login = a.login
    WHERE a.login_1st IS NOT NULL
    AND a.login_2ND IS NOT NULL
    AND a.login_3rd IS NOT NULL
    AND a.login_4th IS NULL';
    --If there is no fifth plance then the rep has a VP, Dir, Mgr, Supervisor, and is a Team Lead
    EXECUTE IMMEDIATE '
    UPDATE TMP_SALES_CNT_BY_USER a
    SET a.vp = a.lst_name_4TH || '', '' || a.fst_name_4TH,
    a.vp_login = a.login_4TH,
    a.director = a.lst_name_3RD || '', '' || a.fst_name_3RD,
    a.director_login = a.login_3RD,
    a.manager = a.lst_name_2ND || '', '' || a.fst_name_2ND,
    a.manager_login = a.login_2ND,
    a.supervisor = a.lst_name_1st || '', '' || a.fst_name_1st,
    a.supervisor_login = a.login_1st,
    a.teamlead = a.last_name || '', '' || a.fst_name,
    a.teamlead_login = a.login
    WHERE a.login_1st IS NOT NULL
    AND a.login_2ND IS NOT NULL
    AND a.login_3rd IS NOT NULL
    AND a.login_4th IS NOT NULL
    AND a.login_5th IS NULL';
    --If there is a fifth place then the rep has a VP, Dir, Mgr, Supervisor, Team Lead and is a rep
    EXECUTE IMMEDIATE '
    UPDATE TMP_SALES_CNT_BY_USER a
    SET a.vp = a.lst_name_5TH || '', '' || a.fst_name_5TH,
    a.vp_login = a.login_5TH,
    a.director = a.lst_name_4TH || '', '' || a.fst_name_4TH,
    a.director_login = a.login_4TH,
    a.manager = a.lst_name_3RD || '', '' || a.fst_name_3RD,
    a.manager_login = a.login_3RD,
    a.supervisor = a.lst_name_2ND || '', '' || a.fst_name_2ND,
    a.supervisor_login = a.login_2ND,
    a.teamlead = a.lst_name_1st || '', '' || a.fst_name_1st,
    a.teamlead_login = a.login_1st
    WHERE a.login_1st IS NOT NULL
    AND a.login_2ND IS NOT NULL
    AND a.login_3rd IS NOT NULL
    AND a.login_4th IS NOT NULL
    AND a.login_5th IS NOT NULL';
    open p_cursor for
    SELECT tsc.vp,
    tsc.director,
    tsc.manager,
    tsc.supervisor,
    tsc.teamlead,
    (tsc.last_name || ', ' || tsc.fst_name) AS Rep,
    tsc.product,
    tsc.totalproductssold,
    tsc.numberofcalls,
    tsc.salesper100calls
    FROM TMP_SALES_CNT_BY_USER tsc;
    END FIRE_SALES_100_CALLS_REPORT;
    The table I use is a Global temp table.
    This runs just fine in oracle but when I try to build a data foundation in Business Objects I get the error that says you cannot insert/update/delete in a READ ONLY Transaction.
    I really need some advice on what to do since I really dont have access to a scheduled script and table that would store my data ahead of time.

    Well, AFAIK, BO is a reporting tool, so it si read-only by nature. I do not know if it possible to "tell" BO table is GTT and it is OK to write to it. You need to post this in BO forum.
    SY.

  • How to Execute Remote procedures that use DBLinks?

    Using Oracle 10g (RAC Linux) to remote connect Windows 10g to dblink to AS/400 <
    <I have created a procedure that I execute remotely by issuing the following:
    CALL GLOBAL.REFRESH_STAGING@KRONOSLINK();
    The procedure errors as
    Error at line 2
    ORA-20001: ERROR OCCURED
    ORA-06512: at "GLOBAL.REFRESH_STAGING", line 47
    ORA-06512: at line 1
    The procedure runs without error from the host database. The problem is when the procedure makes a call to the dblink.
    I unsuccessfully attempted to capture the error message.
    Question: Is it possible to execute remote procedures that use dblinks? If so, How is that accomplished.
    Question: What is the proper way to handle exceptions in this case?
    Bonus: What can be done to improve this procedure? (Suggestions, like adding return on the procedure).
    CREATE OR REPLACE PROCEDURE GLOBAL.REFRESH_STAGING IS
    NOOBJECT EXCEPTION;
    OBJECTEXIST EXCEPTION;
    PRAGMA EXCEPTION_INIT(NOOBJECT, -00942); -- Exception handling for ORA-00942 - table or view does not exist
    PRAGMA EXCEPTION_INIT(OBJECTEXIST, -00955); -- Exception handling for ORA-009555 - name is already used by an existing object
    sT LONG := '';
    sS LONG := '';
    sST LONG := '';
    cursor csrO is
    SELECT
    SCHEMANAME,
    TABLENAME
    FROM GLOBAL.STAGING_TABLES;
    csrR csrO%ROWTYPE;
    BEGIN
    FOR csrR IN csrO
    LOOP
    sT := csrR.TABLENAME;
    sS := csrR.SCHEMANAME;
    sST := sS || '.' || sT;
    BEGIN
    EXECUTE IMMEDIATE 'drop table global.' || sT || ' purge';
    EXCEPTION
    WHEN NOOBJECT THEN
    NULL;
    WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE(DBMS_UTILITY.FORMAT_CALL_STACK);
    DBMS_OUTPUT.PUT_LINE(DBMS_UTILITY.FORMAT_ERROR_STACK);
    RAISE_APPLICATION_ERROR (-20001, 'ERROR OCCURED');
    END;
    BEGIN
    EXECUTE IMMEDIATE 'create table global.' || sT || ' nologging as select * from ' || sST || '@thebosslink';
    COMMIT;
    EXCEPTION
    WHEN OBJECTEXIST THEN
    NULL;
    WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE(DBMS_UTILITY.FORMAT_CALL_STACK);
    DBMS_OUTPUT.PUT_LINE(DBMS_UTILITY.FORMAT_ERROR_STACK);
    DBMS_OUTPUT.PUT_LINE(SQLCODE || ' - ' || SQLERRM);
    RAISE_APPLICATION_ERROR (-20001, 'ERROR OCCURED');
    END;
    END LOOP;
    END REFRESH_STAGING;
    Thanks,
    blevels

    SET LINESIZE 500;
    COLUMN DB_LINK FORMAT a20
    COLUMN HOST FORMAT a20
    COLUMN USERNAME FORMAT a20
    COLUMN OWNER FORMAT a10
    COLUMN TABLE_NAME FORMAT a20
    select db_link,username, host from all_db_links where db_link = 'KRONOSLINK';
    select privilege from dba_sys_privs where grantee = 'SYSTEM';
    select owner, table_name from dba_tab_privs where grantee='SYSTEM';
    DBLINK_ USERNAME HOST
    KRONOSLINK SYSTEM ORCL
    1 row selected.
    PRIVILEGE
    GLOBAL QUERY REWRITE
    CREATE MATERIALIZED VIEW
    CREATE TABLE
    UNLIMITED TABLESPACE
    SELECT ANY TABLE
    5 rows selected.
    OWNER TABLENAME_
    SYS INCEXP
    SYS INCEXP
    SYS INCEXP
    SYS INCEXP
    SYS INCEXP
    SYS INCEXP
    SYS INCEXP
    SYS INCEXP
    SYS INCEXP
    SYS INCEXP
    SYS INCEXP
    SYS INCVID
    SYS INCVID
    SYS INCVID
    SYS INCVID
    SYS INCVID
    SYS INCVID
    SYS INCVID
    SYS INCVID
    SYS INCVID
    SYS INCVID
    SYS INCVID
    SYS INCFIL
    SYS INCFIL
    SYS INCFIL
    SYS INCFIL
    SYS INCFIL
    SYS INCFIL
    SYS INCFIL
    SYS INCFIL
    SYS INCFIL
    SYS INCFIL
    SYS INCFIL
    SYS DBMS_ALERT
    SYS DBMS_SYS_ERROR
    SYS DBMS_RULE_EXIMP
    SYS DBMS_AQ
    SYS DBMS_AQADM
    SYS DBMS_AQ_IMPORT_INTER
    NAL
    SYS DBMS_AQELM
    SYS DBMS_TRANSFORM_EXIMP
    SYS SYS_GROUP
    SYS DBMS_DEFER_IMPORT_IN
    TERNAL
    SYS DBMS_REPCAT
    WMSYS WM$UDTRIG_INFO
    SYS SET_TABLESPACE
    SYS CHECK_UPGRADE
    SYS AVINASH
    SYS AVINASH
    SYS AVINASH1
    SYS AVINASH1
    SYS DB_PMP
    SYS DB_PMP
    SYS DIR_TESTCASE
    SYS DIR_TESTCASE
    SYS EXPORT_FULL_DIR
    SYS EXPORT_FULL_DIR
    SYS PUMP
    SYS PUMP
    SYS LOGS
    SYS LOGS
    SYS DPUMP_DIR2
    SYS DPUMP_DIR2
    SYS AVIS
    SYS AVIS
    SYS DPDIR_LCLLGS
    SYS DPDIR_LCLLGS
    67 rows selected.
    Edited by: user10860953 on Jan 28, 2010 10:43 AM

  • How to call a stored procedure that use a type defined in a package?

    Hi all,
    this is stored procedure:
    GET_GIORNATAEVENTO( in_nome_servizio IN VARCHAR2,
    out_dati_aggiornati OUT TAB_VARCHAR2);
    TAB VARCHAR2 is defined in the package specification:
    TYPE tab_varchar2 IS TABLE OF VARCHAR2(5) INDEX BY BINARY_INTEGER;
    and this is the name of the package: PKG_SERVIZI_MMSPUSH.
    This is my php script:
    <?php
    // Connect to database...
    $c=OCILogon("venus_vfl", "venus_vfl", "venvi");
    if ( ! $c ) {
    echo "Connessione non riuscita: " . var_dump( OCIError() );
    die();
    echo "<br>PKG_SERVIZI_MMSPUSH.GET_GIORNATAEVENTO</br> ";
    echo "<br> </br>";
    // Call database procedure...
    $in_servizio = "MOTO";
    $s = OCIParse($c, "begin PKG_SERVIZI_MMSPUSH.GET_GIORNATAEVENTO(:bind1, :bind2); end;");
    OCIBindByName($s, ":bind1", $in_servizio);
    OCIBindByName($s, ":bind2", $out_esito);
    OCIExecute($s,OCI_DEFAULT);
    echo "OUT_DATI_AGGIORNATI= " . $out_esito;
    // Logoff from Oracle
    OCILogoff($c);
    ?>
    How to test stored procedure to get the output parameter?
    Thanks in advance.

    Thanks,
    but I need to test stored procedures that uses type defined in the package.
    e.g.
    if I have s.p.
    PROCEDURE get_risultati_squadra
    ( in_squadra IN VARCHAR2,
    out_serie OUT tab_varchar2_5,
    out_tiporisultato OUT tab_varchar2_5,
    out_n_giornata OUT tab_varchar2_5,
    out_squadre OUT tab_varchar2_200,
    out_risultato OUT tab_varchar2_10,
    out_marcatore OUT tab_varchar2_50,
    out_punti OUT tab_varchar2_3,
    out_rimbalzista OUT tab_varchar2_50,
    out_rimbalzi OUT tab_varchar2_3,
    out_esito OUT tab_varchar2_2);
    I have to define every type external to the package, in this case five new TYPE !!
    Is there another way to solve this problem?
    Thanks

  • Stored procedure that returns a cursor (result set)

    Hi,
    We have a stored procedure that returns a cursor (result set) but when I compliled it and catalouged (introspected) it in the OBPM I got all the primitive type parameters (either IN or OUT) in the proc call except the cursor type (the result set) which is the out param of the stored proc.
    Any pointers please?
    Thanks

    Result set is of RowType and is not supported as a Stored Procedure as far as I know.
    HTH
    Sharma

  • Function calling stored procedure that returns a cursor into a LOV

    Hello,
    Is it possible in HTML DB to implement a process that has a function that calls a stored procedure that returns a cursor, used to then populate a select list?
    Or can I do a function call to a stored procedure in the 'List of values definition' box for the item itself that returns a cursor to populate the item's select list?

    Hi Vikas,
    Actually, I just found another posting that shows how to do what I'm looking for:
    Re: Filling a LOV with a cursor
    Check it out. I posted another question in response to that discussion...maybe you could answer that? Thanks!
    Laura

  • How to execute stored procedure that returns a cursor?

    How to execute a stored procedure that returns a cursor?
    Follow the code:
    CREATE OR REPLACE PROCEDURE stp_cashin_grupo
    (p_func IN VARCHAR
    ,p_cod_grup IN Integer
    ,p_des_grup IN VARCHAR
    ,p_logi IN VARCHAR
    ,p_curs_rset OUT infoc.pck_cashin_grupo.curs_rset
    IS
    BEGIN
    if p_func = '1' then
    OPEN p_curs_rset FOR
    select
    cod_grup
    ,des_grup
    ,dat_manu_grup
    ,des_logi_manu
    from infoc.tbl_cashin_grupo
    order by des_grup;
    end if;
    END stp_cashin_grupo;
    and the package:
    CREATE OR REPLACE PACKAGE pck_cashin_grupo
    AS
    TYPE curs_rset IS REF CURSOR;
    END pck_cashin_grupo;
    My question is how to execute in sql plus?
    EXEC stp_cashin_grupo('1',0,'','465990', my doubt is how to pass the cursor as return
    Thanks

    my doubt is how to pass the cursor as returnExample :
    TEST@db102 > var c1 refcursor;
    TEST@db102 > create or replace procedure ref1 (
      2     v1 in varchar2,
      3     cur1 out sys_refcursor)
      4  is
      5  begin
      6     open cur1 for 'select * from '||v1;
      7  end;
      8  /
    Procedure created.
    TEST@db102 > exec ref1('dept',:c1);
    PL/SQL procedure successfully completed.
    TEST@db102 > print c1
        DEPTNO DNAME          LOC
            10 ACCOUNTING     NEW YORK
            20 RESEARCH       DALLAS
            30 SALES          CHICAGO
            40 OPERATIONS     BOSTON
    TEST@db102 >

  • Multiple record insert thru PROCEDURE - Urgent

    All,
    My requirement is, I have to invoke a procedure which accepts two input and 1 out variable. The operation of the procedure is to insert the data to two tables(head_tab and line_tab-accepts multiple record). I used %rowtype for the two inputs i.e procedure proc(head_var head_tab%rowtype, line_var line_tab%rowtype, out_var out number). The incoming doc comes from 3rd party application which sends a header record and multiple line record for the same header.
    I used the transformation activity, to insert line record I used for-each loop for multiple record. But %rowtype being a scalar data type, it doesn't accept array of record to it! I'm stuck here. Can we achieve this scenario with using of procedure? or should I configure DBAdapter to insert the data directly to the table rather the procedure does this? If we can achieve it thru procedure, how can I go about?
    Thanks,
    Sen

    Hi,
    I believe you should change the signature of the procedure.
    I tried below code for my proc to send multiple records without use of for loop.
    Type line_var_rec IS RECORD(
    Var1;
    var2;
    Type line_var_tab IS TABLE OF line_var_rec INDEX BY BINARY INTEGER;
    Type head_var_rec IS RECORD(
    var3;
    var4;
    line_var line_var_tab ;
    Type head_var_tab IS TABLE OF head_var_rec INDEX BY BINARY INTEGER;
    proc(head_var IN head_var_tab, out_var out number);
    With the above code you can insert multiple header records each having multiple line records.
    Pls let me know if u have any questions.

  • Recurrent single record Insert problems

    Hi,
    we have on production environment a Java based application that makes aprox 40.000 single record Inserts per hour into a table.
    We ha traced the performance of this Insert and the medium time is 3ms, that is ok. Our Java architecture is based in Websphere Application Server and we access to Oracle 10g through a WAS datasource.
    But we have detected that 3 or 4 times a day, during aprox 30 seconds, the Java service is not able to make any insertion in that table. And suddenly it makes all the "queued inserts" in only 1 second. That "pause" in the insertion cause problems of navigation because is the top layer there is a web application.
    We are sure that is not a problem with the WAS or the Java code. We are sure that is a problem with the Oracle configuration, or some tunning action for this kind of applications that we don´t know. We first thought it could be a problem with a sequence field in the table. Also, a problem when occurs the change of the redo log. But we've checked it with our DBA and this is not the problem.
    Has anybody any idea of what could be the origin of this extrange behaviour?
    Thanks a lot in advance.
    Jose.

    If by one single disk you mean a single physical disk then spreading the online redo lobs onto multiple disks would be a good idea. Log Group A should be on a seperate disk from Log Group B and the members of each log group should also be on seperate disks.
    Note that Oracle does not stop processing when it does a checkpoiint. Here is basically how it works. When online redo LogA fills a checkpoint is signaled and Oracle immediately starts writing to LogB. The ckeck point is processed by ckpt and dbwr.
    If logB fills and a switch to LogC occurs before the ckeckpoint signaled by the switch from LogA to LogB has completed then you get the checkpoint not complete information message. Oracle will continue processing though it has more work to do having to combine two ckeckpoints. If the problem continues then you get 3 and 4 checkpoints backed up. This will bog Oracle down as the buffer cache has to be pretty full at this point. You cannot read data unless you have a clean buffer to read into.
    The checkpoint not complete message normally means your online redo logs are too small and are filling too quickly. In the absence of Data Guard configured to use log shipping you should look to see how many log switches you are doing per day. If is is more the 24 - 48 then increase the size of the online redo logs.
    Database writer performance issues are the next area you would want to ckeck after properly sizing the online redo logs and verifying the IO performance of log writer. Pretty much all you can do to help log writer IO is put enough physical disk under the logs to spread the IO out.
    If your problem is caused by the activity level during peak periods then setting MTTR probably will not help since dbwr will be busy writing anyway.
    You really should run a statspack or AWR report to help clarify the issue.
    If you determine you are switching online redo logs too many times and increase the size take a set of statspack both before and after you make the change. This will help you see the effect on the database as a whole.
    HTH -- Mark D Powell --

  • Multiple records insertion

    Hi,
    How to insert multiple records at a time using stored procedure.
    Please give me example.
    Regards,
    Kiran

    Kiran,
    If you want to use "variable-number-of-parameters", you need to use array:
    http://stackoverflow.com/questions/980324/oracle-variable-number-of-parameters-to-a-stored-procedure?tab=votes#tab-top
    Best Regards,
    Gokhan Atil
    If this question is answered, please mark appropriate posts as correct/helpful and the thread as closed. Thanks

  • Issu for running insert statement in oracle procedure.

    Hi expert,
    I ran a oracle procedure with a insert statement inside as:
    insert into table1 select....
    but I got error message related to this insert statement as "SQLERRM= ORA-08103: object no longer exists"
    I ran this statement separately in toad, no error message, but no data result from this execute.
    please tell how to fix this issue.
    Many Thanks,
    Edited by: 918440 on 27-Jun-2012 8:04 AM

    Hi friend,
    my insert statement is as follows:
            INSERT INTO HIROC_RU_FACT_S   
            select   
                    pp.policy_fk,  
                    pp.transaction_log_fk,  
                    p.policy_no,  
                    p.policy_type_code,   
                    hiroc_rpt_user.hiroc_get_entity_name(pp.policy_fk,'POLHOLDER')  policy_holder,  
                    pp.risk_fk,   
                    r.risk_base_record_fk,   
                    r.entity_fk,  
                    hiroc_sel_entity_risk_name2 (pp.risk_fk,r.entity_fk)  risk_name,   
                    substr(trim(nvl(r.county_code_used_to_rate,pth.issue_state_code)),1,2) rating_state_code,  
                    hiroc_get_province_name(substr(trim(nvl(r.county_code_used_to_rate,pth.issue_state_code)),1,2), 'PROVINCE_CODE', 'L') rating_state_name,  
                    hiroc_get_provicne_pol_prefix(substr(trim(nvl(r.county_code_used_to_rate,pth.issue_state_code)),1,2),p.policy_type_code) rating_prov_pol_prefix,   
                    nvl(r.risk_cls_used_to_rate,pth.peer_groups_code) rating_peer_group_code,  
                    hiroc_get_lookup_desc('PEER_GROUP',nvl(r.risk_cls_used_to_rate,pth.peer_groups_code),'L')  rating_peer_group_name,   
                    pth.policy_term_history_pk,   
                    pth.term_base_record_fk,   
                    to_char(pth.effective_from_date,'yyyy') term_effective_year,   
                    c.coverage_pk,   
                    c.coverage_base_record_fk,   
                    pc.coverage_code,   
                    c.product_coverage_code,   
                    pc.long_description,   
                    pp.coverage_component_code,  
                    c.effective_from_date,   
                    c.effective_to_date,  
                    cls.coverage_code coverage_class_code,   
                    cls.coverage_long_desc coverage_class_long_desc,   
                    decode(pp.coverage_component_code ,'GROSS',cls.exposure_unit,null) exposure_unit, --hiroc_get_expos_units_by_cov(c.coverage_pk,pc.coverage_code,c.effective_from_date,c.effective_to_date) exposure_unit,   
                    decode(pp.coverage_component_code ,'GROSS',cls.number_of_patient_day,null) number_of_patient_day,   
                    pth.effective_from_date  term_eff_from_date,   
                    pth.effective_to_date term_eff_to_date,    
                    pp.premium_amount premium_amount,    
                    (case when (pc.coverage_code in ('CP','MC1','MC2','MC3','MC4','HR','F') or pc.coverage_code like 'ST%') and  
                                  pp.coverage_component_code != 'RISKMGMT' then     
                            (nvl(pp.premium_amount,0))  
                        else  
                            0  
                    end) primary_premium,   
                    (hiroc_get_risk_units(hiroc_get_provicne_pol_prefix(substr(trim(nvl(r.county_code_used_to_rate,pth.issue_state_code)),1,2),p.policy_type_code)-- rating_prov_pol_prefix  
                                        ,nvl(r.risk_cls_used_to_rate,pth.peer_groups_code) -- rating_peer_group_code  
                                        ,cls.coverage_code --coverage_class_code  
                                        ,decode(pp.coverage_component_code ,'GROSS',cls.exposure_unit,null)  
                                        ,pp.premium_amount  
                                        ,(case when (pc.coverage_code in ('CP','MC1','MC2','MC3','MC4','HR','F') or pc.coverage_code like 'ST%') and  
                                                      pp.coverage_component_code != 'RISKMGMT' then     
                                                (nvl(pp.premium_amount,0))  
                                            else  
                                                0  
                                         end)  -- primary_premium  
                                        ,p.policy_type_code           
                                        ,trunc(pth.effective_to_date))) risk_units  
             from     proddw_mart.rmv_territory_makeup tm,  
                      proddw_mart.rmv_premium_class_makeup pcm,  
                      proddw_mart.rmv_product_coverage pc,  
                      proddw_mart.rmv_coverage c,  
                      proddw_mart.rmv_risk r,  
                      proddw_mart.rmv_policy_term_history pth,  
                      proddw_mart.rmv_policy p,  
                      proddw_mart.rmv_transaction_log tl,  
                      proddw_mart.rmv_policy_premium pp,  
                      (select  /* +rule */  
                               p.policy_no,  
                               p.policy_start_date,  
                               p.policy_end_date,   
                               r.risk_pk,  
                               r.risk_description,  
                               c.coverage_pk,  
                               c.parent_coverage_base_record_fk,  
                               pc.parent_product_covg_code,  
                               pc.coverage_code,  
                               pc.short_description coverage_short_desc,   
                               pc.long_description coverage_long_desc,  
                               c.exposure_unit,  
                               pc.exposure_basis_code,  
                               c.number_of_patient_day,  
                               p.policy_start_date policy_effective_date,  
                               p.policy_end_date policy_expiry_date,  
                               c.effective_from_date,  
                               c.effective_to_date,  
                               to_char(c.effective_from_date,'YYYY') class_eff_year  
                        from   proddw_mart.odwr_coverage_only      c  
                              ,proddw_mart.odwr_product_coverage   pc  
                              ,proddw_mart.odwr_risk               r  
                              ,proddw_mart.odwr_policy             p  
                        where  pc.code                 = c.product_coverage_code  
                          and  pc.parent_product_covg_code is not null                 -- coverage classes only  
                          and  r.risk_pk = c.risk_base_record_fk  
                          and  c.accounting_to_date = to_date('1/1/3000','mm/dd/yyyy') -- only open records  
                          and  c.base_record_b = 'N'  
                          and  p.base_record_b = 'N'  
                          and  p.policy_pk = r.policy_fk  
                          and  p.accounting_to_date = to_date('1/1/3000','mm/dd/yyyy')  -- only open records  
                       group by p.policy_no,  
                               p.policy_start_date,  
                               p.policy_end_date,   
                               r.risk_pk,  
                               r.risk_description,  
                               c.coverage_pk,  
                               c.parent_coverage_base_record_fk,  
                               pc.parent_product_covg_code,  
                               pc.coverage_code,  
                               pc.short_description, -- coverage_short_desc,   
                               pc.long_description, -- coverage_long_desc,  
                               c.exposure_unit,  
                               pc.exposure_basis_code,  
                               c.number_of_patient_day,  
                               p.policy_start_date, -- policy_effective_date,  
                               p.policy_end_date, -- policy_expiry_date,  
                               c.effective_from_date,  
                               c.effective_to_date,  
                               to_char(c.effective_from_date,'YYYY')-- class_eff_year  
                      ) cls  
                where    tm.risk_type_code = r.risk_type_code  
                and        tm.county_code = r.county_code_used_to_rate  
                and        tm.effective_from_date <= pp.rate_period_from_date  
                and        tm.effective_to_date   >  pp.rate_period_from_date  
                and        pcm.practice_state_code (+) = r.practice_state_code  
                and        pcm.risk_class_code (+) = r.risk_cls_used_to_rate  
                and        nvl(pcm.effective_from_date, pp.rate_period_from_date) <= pp.rate_period_from_date  
                and        nvl(pcm.effective_to_date, to_date('01/01/3000','mm/dd/yyyy')) > pp.rate_period_from_date  
                and        pc.code = c.product_coverage_code  
                and        c.base_record_b = 'N'  
                and        ( c.record_mode_code = 'OFFICIAL'  
                         and (c.closing_trans_log_fk is null or  
                              c.closing_trans_log_fk != tl.transaction_log_pk)  
                         or c.record_mode_code = 'TEMP'  
                         and c.transaction_log_fk = tl.transaction_log_pk )  
                and   c.parent_coverage_base_record_fk is null  
                and        c.effective_from_date  <  c.effective_to_date  
                and        c.effective_from_date  <= pp.rate_period_from_date  
                and        c.effective_to_date    >  pp.rate_period_from_date  
                and   c.accounting_from_date <= tl.accounting_date  
                and   c.accounting_to_date   >  tl.accounting_date  
                and        c.coverage_base_record_fk=pp.coverage_fk  
                and        r.base_record_b = 'N'  
                and        ( r.record_mode_code = 'OFFICIAL'  
                        and (r.closing_trans_log_fk is null or  
                             r.closing_trans_log_fk != tl.transaction_log_pk)  
                        or r.record_mode_code = 'TEMP'  
                        and r.transaction_log_fk = tl.transaction_log_pk )  
                and        r.effective_from_date  <  r.effective_to_date  
                and        r.effective_from_date  <= pp.rate_period_from_date  
                and        r.effective_to_date    >  pp.rate_period_from_date  
                and   r.accounting_from_date <= tl.accounting_date  
                and   r.accounting_to_date   >  tl.accounting_date  
                and         r.risk_base_record_fk = pp.risk_fk  
                and        pth.base_record_b = 'N'  
                and        ( pth.record_mode_code = 'OFFICIAL'  
                        and (pth.closing_trans_log_fk is null or  
                             pth.closing_trans_log_fk != tl.transaction_log_pk)  
                        or pth.record_mode_code = 'TEMP'  
                        and pth.transaction_log_fk = tl.transaction_log_pk )  
                and        pth.accounting_from_date <= tl.accounting_date  
                and        pth.accounting_to_date   >  tl.accounting_date  
                and        pth.term_base_record_fk = pp.policy_term_fk  
                and   p.policy_pk = pp.policy_fk  
                and        tl.transaction_log_pk  =  pp.transaction_log_fk  
                and   pp.active_premium_b = 'Y'  
                and        pp.rate_period_type_code in ('CS_PERIOD','SR_PERIOD')  
                and        pp.rate_period_to_date > pp.rate_period_from_date  
                and tl.accounting_date <= sysdate   
                and p.policy_cycle_code = 'POLICY'  
                and substr(p.policy_no,1,1) <> 'Q'  
                and tl.transaction_log_pk = (select max(pp.transaction_log_fk)  
                                               from proddw_mart.rmv_policy_premium pp,proddw_mart.rmv_transaction_log tl2  
                                              where pth.term_base_record_fk = pp.policy_term_fk  
                                                and pp.transaction_log_fk = tl2.transaction_log_pk  
                                                and tl2.accounting_date <= sysdate )    
                 and p.policy_type_code in ('LIABCRIME','MIDWIFE')    
                 and pth.accounting_to_date =  to_date('01/01/3000','mm/dd/yyyy') --<<<*******  eliminates duplicates  
                 and p.policy_no = cls.policy_no  
            --     and r.risk_pk = cls.risk_pk  
                 and c.coverage_base_record_fk = cls.parent_coverage_base_record_fk(+)  
                 and  cls.effective_from_date < pth.effective_to_date -- from date less than period end date  
                 and  cls.effective_to_date   > pth.effective_from_date -- to date greater than period start date  
                 and  cls.policy_effective_date   < pth.effective_to_date -- from date less than period end date  
                 and  cls.policy_expiry_date     > pth.effective_from_date -- to date greater than period start date  
           group by pp.policy_fk,  
                    pp.transaction_log_fk,  
                    p.policy_no,  
                    p.policy_type_code,   
                    pp.risk_fk,   
                    r.risk_base_record_fk,   
                    r.entity_fk,  
                    substr(trim(nvl(r.county_code_used_to_rate,pth.issue_state_code)),1,2), -- rating_state_code,  
                    r.county_code_used_to_rate,  
                    pth.issue_state_code,  
                    nvl(r.risk_cls_used_to_rate,pth.peer_groups_code) , --  rating_peer_group_code,  
                    r.risk_cls_used_to_rate,  
                    pth.peer_groups_code,  
                    pth.policy_term_history_pk,   
                    pth.term_base_record_fk,   
                    to_char(pth.effective_from_date,'yyyy'), --term_effective_year,   
                    c.coverage_pk,   
                    c.coverage_base_record_fk,   
                    pc.coverage_code,   
                    c.product_coverage_code,   
                    pc.long_description,   
                    pp.coverage_component_code,  
                    c.effective_from_date,   
                    c.effective_to_date,  
                    cls.coverage_code, -- coverage_class_code,   
                    cls.coverage_long_desc, -- coverage_class_long_desc,   
                    decode(pp.coverage_component_code ,'GROSS',cls.exposure_unit,null),-- exposure_unit,   
                    decode(pp.coverage_component_code ,'GROSS',cls.number_of_patient_day,null), -- number_of_patient_day,   
                    pth.effective_from_date, --term_eff_from_date,   
                    pth.effective_to_date, --, --term_eff_to_date,    
                    pp.premium_amount ;Edited by: BluShadow on 27-Jun-2012 16:12
    added {noformat}{noformat} tags for readability.  PLEASE READ {message:id=9360002} AS PREVIOUSLY REQUESTED!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           &

Maybe you are looking for