SQL 2008 Trigger to handle multi rows scenario

I have created below trigger to start logging the company changes from the table1 into another audit table. It works fine with single row but crashing with identical change with multiple rows. Can you please help me to update the trigger to handle multi-row
scenario. Thanks.
GO
IF
NOT EXISTS
(SELECT
* FROM sys.objects
WHERE object_id
= OBJECT_ID(N'[dbo].[Company_AuditPeriod]')
AND type
in (N'U'))
CREATE
TABLE [dbo].[Company_AuditPeriod](
      [Client] [varchar](25)
NOT NULL,
      [Period] [varchar](25),
      [Table_Name] [varchar](25),
      [Field_Name] [varchar](25),
      [Old_Value] [varchar](25),
      [New_Value] [varchar](25),
      [User_ID] [varchar](25)
      [Last_Update] [datetime],
        [agrtid] [bigint]
IDENTITY(1,1)
NOT NULL,
ON [PRIMARY]
GO
--create trigger
SET
QUOTED_IDENTIFIER ON
GO
CREATE
TRIGGER [dbo].[Table1_Update]
ON [dbo].[Table1]
FOR
UPDATE
NOT
FOR REPLICATION
AS
BEGIN
DECLARE
      @status          
varchar(3),
      @user_id   
varchar(25),
      @period          
varchar(25),
      @client          
varchar(25),
      @last_update
datetime
DECLARE
      @Old_status      
varchar(3),
      @Old_user_id     
varchar(25),
      @Old_period      
varchar(25),
      @Old_client      
varchar(25)
SELECT
      @status    
= status,
      @user_id   
= user_id,
      @period          
= period,
      @client          
= client,
      @last_update
= last_update
FROM Inserted
SELECT
      @Old_status
= status,
      @Old_user_id     
= user_id,
      @Old_period      
= period,
      @Old_client      
= client
FROM Deleted
If @Old_status <> @status
INSERT INTO Company_AuditPeriod
VALUES ( @client, @period,
'Table1',
'period',@old_status, @status, @user_id, @last_update)
END
GO

Sorry for the confusion.
I just made sure the table name is same in sys.objects statement and create table statement (there was a typo)
IF
NOT EXISTS
(SELECT
* FROM sys.objects
WHERE object_id
= OBJECT_ID(N'[dbo].[Company_AuditPeriod]')
AND type
in (N'U'))
CREATE
TABLE [dbo].[ Company_AuditPeriod](
Earlier you created Trigger on Company_AuditPeriod but
We have to create trigger on Table1 please with multi row scenario. Thanks.
--Company_AuditPeriod DDL
GO
IF
NOT EXISTS
(SELECT
* FROM sys.objects
WHERE object_id
= OBJECT_ID(N'[dbo].[Company_AuditPeriod]')
AND type
in (N'U'))
CREATE
TABLE [dbo].[ Company_AuditPeriod](
      [Client] [varchar](25)
NOT NULL,
      [Period] [varchar](25),
      [Table_Name] [varchar](25),
      [Field_Name] [varchar](25),
      [Old_Value] [varchar](25),
      [New_Value] [varchar](25),
      [User_ID] [varchar](25)
      [Last_Update] [datetime],
        [agrtid] [bigint]
IDENTITY(1,1)
NOT NULL,
ON [PRIMARY]
GO
--Table1  DDL
CREATE TABLE [dbo].[Table1](
[bflag] [int] NOT NULL,
[client] [varchar](25) NOT NULL,
[copies] [int] NOT NULL,
[cost_bio] [decimal](28, 8) NOT NULL,
[cost_cpu] [decimal](28, 8) NOT NULL,
[cost_dio] [decimal](28, 8) NOT NULL,
[date_ended] [datetime] NOT NULL,
[date_started] [datetime] NOT NULL,
[description] [varchar](255) NOT NULL,
[expire_days] [int] NOT NULL,
[func_arg] [varchar](255) NOT NULL,
[func_id] [int] NOT NULL,
[ing_status] [int] NOT NULL,
[invoke_time] [datetime] NOT NULL,
[last_update] [datetime] NOT NULL,
[mail_flag] [tinyint] NOT NULL,
[me_mail_flag] [tinyint] NOT NULL,
[module] [char](3) NOT NULL,
[order_date] [datetime] NOT NULL,
[orderno] [int] NOT NULL,
[output_id] [int] NOT NULL,
[poll_status] [char](1) NOT NULL,
[printer] [char](16) NOT NULL,
[priority] [char](1) NOT NULL,
[priority_no] [int] NOT NULL,
[process_id] [int] NOT NULL,
[report_cols] [int] NOT NULL,
[report_id] [varchar](255) NOT NULL,
[report_name] [varchar](25) NOT NULL,
[report_type] [char](1) NOT NULL,
[server_queue] [char](12) NOT NULL,
[status] [char](1) NOT NULL,
[step_id] [char](8) NOT NULL,
[system_name] [char](8) NOT NULL,
[used_bio] [int] NOT NULL,
[used_cpu] [int] NOT NULL,
[used_dio] [int] NOT NULL,
[user_id] [varchar](25) NOT NULL,
[variant] [int] NOT NULL,
[agrtid] [bigint] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
 CONSTRAINT [PK_acrrepord001] PRIMARY KEY NONCLUSTERED 
[agrtid] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 90) ON [INDEX]
) ON [PRIMARY]
G0<o:p></o:p>
--create trigger
SET
QUOTED_IDENTIFIER ON
GO
CREATE
TRIGGER [dbo].[Table1_Update]
ON [dbo].[Table1]
FOR
UPDATE
NOT
FOR REPLICATION
AS
BEGIN
DECLARE
      @status          
varchar(3),
      @user_id   
varchar(25),
      @period          
varchar(25),
      @client          
varchar(25),
      @last_update
datetime
DECLARE
      @Old_status      
varchar(3),
      @Old_user_id     
varchar(25),
      @Old_period      
varchar(25),
      @Old_client      
varchar(25)
SELECT
      @status    
= status,
      @user_id   
= user_id,
      @period          
= period,
      @client          
= client,
      @last_update
= last_update
FROM Inserted
SELECT
      @Old_status
= status,
      @Old_user_id     
= user_id,
      @Old_period      
= period,
      @Old_client      
= client
FROM Deleted
If @Old_status <> @status
INSERT INTO Company_AuditPeriod
VALUES ( @client, @period,
'Table1',
'period',@old_status, @status, @user_id, @last_update)
END
go

Similar Messages

  • How to handle multi row update in table?!

    Hello,
    I am searching for a solution to edit/update a lot of rows of a table at one time. The user has the ability to edit all cells of this table and then update this by pressing a submit button.
    I have a managed bean with an collection of objects. Each object represents on row.
    How is this handled in JSF? Is it only necessary to bind the datatable to the collection?
    Thanks,
    Thomas

    Is it only necessary to
    bind the datatable to the collection?Yes.
    Don't forget to put the collection in session scope.

  • Multiple Users - Tabular Forms - Multi Row Update.....

    Greetings All,
    Any comments, assistance, links, or even answers on the following situation would be much appreciated....
    I have a Application Express 4.0 (Could upgrade to 4.1 if it would help this issue)
    I have a wizard generated tabular form on a table, the form will show up to 600 records (rows) on a page.
    Part 1:
    The situation:
    User 1: Opens the form and brings up latest data set.
    User 2: Opens the form and brings up the latest data set.
    User 1: Changes data for record 1
    User 1: Hits submit. The data is saved.
    User 2: Changes data for record 1
    User 2: Changes data for record 2
    User 2: Hits submit. The following error is produced:
    Error in mru internal routine: ORA-20001: Error in MRU: row= 1, ORA-20001: ORA-20001: Current version of data in database has changed since user initiated update process. current checksum = "3EE15D666E9DBDC59D34CE4CFB3950C0", item checksum = "922DA12AE1E3D8856695745C4D2830D2"., update "<Removed> Error Unable to process update.
    When this error occurs no updates get made to the table.
    I understand that row 1 can not be updated, however I would like row 2 (and all other rows where there is no conflict) to be updated. I would then like to be able to highlight in the form the rows that failed to update (And reload the data in them from the DB).
    Is this something I can achieve using my own MRU procedure, or in another way?
    Can anyone point me to a good example, tutorial or book showing how to do this.
    Thanks!

    Thanks for the comments guys.
    I have solved my issue in two different ways. Way one was not so clever, but worked, involving writing my own process for handling multi-row updates and would allow a user to fill in data for multiple rows (say 10) and have only the row with changed data rejected. V2 takes a very different approach, it uses Javascript, AJAX and the DOM model of the form to check when data is changed / updated by the user. Essentially, when a user enters an updateable form element, a AJAX request checks if the data has been changed. If it has, the value in the form is updated, and the color changed to blue to alert the user. When the user updates the data item, and AJAX request posts the new value to the database, where it is inserted. I had to build a bit of a framework to make this useable, and have to use dynamic sql in the database packages, but it work really well for what my users need! There are limitations (Currently it only supports date fields, text fields and drop down lists) but it works for me. It also involves traffic back and forth with the server each time a user moves the focus to a new form element, but it is a very light request and the work to do the select / updates in oracle is all based on a primary ke, so is ver quick.
    Solution 1: (Would need to be made much more elegant):
    1: Create a new text Item called P5_MESSAGE (To display error / success messages)
    2: Create a new process:
    DECLARE
    l_cks wwv_flow_global.vc_arr2;
    j pls_integer := 1;
    vUpdatedCount number := 0;
    vErrorCount number:=0;
    vMessage varchar2(4000):='';
    BEGIN
    select wwv_flow_item.md5(firstname,lastname,age) cks
    BULK COLLECT INTO
    l_cks
    from VA_TEST1 ;
    for i in 1..l_cks.count
    loop
    if htmldb_application.g_fcs(i) != l_cks(i) then
    -- Log error
    vErrorCount:=vErrorCount+1;
    vMessage:=vMessage||'Could not update row with ID:' || htmldb_application.g_f01(i) || '. This data has been updated by another user since you retrieved the data.<br>';
    else
    -- Do insert
    vUpdatedCount:=vUpdatedCount+1;
    update VA_TEST1
    set
    FIRSTNAME = replace(htmldb_application.g_f02(i),'%'||'null%',NULL)
    ,LASTNAME = replace(htmldb_application.g_f03(i),'%'||'null%',NULL)
    ,AGE = replace(htmldb_application.g_f04(i),'%'||'null%',NULL)
    where ID = htmldb_application.g_f01(i);
    end if;
    end loop;
    :P5_MESSAGE := vMessage;
    end;
    Note, this currently updates every row, even if the data is unchanged, this could be fixed by comparing the checksum of the data to be inserted with the checksum of the data in the table, if the same then no need to insert.
    Solution 2:
    Too complex to explain in detail here, if you need to implement this then let me know.

  • Multi Row Insert

    I have read a few posts that mention a multi-row-insert but I can't find it.
    There is a multi row update and a multi row delete.
    I am using html db 1.6. We will be upgrading after we get this version of our app up and running, but don't want to take time out for the upgrade right now.
    Is multi_row_insert new to Application Express 2.0?
    Thanks,
    Gregory

    No, the multi row insert is not new to 2.0
    The builtin MRU processes handle multi-row updates and multi-row inserts. However, the default Add Rows process that the wizard creates on a tabular form does create only 1 blank row when you click the Add Row button. To increase this, just open the Add Rows process page and change 1 to a different number.

  • How can I handle data in a multi row block?

    Hi all,
    I have a form which contain a multi row block.
    I put data in that block. Suppose that in the second column of
    that block data no changes.I want to fill only the first cell of
    the column and all the cells below first cell ( header) inherits
    that value.
    Example :
    Block1
    ITEM1 ITEM2
    rec1 1 1999
    rec2 2
    rec3 3
    When I insert in the table rec2 I want :
    INSERT INTO(col1,col2) VALUES)(2,1999)!!!.
    Best Regards !
    null

    vali (guest) wrote:
    : Hi all,
    : I have a form which contain a multi row block.
    : I put data in that block. Suppose that in the second column of
    : that block data no changes.I want to fill only the first cell
    of
    : the column and all the cells below first cell ( header)
    inherits
    : that value.
    : Example :
    : Block1
    : ITEM1 ITEM2
    : rec1 1 1999
    : rec2 2
    : rec3 3
    : When I insert in the table rec2 I want :
    : INSERT INTO(col1,col2) VALUES)(2,1999)!!!.
    : Best Regards !
    Mr. Vali,
    I suppose you want to enter ITEM2 value only in first record and
    duplicate that value in subsequent records automatically. There
    are couple of methods to accomplish this and the following is one
    of them:
    Add this code in WHEN-NEW-RECORD-INSTANCE trigger for block1.
    IF :SYSTEM.RECORD_STATUS ='NEW' AND :SYSTEM.CURSOR_RECORD > 1
    THEN
    IF :ITEM2 IS NULL THEN
    GO_ITEM('ITEM2');
    DUPLICATE_ITEM;
    GO_ITEM('ITEM1');
    END IF;
    END IF;
    good luck
    null

  • Multi Row update using pl/sql anonymous block process

    Does anyone have an example of multi row update using a pl/sql anonymous block process?
    The reason I can not use the apex mru process is that the table in questions has a five field key.
    My attempts have failed with a bad number.
    Thanks,
    Gary

    Hi Gary,
    can y<ou pls send the definition of thet table and the UPDATE sql.
    It is a littel difficult like this.
    We need more info.
    BR,
    Lutz
    =;-)

  • How to handle a multi-department scenario?

    Hello,
         I've used WLI 8.1sp2 in the scenario of one administrator handling all
    processes of a company. However, I have a need to use a single
    installation to support multiple departments. Each department has its
    own set of users/roles, and has its own managers.
    I'd love to be able to let each department manager use the WLI console
    to configure their department's specific needs. However, there's no way
    to restrict them from viewing other processes and users in WLI.
    I'm thinking we need to provide a custom application to support this,
    where we can filter the processes and users by the department name (such
    as prepending the department name to the process name or user names).
    Then we'd have a custom application that uses the WLI APIs to filter out
    the information for that particular department.
    Can anyone comment on this scenario and how it could be achieved with
    WLI? Or, does anyone know a product that can handle such a scenario
    natively (I haven't seen one).
    Thanks

    Thank you for your answer.
    I didn't realise I could use inputHidden for anything more complex than a single string...
    I have added a h:inputHidden for the elements array but it still doesn't work.
    How should it be used?
         <h:form>
              <h:inputHidden value="#{myExample.elements}"/>
              <h:commandButton action="#{myExample.doSearch}" value="Search Database" />
    ...While debugging I noticed that at the last button-press the getElements method is called twice before setElements, returning null.

  • Can't restore SQL 2005 BAK to SQL 2008 R2 running on Server 2012

    Hi there,
    Preparing to switch from SQL 2005/Server 2003 to SQL 2008 R2 / Server 2012.   Took a backup of the SQL database on 2005 (stored at a cloud backup provider nightly) and copied to the new machine.  Unable to restore the .BAK file, with the error:
    The media family on device <backup path> is incorrectly formed.  SQL Server cannot process this media family.
    RESTORE HEADERONLY is terminating abnormally.  (Microsoft SQL Server, Error: 3241)
    Tried it with two different backup files from two different nights, same error.  I understand that this error can show up when restoring to a lower version of SQL, but that's not the case here.
    Also, I know this can occur if the BAK file is corrupt, and I can't verify that yet, but two in a row failed.  I'm hoping our cloud solution isn't part of the problem somehow.  
    BAK file is 15 Gb in size, so don't have the ability to attempt the restore on the 2005 production server.   Just not enough room, and can't afford to cause performance issues on that box anyway.
    Anyone know of any way to get a better handle on what's going on, or, even better, how to resolve it?
    Thanks
    Robin

    Hello,
    Since you are using a cloud solution, maybe the following article applies in your scenario.
    http://www.sqlcoffee.com/Troubleshooting047.htm
    Hope this helps.
    Regards,
    Alberto Morillo
    SQLCoffee.com

  • Tabular form - Multi row delete error

    Apex 4.0.2
    We have a simple CRUD type of application on a bunch of tables built using Apex v1.6 that has, over the years, been upgraded to v4.0.2 and it is working mostly fine. It uses all out-of-the-box standard components, forms, classic reports, nothing too fancy. Recently one of the tabular forms started to misbehave, the multi-row-delete process raises a No Data Found error. The tabular form is based on a view with a INSTEAD OF trigger to handle the DML. Manually deleting the row in SQL*Plus works fine delete from mytab here pk_id = :pk_id but selecting the same row in Apex and clicking Delete raises the error.
    How does one go about troubleshooting & fixing this sort of thing? I tried re-saving the region in the Builder, exporting/importing the entire app, nothing. Running in Debug mode doesn't really provide any additional information, just that the MRD process failed. Tabular forms are the most frustrating, opaque component in Apex, wish they were easier to troubleshoot.
    Any ideas?

    Hello Vikas,
    >> How does one go about troubleshooting & fixing this sort of thing?
    By given us a bit more information :)
    • Is it a manual Tabular Form (using the ITEM API) or a wizard created one?
    • Are the Insert/Update operations work correctly? If not, what is the type of your PK column(s)?
    • If the problem is limited to the Delete operation, maybe the problem lies with the checkbox column. Are you sure that on page it is rendered as the f01 column?
    • As triggers are involved, can you save the PK that the trigger sees? Is it the expected value?
    • Are there any other processes that are fired before the DML process? If so, maybe the problem is with them. You can temporarily disable them and see if it change anything.
    >> Tabular forms are the most frustrating, opaque component in Apex, wish they were easier to troubleshoot
    Yes, I agree. However, I believe that 4.1 made some serious advancement where Tabular Form is concerned. Having simplified Tabular Form related Validations and Process should make things easier, and as a result, prone to less errors. Still, the main problem is that the type of error you are talking about is usually the result of metadata problems and these are indeed very hard to track.
    Regards,
    Arie.
    &diams; Please remember to mark appropriate posts as correct/helpful. For the long run, it will benefit us all.
    &diams; Author of Oracle Application Express 3.2 – The Essentials and More

  • Multi row block record_group or cursor?

    I've done a lot of research on the Forms OTN forum and can't find a solution to this problem. I'll continue to research until an answer is posted to this thread. I've used the forms forums and Metalink for years and they've been a great help.
    My problem -
    I have a multi-row block built off a view. Each row has a check box. The canvas also has a button. When the button is pressed, each record checked will be processed. The problem is, I need to sort the data selected (checked) before it's processed. To complicate matters, the sort criteria is not in the view. My plan was to build a cursor off the block, but I'm having problems populating due to the multi-row aspect.. I also tried building a record_group but again ran into complications with it being multi-row. I'm not sure which method to use since I haven't found a clear-cut solution.
    btw - using 10gR2.
    TIA,
    abc

    AB, you're sure not very clear on this.
    Aweiden has the correct suggestion: Create a PL/SQL table in the form, rather than a record group.
    Here are the steps I would follow:
    1. User queries and displays the data, and then checks some checkboxes. Do not use a when-checkbox-changed trigger, since they can check, then un-check boxes.
    2. When user presses the process button, loop through the block as Aweiden has done above. However, I would call a procedure from within the loop to look up the values from the Mel_Item table. Store the values returned from the procedure within your pl/sql table, adding one row to the table for each row in your block that was checked.
    As a side note, how difficult is it to join the Mel_Item table with your view when you query the block? You could store those sort values from Mel_Item along with the data from the view.
    3. Once you are done processing the data block loop, sort the pl/sql table. (Maybe I can find the code lying around here somewhere, but a table sort like that can be coded in maybe 20 lines).
    I am not sure, but are you saying above ("...insert each row into another table (other information is different so its not duplicate rows entirely)...") that you are inserting the data from the user-checked rows into a database table? That is certainly easier to do than writing your own sort, I guess.
    4. After the pl/sql table is sorted, loop through it one more time, processing the data in the required sequence.
    Actually, pl/sql table processing is quite fast. You don't really need to sort the rows. All you need do is to step through the table checking for the first row to process (by finding the lowest value of the sort items). Process that row's data, then remove (delete) it from the table, then repeat the process until you have processed and removed every row from the array. I believe I would use this method rather than trying to sort the pl/sql table, OR inserting into a database table.
    Edited by: Steve Cosner on Oct 23, 2008 10:39 PM

  • Dynamically Changing Labels for Multi Row Block Buttons

    Forms [32 Bit] Version 9.0.4.1.0 (Production)
    Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
    On my local: Windows 7 OS
    I am having a difficult time in doing the following in forms, and not sure if it can be done?
    I have a multi row block,based on DB table, which displays filename and another column from the table.
    It also has a push button on each row, which opens and displays the physical file from its source, when clicked. The filename thus can have 3 diff statuses depending on its sources and accordingly corresponding button should display appropriate label:
    a) View Image (its is in content server and successfully imaged. In this case I display the file in the browser, from the content server, when the button is clicked)
    b) View File (Display the file from file system)
    c) View Error (Display imaging error message from the table, as file failed to make it to the imaging server)
    I have this logic currently coded in the post query trigger, at the block level, and tried using set_item_property(button_id, label, <button_lable>), where I programmatically set the button lable, based on the file status (imaged, not imaged or has error) in that row. This wroks well, only if all the files in the multi row block have the same status. If each of them have diff statuses, then only last processed files's status gets reflected into the button label. For eg: The file in the first row of the block is imaged, and one in the second row has an imaging error. The button label for the first row should say 'View Image' and button for the second row should say 'View Error'. But now buttons for both the rows display 'View Error', as thats what got processed last!
    I __can not use set_item_instance property for 'label'__ (which lets us dynamically change the label on the push buttons).
    Is there any way to do this for ORacle forms? I am now playing with having 3 diff button items in that block, laying them on top of each other and showing only those that are appropriate and hiding the others... But I am not sure it is going to give me what I need? I think I am going to end up facing the same issues as in above case!!
    Any expert advice is highly appreciated.
    Thanks in advance for your time:
    Libran_Girl
    Edited by: libran on Aug 30, 2011 8:04 AM
    Edited by: libran on Aug 30, 2011 8:05 AM

    <p>I have just updated this existing PJC, that was originally constructed to handle Text Fields. You can, now, also handle buttons with it.
    Set the Button's Implementation Class property to : oracle.forms.fd.MultiButton.
    </p>
    This is the code you have to put one triggers of your based block:
    When-New-Record-Instance trigger: (based on the EMP table)
    declare
         LN$Pos  pls_integer ;
         LN$Rec  pls_integer := Get_Block_Property('EMP', CURRENT_RECORD) ;
         LN$Max  pls_integer := Get_Block_Property('EMP', RECORDS_DISPLAYED) ;
         LC$C    Varchar2(15) ;
    Begin     
         LN$Pos :=  LN$Rec - (trunc(LN$Rec/LN$Max) * LN$Max) ;
         If LN$Pos = 0 Then LN$Pos := LN$Max ; End if ;
         If LN$Pos > 0 Then
              Set_Custom_Property('EMP.BT', LN$Pos, 'SET_LOG', 'true' );
              -- Add the new item --
              Set_Custom_Property('EMP.BT', LN$Pos, 'SET_NEW_REC', to_char(LN$Rec) );
              -- Set some properties --
              Set_Custom_Property('EMP.BT', LN$Pos, 'SET_LABEL', to_char(LN$Rec) || ',' || :EMP.ENAME );
              If :EMP.JOB = 'MANAGER' Then
                Set_Custom_Property('EMP.BT', LN$Pos, 'SET_FONT', to_char(LN$Rec) || ',Arial,bold,14' );
                Set_Custom_Property('EMP.BT', LN$Pos, 'SET_FGCOLOR', to_char(LN$Rec) || ',0,0,255' );
              End if ;
              If :GLOBAL.I > 250 Then :GLOBAL.I := 5 ;
              Else  :GLOBAL.I := :GLOBAL.I + 5 ;
              End if ;     
              LC$C := To_Char(LN$Rec) || ','
                   || To_Char(255) || ','
                   || To_Char(255-:GLOBAL.I) || ','
                   || To_Char(255-:GLOBAL.I) ;    
              Set_Custom_Property('EMP.BT', LN$Pos, 'SET_BGCOLOR', LC$C );
              Synchronize;
         End if ;
    end;When-Create-Record trigger:
    declare
         LN$N    pls_integer ;
         LN$Rec  pls_integer := :system.cursor_record ;
         LC$C    Varchar2(15) ;
    Begin     
         if get_block_property('EMP',TOP_RECORD) > 1 Then
              LN$n := :system.cursor_record - get_block_property('EMP',TOP_RECORD) + 1 ;
         else
              LN$N := :system.cursor_record ;
         end if;
         If LN$N > 0 Then
              Set_Custom_Property('EMP.BT', LN$n, 'SET_LOG', 'true' );
              -- Add the new item --
              Set_Custom_Property('EMP.BT', LN$n, 'SET_NEW_REC', to_char(LN$Rec) );
         End if ;
    end;Post-Query trigger:
    declare
         LN$Pos  pls_integer ;
         LN$Rec  pls_integer := Get_Block_Property('EMP', CURRENT_RECORD) ;
         LN$Max  pls_integer := Get_Block_Property('EMP', RECORDS_DISPLAYED) ;
         LC$C    Varchar2(15) ;
    Begin     
         LN$Pos :=  LN$Rec - (trunc(LN$Rec/LN$Max) * LN$Max) ;
         If LN$Pos = 0 Then LN$Pos := LN$Max ; End if ;
         If LN$Pos > 0 Then
              Set_Custom_Property('EMP.BT', LN$Pos, 'SET_LOG', 'true' );
              -- Add the new item --
              Set_Custom_Property('EMP.BT', LN$Pos, 'SET_NEW_REC', to_char(LN$Rec) );
              -- Set some properties --
              Set_Custom_Property('EMP.BT', LN$Pos, 'SET_LABEL', to_char(LN$Rec) || ',' || :EMP.ENAME );
              If :EMP.JOB = 'MANAGER' Then
                Set_Custom_Property('EMP.BT', LN$Pos, 'SET_FONT', to_char(LN$Rec) || ',Arial,bold,14' );
                Set_Custom_Property('EMP.BT', LN$Pos, 'SET_FGCOLOR', to_char(LN$Rec) || ',0,0,255' );
              End if ;
              If :GLOBAL.I > 250 Then :GLOBAL.I := 5 ;
              Else  :GLOBAL.I := :GLOBAL.I + 5 ;
              End if ;     
              LC$C := To_Char(LN$Rec) || ','
                   || To_Char(255) || ','
                   || To_Char(255-:GLOBAL.I) || ','
                   || To_Char(255-:GLOBAL.I) ;    
              Set_Custom_Property('EMP.BT', LN$Pos, 'SET_BGCOLOR', LC$C );
              Synchronize;
         End if ;
    end;Don't forget to copy the multirecord.jar file in your /forms/java folder, then add it to the archive and archive_jini tags of your /forms/server/formsweb.cfg file.
    Enjoy it,
    Francois

  • Multi-row insert in master-detail tables

    Hi, I'm using jdev 10.1.3.2 with jheadstart and my problem is:
    I hava a master-detail structure, both are tables and my goal is that I want multi insert (exactly 3) in master and detail table when user makes new order(some business scenario). I cannot create rows in master or detail VO by overriding create() method because its entities have complex primary keys and some part of this key is populated by the user with lov. So I set in jhs new rows to 3 and checked multi-row insert allowed but the problem is that overall I can only create rows in master table after I submit form. I want to create row in master table and fill rows in detail table, and after that I want to have opportunity to create second (or even third) row in master table and fill rows in detail table.
    thanks for help.
    Piotr

    See JHS DevGuide: 3.2.1. Review Database Design:
    If you are in the position to create or modify the database design, make sure all
    tables have a non-updateable primary key, preferably consisting of only one
    column. If you have updateable and/or composite primary keys, introduce a
    surrogate primary key by adding an ID column that is automatically populated.
    See section 3.2.4 Generating Primary Key Values for more info. Although ADF
    Business Components can handle composite and updateable primary keys, this
    will cause problems in ADF Faces pages. For example, an ADF Faces table
    manages its rows using the key of the underlying row. If this key changes,
    unexpected behavior can occur in your ADF Faces page. In addition, if you want
    to provide a drop down list on a lookup tables to populate a foreign key, the
    foreign key can only consists of one column, which in turn means the referenced
    table must have a single primary key column.
    Groeten,
    HJH

  • Problem with multi row delete

    Hi, I'm new in apex and I tried to build master detail report on some view. Everything is cool but "delete checked" doesn't work.
    "ORA-20001: Error in multi row delete operation: row= , ORA-06502: PL/SQL: numeric or value error: NULL index table key value,"
    the problem is that I don't know what is wrong :), I have a special trigger "instead of delete on MY_VIEW", but in this error problem is not explained.
    Anybody knows what can be wrong? It is probably a problem with trigger or multi row doesn't work with views? I couldn't find how MRD knows what kind of statement use to delete rows so I don't know if the statement that program used is correct. In debug it lokks that:
    0.32: ...Do not run process "ApplyMRU", process point=AFTER_SUBMIT, condition type=REQUEST_IN_CONDITION, when button pressed=
    0.32: ...Process "ApplyMRD": MULTI_ROW_DELETE (AFTER_SUBMIT) #OWNER#:MY_VIEW:ITEM1:ITEM2
    0.33: Show ERROR page...
    0.33: Performing rollback...
    thanks for any help
    //sorry for english mistakes
    edit: it doesn't matter if I use in trigger delete from ... where item1=:OLD.item1 ; or if I use item1=:P4_item1 (which actually saves correct values)
    Edited by: user5931224 on 2009-06-13 08:55

    I realised that this is not a problem with trigger, I changed trigger to "NULL;" and problem is the same. Maybe sb used master detail on view not only on tables and know what can be wrong in this situation?

  • Multi-row Delete (MRD) on a view?

    All,
    I created a tabular form on a view, using an instead of trigger to encapsulate the logic for the data manipulations. Works great--until someone checks a row and hits the delete button, at which point APEX throws this error:
    ORA-20001: Error in multi row delete operation: row= 107970-18527, ORA-06502: PL/SQL: numeric or value error: character to number conversion error,
    Error     multi row operation failedAs far as I can tell, it's not even getting to the trigger; I commented out the body of the instead of delete trigger (replacing it with null), and I'm still getting the same error. I have no validations or processes on the page at this point.
    The underlying data of the view requires three columns for a unique identifier, so I've concatenated two of them together as an extra column in the view (creating a varchar2 column), and told the MRD to use the calculated column and the third column as the primary key columns. But even using two of the three numeric columns (tweaking the trigger to use a hard-coded value for the third) as an ID fails miserably.
    Any idea what's going on?
    Thanks,
    -David
    (In case it makes a difference, we're on APEX 4.0.1.)

    Hi David,
    This might help:
    http://oraclequirks.blogspot.com/2011/07/ora-20001-error-in-multi-row-delete.html
    Hope it helps!
    Regards,
    Kiran

  • Dynamic visual attributes/multi-row blocks

    We're using Headstart, Des2k V6.0.3.8. If you set preference CURREC = multi record block, you get the current record visual attribute (cg$current_record) attached to all displayed items in multi-row blocks. From the Headstart object library, these items also inherit a visual attribute of qms$item_font.
    At runtime, Headstart code is invoked from the block's post-query trigger - this code dynamically assigns a readonly visual attribute to all items that are insert only, or the qms$item_font va to items that are update only. (Incidentally, it seems a bit strange that no va is assigned to items that are neither insertable nor updateable).
    Assigning the va in this way seems to override the current record va for these items, which looks a little strange at runtime. I would prefer to see the current record va overriding the readonly/item_font va. In a future Headstart release, it would be nice if this functionality was configurable, but in the meantime can you suggest the easiest way of making this change to the Headstart code? I think it will be necessary to specifically set the va to stnd/readonly/current record in the when-new-record-instance trigger, & reset it on the post-record trigger. Once va's are being set dynamically, the current record attribute is pretty useless in multi-row blocks.
    Incidentally - we've also changed the behaviour of va's in query mode processing. We wanted the query mode va to override the current record va; qms$record.highlight_items wasn't setting the selected va unless items have a current record attribute of DEFAULT. We wanted query mode to look the same regardless how many rows are in the block; it also looked a little odd in a multi-row block with overflow items, where the overflow items were being highlighted but the rest of the block wasn't. It would be nice if this was also a configurable option.

    Cheryl,
    Good point! It does look a bit odd. I'll take this into consideration for HSD6i.
    To customize your app, try the following.
    Copy qms$event_data_block from qmsevh50.pll to your application library.
    Copy procedure set_nav_items_exg_record from the qms$record package in qmslib50.pll to your application library -AND GIVE IT A NEW NAME- like set_nav_items_custom.
    Change your copy of qms$event_data_block to call this new procedure in the post-query event.
    Modify set_nav_items_custom as follows.
    ============================================
    procedure set_nav_items_custom
    ( p_block in varchar2
    , p_recno in number default current_record
    is
    l_rg_id recordgroup;
    l_rgc1_id groupcolumn;
    l_rgc2_id groupcolumn;
    rg_rows number;
    l_item_flag varchar2(1);
    l_item_name varchar2(100);
    l_first_io_item varchar2(100);
    begin
    qms$block.init_block_rg
    ( p_block,false,l_rg_id,l_rgc1_id,
    l_rgc2_id, rg_rows);
    if id_null(l_rg_id)
    then
    -- no insert-only or update only items
    -- in block
    return;
    end if;
    for j in 1..rg_rows loop
    l_item_name := get_group_char_cell
    (l_rgc1_id, j );
    l_item_flag := get_group_char_cell
    (l_rgc2_id, j );
    if l_item_flag = 'I'
    then
    if l_first_io_item is null
    then
    l_first_io_item := l_item_name;
    end if;
    -- Item is insert-only, update not
    -- allowed
    -- Change background color to
    -- read-only.
    set_item_instance_property
    ( l_item_name,p_recno,navigable
    , property_false);
    /* customization */
    if get_item_property(l_item_name
    , current_record_attribute) is null
    or p_recno <> :system.cursor_record
    then
    /* end customization */
    set_item_instance_property
    (l_item_name,p_recno
    ,visual_attribute
    ,qms$user_prefs.get_va_readonly_item);
    /* customization */
    end if;
    /* end customization */
    else
    -- Item is update-only, insert not
    -- allowed */
    set_item_instance_property
    (l_item_name,p_recno
    ,navigable,property_true);
    /* customization */
    if get_item_property(l_item_name
    ,current_record_attribute) is null
    or p_recno <> :system.cursor_record
    then
    /* end customization */
    set_item_instance_property
    (l_item_name,p_recno
    ,visual_attribute
    ,qms$config.get_stnd_font);
    /* customization */
    end if;
    /* end customization */
    end if;
    end loop;
    -- 18-1-1999: If block only contains no
    -- updatebale items, there are navigable
    -- items left.
    -- If this is the case make first
    -- insert-only item navigable again.
    if get_block_property(p_block,enterable) =
    'FALSE'
    then
    if l_first_io_item is not null
    then
    set_item_instance_property
    (l_first_io_item,p_recno
    ,navigable,property_true);
    end if;
    end if;
    exception
    when form_trigger_failure then raise;
    when others then
    qms$errors.unhandled_exception
    ('qms$block.set_mav_items_custom');
    end set_nav_items_custom;
    ============================================
    Next, as you suggested, add WHEN-NEW-RECORD-INSTANCE and POST-RECORD triggers to handle movement from one record to the next.
    WHEN-NEW-RECORD-INSTANCE
    ============================================
    procedure set_nav_items_wnri
    ( p_block in varchar2
    , p_recno in number default current_record
    is
    l_rg_id recordgroup;
    l_rgc1_id groupcolumn;
    l_rgc2_id groupcolumn;
    rg_rows number;
    l_item_flag varchar2(1);
    l_item_name varchar2(100);
    begin
    qms$block.init_block_rg
    ( p_block,false,l_rg_id,l_rgc1_id,
    l_rgc2_id, rg_rows);
    if id_null(l_rg_id)
    then
    -- no insert-only or update only items
    -- in block
    return;
    end if;
    for j in 1..rg_rows loop
    l_item_name := get_group_char_cell
    (l_rgc1_id, j );
    l_item_flag := get_group_char_cell
    (l_rgc2_id, j );
    if l_item_flag = 'I'
    then
    -- Item is insert-only, update not
    -- allowed
    -- Change background color to
    -- read-only.
    if get_item_property(l_item_name
    , current_record_attribute) is null
    or p_recno <> :system.cursor_record
    then
    set_item_instance_property
    (l_item_name,p_recno
    ,visual_attribute
    ,qms$user_prefs.get_va_readonly_item);
    else
    set_item_instance_property
    (l_item_name,p_recn o
    ,visual_attribute
    ,get_item_property(l_item_name
    , current_record_attribute));
    end if;
    else
    -- Item is update-only, insert not
    -- allowed */
    if get_item_property(l_item_name
    ,current_record_attribute) is null
    or p_recno <> :system.cursor_record
    then
    set_item_instance_property
    (l_item_name,p_recno
    ,visual_attribute
    ,qms$config.get_stnd_font);
    else
    set_item_instance_property
    (l_item_name,p_recno
    ,visual_attribute
    ,get_item_property(l_item_name
    , current_record_attribute));
    end if;
    end if;
    end loop;
    exception
    when form_trigger_failure then raise;
    when others then
    qms$errors.unhandled_exception
    ('qms$block.set_mav_items_wnri');
    end set_nav_items_wnri;
    ============================================
    For the POST-RECORD trigger, you will have to modify your object library since this trigger is not included by default. Add the trigger to the object library CGSO$BLOCK_MR.
    Then add the POST-RECORD event to your copy of qms$event_data_block.
    Finally, add a procedure for the POST-RECORD trigger.
    ============================================
    procedure set_nav_items_pr
    (p_block in varchar2
    ,p_recno in number default current_record
    is
    l_rg_id recordgroup;
    l_rgc1_id groupcolumn;
    l_rgc2_id groupcolumn;
    rg_rows number;
    l_item_flag varchar2(1);
    l_item_name varchar2(100);
    l_first_io_item varchar2(100);
    begin
    qms$block.init_block_rg
    ( p_block,false,l_rg_id,l_rgc1_id,
    l_rgc2_id, rg_rows);
    if id_null(l_rg_id)
    then
    -- no insert-only or update only items
    -- in block
    return;
    end if;
    for j in 1..rg_rows loop
    l_item_name := get_group_char_cell
    (l_rgc1_id, j );
    l_item_flag := get_group_char_cell
    (l_rgc2_id, j );
    if l_item_flag = 'I'
    then
    -- Item is insert-only, update not
    -- allowed
    -- Change background color to
    -- read-only.
    if l_item_flag = 'I'
    then
    -- Item is insert-only, update not
    -- allowed
    -- Change background color to
    -- read-only.
    set_item_instance_property
    (l_item_name,p_recno
    ,visual_attribute
    ,qms$user_prefs.get_va_readonly_item);
    else
    -- Item is update-only, insert not
    -- allowed
    set_item_instance_property
    (l_item_name,p_recno
    ,visual_attribute
    ,qms$config.get_stnd_font);
    end if;
    end loop;
    exception
    when form_trigger_failure then raise;
    when others then
    qms$errors.unhandled_exception
    ('qms$block.set_mav_items_pr');
    end set_nav_items_pr;
    ============================================
    Regards,
    Lauri

Maybe you are looking for

  • Problem while transporting generic datasource to test box

    Hi Gurus, I am trying to transport Generic datasource from SCM Dev to SCM Test box. Datasource is created with custom table in SCM. It is throwing me RC8. Start of the after-import method RS_ISMP_AFTER_IMPORT for object type(s) ISMP (Activation Mode)

  • Crystal Reports has stopped working with Windows 7 and demo database

    I'm trying to get back up to speed on Crystal Reports after 10 years away. I'm running Crystal Reports 2008 Standard with the just-released Service Pack 3 (same symptom with SP2). So I downloaded the demo database and tried creating a new report. No

  • BPEL Installation Best Practises

    All, I have been tasked with installing BPEL in our test and production environments. It looks like there are several architectural options during installation. Specifically, installing a complete standalone BPEL with it's own home or installing in a

  • Can't log in as administrator after update

    I upgraded to 10.4.8 and now I can't log in as administrator. At the log in screen, it will go away after I enter the passwordand act like it will work, but then the log in screen will appear again. I have a test account that I am still able to log i

  • Cannot associate: No matching privacy setting

    I am trying to create a wireless bridge with 2 1200 AP. The "Client" is giving me this error message: Interface Dot11Radio0, cannot associate: No matching privacy setting (from 001b.d5c8.ce80) This is the master config: version 12.3 no service pad se