Check two columns and update other table

HI ,
I have a table called trackCenterline .Below is the table.
What i want to do is If the segmentSequenceID is 1 it should pick the corresponding SegmentID i.e 10001 and Check for the same segment id in other table called TrackSegment which is below.  and pick the BeginMilepost of that segmentID and Update That
Milepost in a new table .At end SegmentSequenceID number it should pick ENDMilepost and update
TrackCenterline table.
TrackSegment table
In the below table for 10001 SegmentID it should pick BeginMilepost. For end Number of SegmentSequenceID in above table ID ends at 121 for that end sequenceID It should refer TrackSegment table below and pick EndMilepost and should be updated in another
table Milepost column.
after that a new segment starts with new sequence .and so on ...
bhavana

Hi Deepa_Deepu,
According to your description, since the issue regards T-SQL. I will help you move the question in the T-SQL forums at
http://social.technet.microsoft.com/Forums/en-US/home?forum=transactsql. It is appropriate and more experts will assist you.
When you want to check two columns from two tables then return some results and update the third table. I recommend you use join function and combine two tables, then use update select from statement for modifying the Mailpost table. You can refer to the
following T-SQL Statement.
-----using join to connect to two tables
select TrackCenterline.FeatureId,TrackCenterline.SegmentId,
TrackCenterline.SegmentSequenceId,TrackSegment.BeginMilepost,TrackSegment.EndMilepost
from dbo.TrackCenterline join dbo.TrackSegment
on TrackCenterline.SegmentId=TrackSegment.SegmentId
order by TrackCenterline.SegmentId, TrackCenterline.SegmentSequenceId
---the result shows as following.
FeatureId SegmentId SegmentSequenceId BeginMilepost EndMilepost
AMK100011 10001 1 61.0000 61.3740
AMK100012 10001 2 61.0000 61.3740
AMK100013 10001 3 61.0000 61.3740
AMK1000121 10001 121 61.0000 61.3740
AMK100021 10002 1 61.1260 61.7240
AMK100023 10002 3 61.1260 61.7240
AMK100033 10003 3 61.3740 62.9530
-----Then you can use update select from statement to modify the Mailpost table, Or you can post the table structure of Mailpost
And for more information, you can review the following article about update statement.
http://www.techonthenet.com/sql/update.php
Regards,
Sofiya Li
Sofiya Li
TechNet Community Support

