Run a procedure ON-INSERT

I am on an Oracle 10.2.0.4.0 database. I struggled if I should post the question here or in the General Questions forum, but decided to start here first.
I need to create a table that will be populated by another database probably 1000 times per a 24 hour day. The data will be populated via a database link via a SQL INSERT statement then committed. As far as the user of the other database is concerned, once they do the insert they are finished.
As the owner of the database that now has a new record in it, I need to process that new record. Basically, the table that was inserted into was a "staging" table. I want to pull the data from that table and populate various tables in my database with that information, then remove the record from the "staging" table and I would like to do that as close to "real-time" as possible.
The first thought that came in my mind was to create an ON INSERT trigger on the "staging" table that would call a procedure to move the data to the appropriate tables then remove the record from the "staging" table, but I figured that I would receive a "mutating table" error. I tried it and that is exactly what happened. My DBA recommended that I attempt to do the same thing with a Global Temporary table that removes the data on insert. It sounded good, but when I tried it, I received the same "mutating trigger" error.
Below are the statements to create the objects:
-- This will emulate the table that a user from another database will insert a record into.
create global temporary table temp_staging_table
(pk_id         number(5),
data_1        varchar2(10),
data_2        varchar2(10),
data_3        varchar2(10)) on commit delete rows;
--The first attempt I created a regular table:
create table temp_staging_table
(pk_id         number(5),
data_1        varchar2(10),
data_2        varchar2(10),
data_3        varchar2(10));
-- The next three tables are just tables used to simulate populating production tables from the staging table
create table temp_table_1
(pk_id         number(5),
data_1        varchar2(10));
create table temp_table_2
(pk_id         number(5),
data_1        varchar2(10));
create table temp_table_3
(pk_id         number(5),
data_1        varchar2(10));
-- The procedure to move the data from the staging table into the fake production tables
create or replace procedure tst_procedure (p_pk_id in number)
is
begin
  insert into temp_table_1 (pk_id, data_1)
  select pk_id, data_1
    from temp_staging_table
   where pk_id = p_pk_id;
  insert into temp_table_2 (pk_id, data_1)
  select pk_id, data_2
    from temp_staging_table
   where pk_id = p_pk_id;
  insert into temp_table_3 (pk_id, data_1)
  select pk_id, data_3
    from temp_staging_table
   where pk_id = p_pk_id;
end;
-- The trigger on the staging table that will call the procedure
create or replace TRIGGER tst_trg
  AFTER
  INSERT
  ON temp_staging_table
  REFERENCING OLD AS OLD NEW AS NEW
  FOR EACH ROW
DECLARE
BEGIN
  tst_procedure(:new.pk_id);
END;
/You might notice that I did not include any commits in the procedure or trigger hoping that I could avoid the "mutating" trigger error. The commit I included in a separate script where I performed the actual insert, but it never makes it that far because of the "mutating trigger" error. Below is that script to insert the data:
insert into temp_staging_table
values (500,'THIS','IS A','TEST');
commit;I don't have to do it this way, but I'm not sure what other options I have. I could create a DBMS_JOB that runs every minute of a 24 hour period, but that seems very inefficient and not quite "real-time". I thought about replacing my call to the procedure in the trigger to logic that would schedule a job that would run immediately that would call the procedure, but I don't have the right privileges so I haven't tried that yet, but once again is that the most efficient way of doing it?
I am hoping by posting this that someone might have a better option. I have Googled the problem but haven't found any good solutions.

>
I had never heard of "Oracle Streams" until you mentioned it.
>
Here is an Oracle-base article that has sample code
http://www.oracle-base.com/articles/9i/advanced-queuing-9i.php
You could also just run a scheduler job that continuously queries the staging table for data and processes whatever rows it finds.
Before you start implementing any solution I suggest you flesh out your requirements regarding restart/recovery. What happens if the source or target DB is unavailable for some period of time? Do the records need to be processed in any particular order?

Similar Messages

  • How do I run a database procedure that inserts data into a table from withi

    How do I run a database procedure that inserts data into a table from within a Crystal report?
    I'm using CR 2008 with an Oracle 10i database containing a number of database tables, procedures and packages that provide the data for the reports I'm developing for my department.  However, I'd like to know when a particular report is run and by whom.  To do this I have created a database table called Report_Log and an associated procedure called prc_Insert_Entry that inserts a new line in the table each time it's called.  The procedure has 2 imput parameters (Report_Name & Username), the report name is just text and I'd like the username to be the account name of the person logged onto the PC.  How can I call this procedure from within a report when it's run and provide it with the 2 parameters?  I know the procedure works, I just can't figure out how to call it from with a report.
    I'd be grateful for any help.
    Colin

    Hi Colin, 
    Just so I'm clear about what you want: 
    You have a Stored procedure in your report.  When the report runs, you want that same procedure to write to a table called Report_Log. 
    If this is what you want the simple answer is cannot be done.  Crystal's fundamental prupose is to read only, not write.  That being said, there are ways around this. 
    One way is to have a trigger in your database that updates the Report_Log table when the Stored Procedure is executed.  This would be the most efficient.
    The other way would be to have an application run the report and manage the entry. 
    Good luck,
    Brian

  • PL/SQL procedure to insert data doesn't work and unable to find reason.

    Sorry that I couldn't find the best place to post this question. It seems that the forum does not deal with this kind of question. I post here for help.
    I have a stored procedure to insert data into one table. SP was compiled without error and executed without error (from log table to get information). But the data was not inserted into
    the target table. I have tried different way to figure out the reason. But I failed to get any idea. Please help me to find possible reasons. The smple SP looks like this:
    CREATE OR REPLACE PROCEDURE my.sp_insert( P_DATE IN VARCHAR2)
    IS
    declare section
    begin
    insert into target_table (column1, column2, column3, column4)
    select record1, record2, record3, record4 from table1, table2, table3, table4
    where clause;
    commit;
    exception section
    UPDATE PROCESS_LOG_TABLE CLAUSE;
    html_email section;
    rollback;
    end my.sp_insert
    I have tested that "select record1, record2, record3, record4 from table1, table2, table3, table4" really fetch the 7,000 records. and if I only run part of SQL from SQLPLUS as
    insert into target_table (column1, column2, column3, column4)
    select record1, record2, record3, record4 from table1, table2, table3, table4
    where clause;
    It will work and insert 7,000 records into target table. Why did it not insert into target_table when execiting as stored procedure? Please help with your input. Thanks.
    Edited by: citicbj on Feb 12, 2013 4:15 PM

    Dear Friend,
    Is the user from which you created database procedure and sqlplus that you tested the code successfully is same?
    Regards
    Ahamed Rafeeque Cherkala

  • ODI -OBIEE Lineage:Error while running ODI Procedure

    Hi ,
    I am using prebuilt mapping provided by oracle to achive dtata lineage between odi and obiee.
    I am getting error when i run scenario at Create "Same Column dummy Exp" procedure step.
    Error Info :
    ODI-1228: Task Create the "Same Column" dummy Expression (Procedure) fails on the target ORACLE connection ORACLE_XPONE.
    Caused By: java.sql.SQLSyntaxErrorException: ORA-00984: column not allowed here
    Procedure info:
    insert into <%=odiRef.getObjectName("LINEAGE_EXPRESSION")%>
    (I_LINEAGE_EXPRESSION, PROJECT_NAME, FOLDER_NAME, JOB_NAME, EXPRESSION, EXPRESSION_ORIGIN)
    values
    (<%=odiRef.getObjectName("BI_OBJ_ID.NEXTVAL")%>, 'Dummy', 'Dummy', 'Dummy', '(Same Column)', 'Dummy')
    Please let me know how to overcome this problem if anybody have achived lineaged by using oracle provided mappings.
    Thanks in Advance

    Hi,
    If you are on ODI 11g remove the odiRef.getObjectName("BI_OBJ_ID.NEXTVAL") function call and just give the sequence BI_OBJ_ID.NEXTVAL where ever its being used.
    Regards,
    Rajesh

  • Need to create procedure for insert tax line into ra_interface_lines_all

    Dear
    I need to create a procedure for insert a tax line into ra_interface_lines_all against the line type "LINE".
    after inserting the record i will run the auto invoice program to see the changes. kindly share how i can achieve through procedure.
    scenario:-
    after order dispatch workflow back ground run and data populated in ra_interface_lines_all where interface line id is null there i need to insert tax line against multiple orders.
    I know the join. when line type = 'LINE'  then tax line must have link_to_line_id of the line type line. my question is this when order number change how i can insert tax line against the line type line.
    regards,
    Fs
    Message was edited by: 832296

    Dear
    I need to create a procedure for insert a tax line into ra_interface_lines_all against the line type "LINE".
    after inserting the record i will run the auto invoice program to see the changes. kindly share how i can achieve through procedure.
    scenario:-
    after order dispatch workflow back ground run and data populated in ra_interface_lines_all where interface line id is null there i need to insert tax line against multiple orders.
    I know the join. when line type = 'LINE'  then tax line must have link_to_line_id of the line type line. my question is this when order number change how i can insert tax line against the line type line.
    regards,
    Fs
    Message was edited by: 832296

  • Running a procedure

    I need to write a script to run a procedure already written in the package body of the schema. The procedure iterates through one table_1 and inserts each row into another table_2. If the procedure is defined in Package Body/table/table_procs, how do I run this Proc? I don't even know the command to run this.

    In SQL* Plus, the syntax is
    SQL>exec package_name.procedure_name;
    Thanks
    Nathan

  • Procedure for inserting rows

    dear members,
    i have a table with some missing numbers in a col1.
    how can i add rows containing missing numbers.
    starting and ending number is given in the procedure.
    let us say starting from 1 to 10.
    table
    id col1
    1 2
    2 3
    3 4
    4 9
    Required Result after running the procedure.
    table
    id col1
    1 2
    2 3
    3 4
    4 9
    5 1
    6 5
    7 6
    8 7
    9 8
    10 10
    can i have that procedure.
    regards
    teefu.
    Edited by: user_teefu on Aug 23, 2010 2:19 PM

    Hi,
    I would do something like that :create or replace procedure t_addrows(
            p_min integer,
            p_max integer)
    as
            l_inserted integer;
    begin
            insert into t (id, col1)
            select
                    idstart+rownum id,
                    col1
            from (
                    select idstart, p_min+level-1 as col1
                    from (
                            select nvl(max(id),0) idstart
                            from t
                    connect by level <= p_max-p_min+1
            ) n    
            where not exists (
                    select null
                    from t
                    where t.col1=n.col1
            l_inserted := SQL%ROWCOUNT;
            dbms_output.put_line('inserted : '||l_inserted);
    end;
    /It gets the max(id) from the table to generate "following" ids.
    it uses the connect by level to generate integers between min and max parameters provided.
    it does a NOT EXISTS to avoid primary key errors.
    Example :Scott@my10g SQL>select * from t;
            ID       COL1
             1          2
             2          3
             3          4
             4          9
    Scott@my10g SQL>begin
      2  t_addrows(1,10);
      3  end;
      4  /
    inserted : 6
    PL/SQL procedure successfully completed.
    Scott@my10g SQL>select * from t;
            ID       COL1
             1          2
             2          3
             3          4
             4          9
             5          5
             6          8
             7          1
             8         10
             9          6
            10          7
    10 rows selected.
    NB :_ I didn't include a COMMIT in the procedure. You decide wheither it should be there or not.

  • Remote Database connection error on local database while running a procedur

    Dear Gurus,
    I am trying to run a procedure to grant Select Access to all objects of a schema to all schema but getting below error messages:
    Error report:
    ORA-02019: connection description for remote database not found
    This is on local database and all required privileges have been given to run this procedure but I dont understand why this error is being thrown every time. I am able to fetch all the tables directly (i.e. SELECT object_name FROM user_objects where OBJECT_TYPE IN('TABLE','VIEW','MATERIALIZED VIEW') AND STATUS='VALID')
    Kindly let me know if you have any solution.
    Procedure detail:
    declare
    sqltxt varchar(250);
    cursor course_det is
    SELECT object_name FROM user_objects where OBJECT_TYPE IN('TABLE','VIEW','MATERIALIZED VIEW') AND STATUS='VALID';
    v_objnm user_objects.object_name%type;
    begin
    open course_det;
    loop
    fetch course_det into v_objnm;
    exit when course_det%notfound;
    sqltxt :='GRANT SELECT ON ' || v_objnm|| ' TO public with grant option';
    EXECUTE IMMEDIATE sqltxt ;
    end loop;
    end;
    System detail:
    Oracle 11.2.0.3/Linux 5.3
    Ragards.
    Edited by: 877938 on Mar 20, 2013 12:27 AM

    Hi,
    It seems you are fetching records from one database to other. for that you need to create dblink for that.
    Create dblink first and then try to fetch records using that dblink.
    ORA-02019: connection description for remote database not found
    Cause: An attempt was made to connect or log in to a remote database using a connection description that could not be found.
    Action: Specify an existing database link. Query the data dictionary to see all existing database links. See your operating system-specific Net8 documentation for valid connection descriptors. 

  • Help on ORA-06550 & PLS-00363 Error while running a procedure from a packag

    Greeting All,
    I ran the following procedure from a package on a command line in sqlplus:
    SQL> exec QUALITY_ASSURANCE.COPY_SW_RESOURCES(2009,2010,9508);Where '2009' is the old fiscal year, '2010' is the new fiscal year and '9508' is the error code passed from the calling program. But, I received the following error messages:
    ERROR at line 1:
    ORA-06550: line 1, column 53:
    PLS-00363: expression '9508' cannot be used as an assignment target
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    Any thoughts, suggestions and/or advice to resolve these errors.
    Thanks in advance.

    Orchid wrote:
    Justin,
    Thanks for your response and information. Yes, Theoa was correct the 3rd parameter is an OUT variable, and it is a numeric field. The procedure was called by a form as follows:
    QUALITY_ASSURANCE.COPY_SW_RESOURCES(:BLK_CONTROL.FROMFY,:BLK_CONTROL.TOFY,V_ERR);But the form does not work so I am trying to isolate the problem by running the procedure by itself in sqlplus to make sure there is no problem with the procedure.
    Yesterday, I was able to run the procedure in Toad for Oracle to a successful completion by providing the 3 parameters: (2009, 2010, null). Just wonder why I cannot run the same procedure with the same parameters on a command line in sqlplus as follows:
    exec QUALITY_ASSURANCE.COPY_SW_RESOURCES(2009,2010,null);So, if I understand your suggestion correctly, in order to run the procedure with the 3 parameter successfully in sqlplus,
    I have to declare the 3rd parameter in PL/SQL. That is to create a PL/SQL file as suggested and run the file, correct? CORRECT!

  • How run stored procedure in Crystal report?

    I have table from query in report, but first I need to run stored procedure in report.
    How I need to do it?

    previous post not correct
      this is correct
    When I need to run my report
    1) I need to run storeed procedure ( the stored procedure will update some tables)
    I just used Add Command and added stored procedure in Database Fields, but I think the procedure doesn't work in report. Maybe I need add new commant and write there:
    exec ProcedureName par1 par2
    or
    exec ProcedureName (par1={?parameter1} par2={?parameter2})
    It's doesn't work. What I need to do?
    2) I use some query in report
    ex.
    select t1.col1, t2.col2, t6.col3 t1.col7 t4.col1
    from t1, t2, t6, t4, r4, ju, hh
    where hh.col11={?parameter1}
    and ju.col3=6
    and r4.col3={?parameter2}
    group by .....
    order by ......
    How I need to create me report? What I need to do first?
    If parameter in stored procedure par1={?parameter1} in query
    and par2={?parameter2}

  • Procedure to Insert PDF from FIle System to Database

    Hi ,
    I have a requirement to put the pdf files from our Local Machine or File system into Database table ..
    For that I have created a directory called "MY_PDF" with create and replace directory .
    Also , I have created a database table to store the files from Local machine FIle System directory ( MY_PDF) .
    I have created a procedure which takes 2 inputs ( ID and FIlename ) as parameters , this procedure when executes , it insert the file along with the ID in the database table .
    Procedure is as follows :
    CREATE OR REPLACE PROCEDURE proc_load_a_file( p_id IN NUMBER, p_filename IN VARCHAR2 )
    AS
    l_blob BLOB;
    l_bfile BFILE;
    x VARCHAR2(1000);
    BEGIN
    x:=p_filename;
    INSERT INTO demo(id,theblob,filename) VALUES ( p_id, empty_blob() ,x)
    RETURNING theBlob INTO l_blob;
    UPDATE demo
    SET locater =l_blob where id=p_id;
    l_bfile := bfilename( 'MY_FILES', p_filename );
    DBMS_LOB.FILEOPEN( l_bfile );
    DBMS_LOB.LOADFROMFILE( l_blob, l_bfile,
    DBMS_LOB.getlength( l_bfile ) );
    DBMS_LOB.fileclose( l_bfile );
    COMMIT;
    END;
    Now , my requirement is not to insert one one file each and every time when I execute the procedure .
    My requirement is first to check the File system Directory (MY_PDF) . If
    there is any pdf file in the directory then it will call that procedure and insert that file into the database untill no files found in the dorectory ( MY_PDF) .
    I am not getting the idea how to do this ..
    Please someone provide some valueable inputs .. so that I can finish it up .
    Thanks
    Prashant Dwivedi

    Suggest using the FlowElement.setStyle method to attach additional information about the image to the InlineGraphicElement that gets created.  Looking at the example code in the posted link you'll need to pass that data to the imageLoadComplete method.  The InlineGraphicElement can be found by saving interactionManager.absoluteStart before the graphic is inserted and then calling textFlow.findLeaf(savedAbsoluteStart).
    Hope that helps,
    Richard

  • Is it possible to trigger an error so that the running stored procedure is stopped?

    Hello all,
    I want to run an existing stored procedure and then I want to manually trigger an error/abort/interruption so see what happens and do some testing with that.
    Is it possible to manually trigger an error/abort/interruption on a running stored procedure so that it is stopped?
    If yes, how can I do that?
    I hope someone has an idea. For me it sounds not really difficult, but I just do not get the idea how to do it.
    Kind regards
    Peter

    Hello Visakh,
    I dont want to modify the existing procedure. I just want to run it and than stop it, but not with the button to stop it, but "kill" it somehow with an error (with not destroying the database).
    Nope you cant simulate an intermediate failure inside procedure code from outside. For that you have to modify the actual sp code itself
    Another way is by doing data manipulation in such a way which causes a error in procedure but for that you need to revisit the logic to ensure you do changes in such way as to cause an error
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • How to use pool connection run oracle procedure?

    Hi, All:
              I am facing a difficulty I can not find the solution. Maybe you can help
              me.
              I want to call an oracle stored procedure whenever I talk to datebase to
              make the application more efficient. I was able to run the procedure using
              oracle thin driver but not the connection pool using Weblogic jDriver for
              JDBC2.0.
              Please check the following code and see what I did wrong:
              The code in JSP file in Weblogic:
              <%-- JSP page directive --%>
              <%@ page
              import="java.io.*,java.util.*,java.sql.*,weblogic.common.*,weblogic.jdbc20.c
              ommon.*" %>
              <%-- JSP Declaration --%>
              <%!
              protected Connection con = null;
              ResultSet rset = null;
              %>
              <%-- JSP Scriptlet --%>
              <% try {
              Properties props = new Properties();
              props.setProperty("user", "james");
              props.setProperty("password", "aimjames");
              Driver myDriver =
              (Driver) Class.forName
              ("weblogic.jdbc.pool.Driver").newInstance();
              con = myDriver.connect("jdbc:weblogic:pool:hdj2Pool", props);
              String userid = (String)session.getAttribute("user.id");
              int subid =
              Integer.parseInt((String)session.getAttribute("sub.id"));
              String query = "begin pkg_select.sel_req_in_001(" + userid +
              ", " + subid + ", ?); end;";
              weblogic.jdbc.common.OracleCallableStatement cstmt =
              (weblogic.jdbc.common.OracleCallableStatement)con.prepareCall(query);
              cstmt.registerOutParameter(1,java.sql.Types.OTHER);
              cstmt.execute();
              rset = cstmt.getResultSet(1);
              When I run this JSP file, the compilation is fine but the result shows
              nothing. That's means I can not get the ResultSet for some reason.
              The working file when I use oracle thin driver (NOT use a connection pool):
              String userid = (String)session.getAttribute("user.id");
              int subid = Integer.parseInt((String)session.getAttribute("sub.id"));
              String query = "begin pkg_select.sel_req_in_001(" + userid +", " +subid
              +", ?); end ";
              CallableStatement cstmt = con.prepareCall(query);
              cstmt.registerOutParameter(1,OracleTypes.CURSOR);
              cstmt.execute();
              ResultSet rset = (ResultSet)cstmt.getObject(1);
              You may notice that I am trying to bind a parameter to an Oracle cursor. Is
              there anything I did wrong in using weblogic API? I just want to let you
              that in the weblogic JSP file, I also tried to use
              weblogic.jdbc.oci.CallableStatement and
              weblogic.jdbc20.oci.CallableStatement instead of
              weblogic.jdbc.common.OracleCallableStatement, but none of them seems work.
              I did check the bea site at
              http://www.weblogic.com/docs51/classdocs/API_joci.html#1080420 for the
              example to use:
              cstmt.registerOutParameter(1,java.sql.Types.OTHER);
              and I think I followed the exact procedure the example did.
              Please help!
              James Lee
              Artificial Intelligence in Medicine, Inc.
              2 Berkeley Street, Suite 403
              Toronto, Ontario M5A 2W3
              Tel: 416-594-9393 ext. 223
              Fax: 416-594-2420
              Email: [email protected]
              

    Joseph
    Thanks for the suggestion about latest version of Weblogic Server.
    "coding best-practices" is not mentioned in the post.
    In order to make servlet application run significantly faster, my servet how to use connection poo is much moreresonable?
    It is reasonable to expect servlet to run significantly faster with connection pooling.
    Is it true that geting and close a connection whenever
    one time database access finished?
    Already answered. Applications use a connection from the pool then return it when finished using the connection.
    Will the solution affect the servlet performance?
    Yes. Already answered. Connection pooling enhances performance by eliminating the costly task of creating database connections for the application.
    Is there any official document to introduce connection pool program?
    For the latest version
    http://download.oracle.com/docs/cd/E17904_01/web.1111/e13726/toc.htm
    http://download.oracle.com/docs/cd/E17904_01/web.1111/e13737/jdbc_datasources.htm#insertedID0

  • Can't Run Stored Procedure in Package

    Hi,
    I am trying to run a stored procedure that has multiple in and out paramaters. The procedure can only be viewed in my Connections panel by navigating Oher Users | <user> | Packages | <package> | <procedure>
    If I right click <procedure>, the menu items are "Order Members By..." and "Create Unit Test" (greyed out). The ability to "Run" the procedure does not seem possible when it's accessed by user.
    I have been trying to find an example of how to create an anonymous block so that I can run the procedure as a SQL file, but haven't found anything that works.
    Does anyone know how I can execute this procedure from SQL Developer? I am using Version 2.1.1.64.
    Thanks in advance!

    Thanks for replying. I did understand the basics of an anonymous block, but what I didn't understand was how to set the out parameters. I should have been more detailed in my question. However, I did get the answer here:
    http://stackoverflow.com/questions/3991721/run-stored-procedure-in-sql-developer
    Thanks again for replying. I appreciate you taking the time.

  • Run a procedure based on a schedule

    hi dear;
    how can i schedule to run a process in specific time or every one interval of time?
    regards;

    Dear John;
    i mean a procedure in SDK and not in sql.
    exp: the procedure is copying the open sales orders to invoices.
            i want to run this procedure every 5 minutes automatically
    how can i do it in SDK?
    thank you and regards;

Maybe you are looking for

  • How do i recover an e-mail draft that i deleted?

    how do i recover an email draft that was previously saved then deleted?

  • Mountain lion screen freeze

    Since I downloaded Mountain Lion OS 10.8, my screen freezes constantly.  I wish I had never downloaded this "upgrade."  Need solution ASAP becasue this puts me out of business.

  • License Problem again and again

    Hi! We are getting the below message every few days and then we have to delete MS License Registry key to use it again. "Remote session was disconnected because there are no Remote Desktop client access licenses available for this computer. Please co

  • Picture package plugin HELP

    Could someone explain how to add this feature to Photoshop cs5. I miss this feature from adobe, and I don't understand there own instructions.

  • Failed to lookup port type on Mediator Callback

    Hi everyone, I'm new to SOA Suite and to learn it i've started following the book "Getting Started with Oracle Soa Suite: A Hands On Tutorial". In chapter 7 about BPEL i'm getting the following error message when i try to set a callback on the mediat