Similar Messages

  • Compare 45 columns and update one table col

    I am using Oracle 9i database.I need to compare each record between two tables
    and update the one of table column (what records are updated)
    CURSOR cur1 is select t1., t2. from t1, t2 where t1.primarykey = t2.primarykey
    FOR rec1 IN cur1
    LOOP
    IF rec1.t1_col_1<>rec1.t2_col_1
    then
    update t1
    set col_t1.rem="MOdified",t.col_1=rec1.t2_col_1
    where t1.primerykey=rec1.primarykey
    END IF;
    IF rec1.t1_col_2<>rec1.t2_col_2
    then
    update t1
    set col_t1.rem="MOdified",t.col_2=rec1.t2_col_2
    where t1.primerykey=rec1.primarykey
    END IF;
    ..........45 if else conditions
    END LOOP;
    I have 1 million records to compare and 45 columns to compare, how do I increase performance.
    Currently it takes about 5hrs for the cursor to go through this if -else comparison.
    Thanks and Regards
    Swayamprakash.Chiluveru

    Hi Swayamprakash,
    Few basics first.
    1. DML SQL's perform better than PL/SQL. Sounds great but Oracle then need to hop between SQL and PL/SQL engine for every record in the cursor causing THRASHING. This is an old concept, reference of which can be found in Operating Systems.
    With Bulk Collect option, this could be minimized to a large extent, but causes a large amount of Undo being generated. This is another pitfall of using Bulk Collect. Morever, when you expect more percentage of records to be updated, it is advisable that the indices (if any) must be disabled. They can be rebuild afterwards causing very minimal amount of Undo. Performance gain is expected here.
    Now a query that you need to clarify:
    1. One million records to be updated on a diurnal basis - An OLTP database might need this functionality which is better handled by a screen driven interface rather than a SQL/Procedure running in background.
    An OLAP database must simply ignore such requirements for they are meant to be history archives.
    Suggestion:
    Merge - Seems to be the only optimal solution at the moment for the exact requirements are unclear. Already, somone has suggested this.
    Oracle Developers, DBA's must setp out from technicalities and turn towards functionality.
    Kind regards,
    Abhijit

  • How to concatinate values of two columns and update into another column

    There is a table : TEST contains three columns - Column1 , Column2 , Column 3
    Column1 contains values - (1,2,4)
    Column2 contains values : (a,b,c)
    Column 3 is empty .
    Target : Values in column 3 should be (1a,2b,4c)
    Need to achieve this through procedure .

    Paul if i want to concatenate two strings or alpha numeric characters from 2 fields and display in the third field,Will this code be able to do that?

  • Comparing Two tables with 300k records and update one table

    Could you let me know how to compare two tables having 300k records and update one table.below is the scenario.
    Table Tabl_1 has columns A,B and Tabl_2 has columns B,new_column.
    Column B has same data in both the tables.
    I need to update Tabl_2 in new_column with Tabl_1 A column data by comparing B column in both tables.
    I m trying to do using PLSQL Tables.
    Any suggestion?
    Thanks.

    Hi,
    Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved, so that the people who want to help you can re-create the problem and test their ideas.
    Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    If you're asking about a DML statement, such as UPDATE, the CREATE TABLE and INSERT statements should re-create the tables as they are before the DML, and the results  will be the contents of the changed table(s) when everything is finished.
    Always say which version of Oracle you're using (for example, 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002
    ef2019c7-080c-4475-9cf4-2cf1b1057a41 wrote:
    Could you let me know how to compare two tables having 300k records and update one table.below is the scenario.
    Table Tabl_1 has columns A,B and Tabl_2 has columns B,new_column.
    Column B has same data in both the tables.
    I need to update Tabl_2 in new_column with Tabl_1 A column data by comparing B column in both tables.
    I m trying to do using PLSQL Tables.
    Any suggestion?
    Thanks.
    Why are you trying to use PL/SQL tables?  If tabl_1 and tabl_2 are regular database tables, it will be much simpler and faster just to use them.
    Depending on your requirements, you can do an UPDATE or MERGE, either in SQL or in PL/SQL.

  • Unique row based on two columns and single column

    Dear Members,
    I have a table which contains duplicate rows, for which a query should be able to fetch the unique row from the table. Here the unique is not based on one column, but it should be on two columns and also check for uniqueness on one column.
    create table addr ( firstname varchar2(10), lastname varchar2(10), area varchar2(3));
    insert into addr values('bob', 'james', '1');
    insert into addr values('bob', 'james', '1');
    insert into addr values('harry', 'bert', '1');
    insert into addr values('jimmy', 'bert', '1');
    insert into addr values('sam', 'mac', '1');
    insert into addr values('sam', 'knight', '1');
    insert into addr values('tom', 'sand', '1');
    insert into addr values('cat', 'mud', '1');
    The output of query should contain 3 rows.
    bob - james
    harry - bert or jimmy - bert [ either one of them, but not both ]
    sam - mac or sam - knight [ either one of them, but not both ]
    tom - sand
    cat - mud
    SELECT firstname, lastname as total from addr WHERE area = '1' GROUP by firstname,lastname; This does not take of single column duplication..
    Any suggestions..

    SQL> with t_data
    as
    select 'bob' as firstname, 'james' as lastname, '1' as area from dual union all
    select 'bob', 'james', '1' from dual union all
    select 'harry', 'bert', '1' from dual union all
    select 'jimmy', 'bert', '1' from dual union all
    select 'sam', 'mac', '1' from dual union all
    select 'sam', 'knight', '1' from dual union all
    select 'tom', 'sand', '1' from dual union all
    select 'cat', 'mud', '1' from dual
    SELECT
            firstname,
            lastname,
            area
    FROM
                    SELECT
                            t.*,
                            row_number() over(partition BY firstname order by 1) rn,
                            row_number() over(partition BY lastname order by 1) rn1
                    FROM
                            t_data t
    WHERE
            rn     = 1
    AND rn1 =1 ; 
    FIRSTNAME       LASTNAME        AREA
    bob             james           1
    cat             mud             1
    jimmy           bert            1
    sam             knight          1
    tom             sand            1
    SQL>

  • Analysing and Updating a table

    Hi,
    Can anyone help me on follwing query..
    Can analyse of a table and updation on to same table can happen paralley?
    thank in advance.

    What's your db version? The very first thing is that you should not use the analyze command but dbms_stats package. Now , I am not sure why you want to gather the stats and update the table at the same time? As mentioned by Erica, the update should be followed with the stats gathering. And about the index usage, there are couple of things that can stop index from being used, for example, low selectivity on the column can very well stop the index. Other than that, if you are accessing the column containing the index alone and the column is supposed to contain the null values, oracle would rather use a FTS than using the index which actually makes perfect sense since use of index would result in incorrect data. So there can be couple of htings possible which may stop your index from being used. All what dbms_stats(and even Analyze) command would do , is to make the distribution of the data known tooracle. Having stats alone doesn't guarantee that the index would be used for sure.
    HTH
    Aman....

  • Help on triggers needed-update other tables

    Hi,
    I am using 10g and is very new to triggers and I hope I can gain some advises here.
    I have the following 3 tables. MainInterfaceTable is a table where it stores records of values which are to be updated to tables: log1 and log2 respectively. One application will insert record into MainInterfaceTable and the inserted record contains only values for columns which are to be updated into tables: log1 and log2 respectively. Columns which contain null values are not to be updated into log1 and log2 tables.
    I can only think of using many "if" statements in my trigger to concatenate the UPDATE DML to update log1 and log2 tables. But if the MainInterfaceTable table contains many columns, it is not very efficient. {color:#800080}Is there any built in oracle functions or a more efficient to perform this task??{color}
    {color:#800080}Any advises are greaatly appreciated. Thanks{color}
    For E.g. In the below MainInterfaceTable record, I only update table log1 with txt1A column values. And update log2 table with col1 and col2B column values.
    Column Values
    txt1 null
    txt1A 6
    txt1B null
    col1 &lsquo;new orders'
    col2A null
    col2B &lsquo;new purchase'
    ------------------------------my trigger -------------------------------------
    CREATE TRIGGER TRG_MainInterfaceTable
    AFTER INSERT ON MainInterfaceTable
    FOR EACH ROW
    DECLARE
    sqlStmt VARCHAR2(2000); -- the SQL statement
    BEGIN
    sqlStmt := 'UPDATE log1 a SET 1=1 ';
    if :*new*.txt1 is not null then
    sqlStmt := sqlStmt || ' ,a.txt1 = ' || :*new*.txt1;
    END IF
    if :*new*.txt1A is not null then
    sqlStmt := sqlStmt || ' ,a.txt1A = ' || :*new*.txt1A;
    END IF
    if :*new*.txt1B is not null then
    sqlStmt := sqlStmt || ' ,a.txt1B = ' || :*new*.txt1B;
    END IF
    prc_run_update_sql_log1(sqlStmt);
    ------repeat more IF THEN for other tables
    EXCEPTION
    WHEN
    -- exception handling
    end TRG_MainInterfaceTable
    --------------------------------------Table Structure------------------------------------------------------------------
    create table MainInterfaceTable (
    statuscol char(1),
    txt1 varchar2(20),
    txt1A number(6),
    txt1B varchar2(20),
    col1 varchar2(20),
    col2A number(6),
    col2B varchar2(20),
    create table log1 (
    txt1 varchar2(20),
    txt1A number(6),
    txt1B varchar2(20),
    create table log2 (
    col1 varchar2(20),
    col2A number(6),
    col2B varchar2(20),

    Thanks. I put the IF ELSE.. into a function and my codes looks neater. However I encounter a error when i try to pass in a DATE value.
    ORA_06502 numeric or value error: host bind array too small
    The error occur at the line in bold .
    I try to run
    Select TO_CHAR(sysdate, 'DD-MON-YYYY HH24:MI') from dual
    in PL/SQL screen and it works.
    Why the same TO_CHAR() syntax doesn't work in a function????
    FUNCTION concatupdatequery(pVal IN DATE, pCol IN VARCHAR2, pSql IN VARCHAR2) RETURN VARCHAR2 IS
    lvQueryStr VARCHAR2(30000);
    lvTempDate VARCHAR2(100);
    BEGIN
    lvQueryStr := pSql;
    IF pVal IS NOT NULL THEN
    dbms_output.put_line('pVal = ' || pVal);
    lvTempDate := TO_CHAR(pVal, 'DD-MON-YYYY HH24:MI:SS');
    lvQueryStr:=pSql||','||pCol||'=TO_DATE('''||lvTempDate||''',''DD-MON-YYYY HH24:MI'')'; -- DATE data type
    dbms_output.put_line('lvTempDate = ' || lvTempDate);
    END IF;
    RETURN lvQueryStr;
    EXCEPTION
    WHEN OTHERS THEN
    dbms_output.put_line('concatupdatequery (DATE) :pCol:'||pCol||' ,pVal:'||pVal||' ,pSql:'||pSql);
    dbms_output.put_line(SQLCODE||' - '||SQLERRM);
    RAISE;
    END concatupdatequery;

  • Two forms that update differrent tables on the same page?

    I tried to add two forms that update different tables on to one page.
    Problem is when I do that the forms gives me an error saying the field does not exist. It's like it is trying to update one table with the other tables fields.
    As an example Say I have one forms that is for people table and another one that is the Jobs table.
    When I go to update the people table, it sends the data for the jobs fields too I get an error like the field job description does not exist.
    I have two different forms for these and everything.
    I would hope it is possible to have two forms that update different tables on the same page.

    I was trying the exact same thing, but i managed to work round it by setting the steps to hide one region, so the user would enter the form see one region submit the region then direct back to the same page with the different region visible and the original hidden.
    I don't know if this would be acceptable for you...

  • How to call a idoc in abap program and updates catsdb table

    how to call a idoc in abap program and updates catsdb table
    thank you,
    Jagrut BharatKumar Shukla

    Hi Kishan,
    You can refer to following help document,
    http://help.sap.com/saphelp_nw04/helpdata/en/bf/d005244e9d1d4d92b2fe7935556b4c/content.htm
    Regards,
    Meera

  • I want to compare two columns and replace any equal values with the value in a specific cell

    I want to compare the numbers in two columns and replace all matching numbers in the second columns with the corresponding value from a cell in the same row as the matching number. 

    Me too.
    Barry

  • Topics with Two Columns, and ?s about Margins

    I've been searching all over and can't quite get the answers I need.  I have a robohelp project which will solely be for written documentation.  Some of the topics within this project I would like two have two columns, the left column will just have headings and the right side will have content.  I did accomplish this by making a table, however I can't remove the borders.  I also tried another way by using this, which works great but when I made printed documentation it didn't make it look like I have on my screen (printed the headings all together then the content on later pages).
    #container2 {     clear: left;     float: left;     width: 100%;     overflow: hidden; } #container1 {     float: left;     width: 100%;     position: relative;     right: 50%; } #col1 {     float: left;     width: 50%;     position: relative;     overflow: hidden; } #col2 {     float: left;     width: 50%;     position: relative;     overflow: hidden; } 
    So I guess I have a few questions to try and make this project go smoothly.  Since I will only be using this project for written documentation, what would be the best way to make sure that each topic I am working on will print the way I want it to (margins, etc.)?  Is there a good way to deal with my two column issue?  Would making a style that indents the text be a good solution?

    You may also want to check out CSS columns. That will allow you to work without using tables and let the browser to take care of the rest. See: http://www.w3schools.com/css/css3_multiple_columns.asp
    Kind regards,
    Willam

  • ALV grid oo delete rows and update to table

    Hi all
      How can I delete one row and update to the db table?
    thanks

    Hi,
    Refer:-
    The ALV Grid has events data_changed and data_changed_finished. The former method is
    triggered just after the change at an editable field is perceived. Here you can make checks for
    the input. And the second event is triggered after the change is committed.
    You can select the way how the control perceives data changes by using the method
    register_edit_event. You have two choices:
    1. After return key is pressed: To select this way, to the parameter i_event_id pass cl_gui_alv_grid=>mc_evt_enter.
    2. After the field is modified and the cursor is moved to another field: For this, pass cl_gui_alv_grid=>mc_evt_modifies to the same parameter.
    To make events controlling data changes be triggered, you must select either way by
    calling this method. Otherwise, these events will not be triggered.
    To control field data changes, ALV Grid uses an instance of the class
    CL_ALV_CHANGED_DATA_PROTOCOL and passes this via the event data_changed.
    Using methods of this class, you can get and modify cell values and produce error messages.
    Hope this helps you.
    Regards,
    Tarun

  • Reg: read excel column and insert into table.

    hi Friends,
          i wanted to read the data from Excel and insert into in my oracle tables.
          can you provide the link or example script.
        how to read the column value from excel and insert into table.
      please help.

    < unnecessary reference to personal blog removed by moderator >
    Here are the steps:
    1) First create a directory and grant read , write , execute to the user from where you want to access the flat files and load it.
    2) Write a generic function to load PIPE delimited flat files:
    CREATE OR REPLACE FUNCTION TABLE_LOAD ( p_table in varchar2,
    p_dir in varchar2 DEFAULT ‘YOUR_DIRECTORY_NAME’,
    P_FILENAME in varchar2,
    p_ignore_headerlines IN INTEGER DEFAULT 1,
    p_delimiter in varchar2 default ‘|’,
    p_optional_enclosed in varchar2 default ‘”‘ )
    return number
    is
    – FUNCTION TABLE_LOAD
    – PURPOSE: Load the flat files i.e. only text files to Oracle
    – tables.
    – This is a generic function which can be used for
    – importing any text flat files to oracle database.
    – PARAMETERS:
    – P_TABLE
    – Pass name of the table for which import has to be done.
    – P_DIR
    – Name of the directory where the file is been placed.
    – Note: The grant has to be given for the user to the directory
    – before executing the function
    – P_FILENAME
    – The name of the flat file(a text file)
    – P_IGNORE_HEADERLINES
    – By default we are passing 1 to skip the first line of the file
    – which are headers on the Flat files.
    – P_DELIMITER
    – Dafault “|” pipe is been passed.
    – P_OPTIONAL_ENCLOSED
    – Optionally enclosed by ‘ ” ‘ are been ignored.
    – AUTHOR:
    – Slobaray
    l_input utl_file.file_type;
    l_theCursor integer default dbms_sql.open_cursor;
    l_lastLine varchar2(4000);
    l_cnames varchar2(4000);
    l_bindvars varchar2(4000);
    l_status integer;
    l_cnt number default 0;
    l_rowCount number default 0;
    l_sep char(1) default NULL;
    L_ERRMSG varchar2(4000);
    V_EOF BOOLEAN := false;
    begin
    l_cnt := 1;
    for TAB_COLUMNS in (
    select column_name, data_type from user_tab_columns where table_name=p_table order by column_id
    ) loop
    l_cnames := l_cnames || tab_columns.column_name || ‘,’;
    l_bindvars := l_bindvars || case when tab_columns.data_type in (‘DATE’, ‘TIMESTAMP(6)’) then ‘to_date(:b’ || l_cnt || ‘,”YYYY-MM-DD HH24:MI:SS”),’ else ‘:b’|| l_cnt || ‘,’ end;
    l_cnt := l_cnt + 1;
    end loop;
    l_cnames := rtrim(l_cnames,’,');
    L_BINDVARS := RTRIM(L_BINDVARS,’,');
    L_INPUT := UTL_FILE.FOPEN( P_DIR, P_FILENAME, ‘r’ );
    IF p_ignore_headerlines > 0
    THEN
    BEGIN
    FOR i IN 1 .. p_ignore_headerlines
    LOOP
    UTL_FILE.get_line(l_input, l_lastLine);
    END LOOP;
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
    v_eof := TRUE;
    end;
    END IF;
    if not v_eof then
    dbms_sql.parse( l_theCursor, ‘insert into ‘ || p_table || ‘(‘ || l_cnames || ‘) values (‘ || l_bindvars || ‘)’, dbms_sql.native );
    loop
    begin
    utl_file.get_line( l_input, l_lastLine );
    exception
    when NO_DATA_FOUND then
    exit;
    end;
    if length(l_lastLine) > 0 then
    for i in 1 .. l_cnt-1
    LOOP
    dbms_sql.bind_variable( l_theCursor, ‘:b’||i,
    ltrim(rtrim(rtrim(
    regexp_substr(l_lastLine,’([^|]*)(\||$)’,1,i),p_delimiter),p_optional_enclosed),p_optional_enclosed));
    end loop;
    begin
    l_status := dbms_sql.execute(l_theCursor);
    l_rowCount := l_rowCount + 1;
    exception
    when OTHERS then
    L_ERRMSG := SQLERRM;
    insert into BADLOG ( TABLE_NAME, ERRM, data, ERROR_DATE )
    values ( P_TABLE,l_errmsg, l_lastLine ,systimestamp );
    end;
    end if;
    end loop;
    dbms_sql.close_cursor(l_theCursor);
    utl_file.fclose( l_input );
    commit;
    end if;
    insert into IMPORT_HIST (FILENAME,TABLE_NAME,NUM_OF_REC,IMPORT_DATE)
    values ( P_FILENAME, P_TABLE,l_rowCount,sysdate );
    UTL_FILE.FRENAME(
    P_DIR,
    P_FILENAME,
    P_DIR,
    REPLACE(P_FILENAME,
    ‘.txt’,
    ‘_’ || TO_CHAR(SYSDATE, ‘DD_MON_RRRR_HH24_MI_SS_AM’) || ‘.txt’
    commit;
    RETURN L_ROWCOUNT;
    end TABLE_LOAD;
    Note: when you run the function then it will also modify the source flat file with timestamp , so that we can have the track like which file was loaded .
    3) Check if the user is having UTL_FILE privileges or not :
    SQL> SELECT OWNER,
    OBJECT_TYPE
    FROM ALL_OBJECTS
    WHERE OBJECT_NAME = ‘UTL_FILE’
    AND OWNER =<>;
    If the user is not having the privileges then grant “UTL_FILE” to user from SYS user:
    SQL> GRANT EXECUTE ON UTL_FILE TO <>;
    4) In the function I have used two tables like:
    import_hist table and badlog table to track the history of the load and another to check the bad log if it occurs while doing the load .
    Under the same user create an error log table to log the error out records while doing the import:
    SQL> CREATE TABLE badlog
    errm VARCHAR2(4000),
    data VARCHAR2(4000) ,
    error_date TIMESTAMP
    Under the same user create Load history table to log the details of the file and tables that are imported with a track of records loaded:
    SQL> create table IMPORT_HIST
    FILENAME varchar2(200),
    TABLE_NAME varchar2(200),
    NUM_OF_REC number,
    IMPORT_DATE DATE
    5) Finally run the PLSQL block and check if it is loading properly or not if not then check the badlog:
    Execute the PLSQL block to import the data from the USER:
    SQL> declare
    P_TABLE varchar2(200):=<>;
    P_DIR varchar2(200):=<>;
    P_FILENAME VARCHAR2(200):=<>;
    v_Return NUMBER;
    BEGIN
    v_Return := TABLE_LOAD(
    P_TABLE => P_TABLE,
    P_DIR => P_DIR,
    P_FILENAME => P_FILENAME,
    P_IGNORE_HEADERLINES => P_IGNORE_HEADERLINES,
    P_DELIMITER => P_DELIMITER,
    P_OPTIONAL_ENCLOSED => P_OPTIONAL_ENCLOSED
    DBMS_OUTPUT.PUT_LINE(‘v_Return = ‘ || v_Return);
    end;
    6) Once the PLSQL block is been executed then check for any error log table and also the target table if the records are been successfully imported or not.

  • Trigger and Update Flag Table

    I've recently started trying to automate around a dozen procedures. These procedures are set to run immediately after the necessary previous procedure(s) is(are) done.
    What I am attempting to accomplish is a single generic trigger that will fire off each procedure when its parent procedures have finished firing. This will be accompanied by an update_flag table with three columns
    PARENT_PRC----------------------CHILD_PRC----------------------FLAG
    parent_prc_name1--------------child_prc_name1-----------------N
    parent_prc_name1--------------child_prc_name2-----------------N
    parent_prc_name3--------------child_prc_name3-----------------Y
    Logic:
    *1.*     When a procedure fires it updates this table to set any rows in which it is the “PARENT_PRC” by updating the FLAG column to = Y.
    *2.*     The trigger will execute a child procedure if its flag (or in the case of multiple parent procedures; all of its flags) are set to 'Y'. This trigger is set to fire AFTER a table update on the UPDATE_FLAG table.
    ----a.     I have to execute the procedure UFLAG in a job because I want the trigger to execute the procedure and then continue running immediately, rather than wait for the procedure to finish then commit. This way the trigger could start several procedures all running at the same time.
    ----b.     I have made it an autonomous transaction because I needed the job to fire immediately rather than be queued, which required a commit within the trigger.
    *3.*     The last step is to set the flag in UPDATE_FLAGS back to 'N' for CHILD_PRC = '||uflag||' once the child procedure is complete.
    ----a.     I have tried placing the update child_prc = 'N' in the trigger but it won’t allow a trigger that fires on update to update the same table.
    ----b.     I want to avoid putting the update statement in all of my procedures because I would like the option of running these procedures manually for testing purposes WITHOUT effecting the update_flags table.
    Number 3. is the key problem I have been having. Placing code within the trigger to update the update_flags table setting 'Y's back to 'N's once the procedures have fired causes a deadlock error.
    I believe this is simply because the trigger is attempting to update a table which (upon updating) causes the same trigger to fire before it has finish executing.
    How can I update the Flag table to reset the update flags back to 'N'?
    Is there a different way of doing this all together?
    Here is some code with dummy procedures that demonstrates what I have so far.
    With this code, executing parent procedures should set the update_flag table to 'Y' for FLAG where procedure = 'parent_prc'.
    I need to find a way to execute the child procedures AND set the FLAG column back to 'N' from the trigger.
    ex. executing parent_1 should set update_flags.flag = 'Y' where parent_prc = 'parent_1' and thus execute procedure CHILD_A and CHILD_B.
    create table update_flags (parent_prc varchar2(10), child_prc varchar2(10), flag varchar2(1));
    insert into update_flags values('parent_1', 'child_a', 'N');
    insert into update_flags values('parent_1', 'child_b', 'N');
    insert into update_flags values('parent_2', 'child_c', 'N');
    insert into update_flags values('parent_3', 'child_c', 'N');
    insert into update_flags values('parent_4', 'child_d', 'N');
    CREATE OR REPLACE procedure parent_1 as
    BEGIN
    update update_flags set flag = 'Y' where parent_prc = 'parent_1';
    END parent_1;
    CREATE OR REPLACE procedure parent_2 as
    BEGIN
    update update_flags set flag = 'Y' where parent_prc = 'parent_2';
    END parent_2;
    CREATE OR REPLACE procedure parent_3 as
    BEGIN
    update update_flags set flag = 'Y' where parent_prc = 'parent_3';
    END parent_3;
    CREATE OR REPLACE procedure parent_4 as
    BEGIN
    update update_flags set flag = 'Y' where parent_prc = 'parent_4';
    END parent_4;
    CREATE OR REPLACE procedure child_a as
    BEGIN
    dbms_output.PUT_LINE('CHILD_A Worked');
    commit;
    END child_a;
    CREATE OR REPLACE procedure child_b as
    BEGIN
    dbms_output.PUT_LINE('CHILD_B Worked');
    commit;
    END child_b;
    CREATE OR REPLACE procedure child_c as
    BEGIN
    dbms_output.PUT_LINE('CHILD_C Worked');
    commit;
    END child_c;
    CREATE OR REPLACE procedure child_d as
    BEGIN
    dbms_output.PUT_LINE('CHILD_D Worked');
    commit;
    END child_d;
    CREATE OR REPLACE TRIGGER MASTER_TRG
    AFTER UPDATE
    ON UPDATE_FLAGS
    DECLARE
    Pragma  AUTONOMOUS_TRANSACTION;
    BEGIN
      DECLARE
      job_num number;
      uflag varchar2(1000);
      BEGIN
            select  MAX(case when COUNT(case when flag='Y' then 1 end)=COUNT(*) then CHILD_PRC else '  ' end)
            into uflag
            from        update_flags
            group by    child_prc;
            IF   uflag <> '  ' THEN
                                      --update update_flags set  flag = 'N' where child_prc = uflag     --(line of code that causes deadlock error)
                            dbms_job.submit (job => job_num,
                            what => ' '||uflag||';'
            END IF; 
       END;            
    COMMIT;
    END MASTER_TRG;
    execute parent_2;
    execute parent_3;

    >
    I think I am getting my head around the transactional/trigger issue.
    >
    It doesn't sound like it since you are still talking 'triggers'. At any rate it is OP that needs to get their head around it.
    OP doesn't even know what the entire process needs to be but has already decided that
    1. a single generic trigger that will fire off each procedure when its parent procedures have finished firing
    2. an update_flag table with three columns: PARENT_PRC, CHILD_PRC, FLAG
    3. a procedure fires it updates this table to set any rows in which it is the “PARENT_PRC” by updating the FLAG column to = Y.
    4. a job - I have to execute the procedure UFLAG in a job
    5. I have made it an autonomous transaction because I needed the job to fire immediately rather than be queued, which required a commit within the trigger.
    6. there should be an option of running these procedures manually for testing purposes WITHOUT effecting the update_flags table.
    Fortunately OP had the wisdom to ask
    >
    Is there a different way of doing this all together?
    >
    Doesn't anyone design things anymore? Seems like everyone just wants to decide what the solution ought to be be and then try to force the problem to fit into it.
    The first stage is the DESIGN - not the implementation details or technology to use.
    The first design step is to outline, or flowchart, the PROCESS that needs to take place. Since OPs post lacks sufficient detail I will substitute my own 'guesstimations' to illustrate.
    1. there are one or more 'parent' processes
    2a. these parent processes are allowed to run in parallel as they do not interfere in any way with the processing done by other parent or child processes. (is this true?)
    2b. these parent processes ARE NOT allowed to run in parallel as they may interfere with each other.
    3. Each parent process can have one or more 'child' processes. (it appears that these aren't really children but rather processes that are 'dependent' on the parent or that must always be executed after, and each time that the parent executes.
    So here are just SOME of the things that are missing that must be known before possible alternatives can be explored
    1. Re item #2 - can the parent processes be executed in parallel? Or must they be executed serially? Will any of the parent processes be dependent on any other parent or child process?
    2. What is the relationship between a parent process and its child processes? Is the parent always executed first? What triggers the parent execution? How often is it executed?
    What if it is already executing? What if other parent processes are currently executing? What if one or more of its child processes are executing? What if the parent process fails for any reason - what action should be taken?
    Based on what was posted a set of parent and child processes might need nothing more than: execute parent, execute child1, execute child2, . . ., execute childn.
    3. What is the relationship between the child processes that belong to the same parent? Can they be executed in parallel (i.e. are they completely independent)? Or must they be executed in some particular order? What if one or more of the child processes fails for any reason - what action should be taken?
    4. Will any other user or process be executing these parent or child processes? That could interfered with the automated stream.
    5. What type of exception handling and recovery needs to be implemented in one or more steps of the processing fail for some reason?
    Typically there is often one or more control tables (OPs flag table) to control and limit the processing. But the table would have status information for every process not just the children:
    A. STATUS - DISABLED, ACTIVE, RUNNING, IDLE, ERROR
    B. START_TIME
    C. END_TIME
    D. RESULT_CODE
    The control table can be used by a parent or child process to determine if it is permitted to run. For example the first thing a procedure might do is check it's own STATUS. If it is already running it would exit or log an error or message. If that test is passed it might check the status of any dependent processes. For example it might check that its child processes are ACTIVE and ready to run; if a child was still running the parent would exit or log an error or message.
    The control process would lock the appropriate control table records (FOR UPDATE) and would set the status and other fields appropriately to prevent interference by other processes or procedures.
    Design first. Then look at the implementation options.

  • Query and update a table/view

    What is the best & fastest way to do this?
    1) Put up a query input region for users to enter parameters.
    2) Run a query on a table/view using those parameters.
    3) Allow the output in (2) to be modified by user (multiple rows at a time) and then Submit the updates back to update th table/view
    I can do (1) and (2) easily. How can I do (3)?
    Thanks

    Make a report on the table. Go to the definition of
    the report column and change the "Display As" type to
    text field or select list or whcih ever is
    applicable. Write a process on submit to insert these
    values back to the table. You will have control over
    which columns the user can modify.Thats a good idea and I was able to start on it. But how can my after submit process tell which rows to modify? i.e. what will my after submit process look like?
    for rec in (....)
    loop
    update my_table set
    end loop;
    Help? Thanks

Maybe you are looking for