更新特定字段后跟随插入的oracle触发器

时间:2017-10-10 16:21:01

标签: oracle triggers

我正在创建一个触发器,它会根据更新后的更新和在更新中引用的某些文本将记录插入到另一个表中。

StaysOpen=False

当我尝试编译时,我收到错误

<Grid>
    <ListBox ItemsSource="{Binding RandomNames}">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition></ColumnDefinition>
                        <ColumnDefinition></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="Name: "
                               Grid.Column="0"/>
                    <TextBlock Grid.Column="1"
                               x:Name="NameBlock"
                               Text="{Binding}">
                        <TextBlock.Style>
                            <Style TargetType="TextBlock">
                                <Style.Triggers>
                                    <Trigger Property="IsMouseOver" Value="True">
                                        <Setter Property="Foreground" Value="Red" />
                                    </Trigger>
                                </Style.Triggers>
                            </Style>
                        </TextBlock.Style>
                    </TextBlock>
                    <Popup x:Name="PopupX"
                           Grid.Column="1"
                           PlacementTarget="{Binding ElementName=NameBlock}"
                           Placement="Bottom">
                        <!--<Popup.IsOpen>
                            <MultiBinding Converter="{StaticResource PopupIsOpenConverter}">
                                <Binding ElementName="PopupX" Path="IsMouseOver" Mode="OneWay" />
                                <Binding ElementName="NameBlock" Path="IsMouseOver" Mode="OneWay" />
                            </MultiBinding>
                        </Popup.IsOpen>-->
                        <Popup.Style>
                            <Style TargetType="Popup">
                                <Setter Property="IsOpen" Value="True" />
                                <Style.Triggers>
                                    <MultiDataTrigger>
                                        <MultiDataTrigger.Conditions>
                                            <Condition Binding="{Binding IsMouseOver, ElementName=NameBlock}" Value="False" />
                                            <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="False" />
                                        </MultiDataTrigger.Conditions>
                                        <Setter Property="IsOpen" Value="False" />
                                    </MultiDataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Popup.Style>
                        <TextBlock Text="{Binding}"
                                   Foreground="Coral" />
                    </Popup>
                </Grid>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</Grid>

有点不确定我哪里出错了?转到错误的源代码将我带到AFTER UPDATE行,但看看示例我看不到有什么问题。我尝试使用SQL Developer的触发器向导,这给了我相同的结果

1 个答案:

答案 0 :(得分:0)

REFERENCING子句仅用于更改内置OLD和NEW记录的名称。 OLD包含更新前行的值,NEW在更新后保存值。以下是您如何使用它们的示例。

create table PM_USER_DATA (user_id varchar2(20), email varchar2(20), change_date date, changeby_char varchar2(20));
create table DEACTIVATED_USERS (username varchar2(20), email varchar2(20), deactivated_date date);

insert into pm_user_data values ('test', 'test@test.com', sysdate, 'SOMEUSER');

create or replace trigger deactivate_users
    after update of changeby_char on pm_user_data
    referencing old as o1 new as n1
    for each row
begin
    if :n1.changeby_char = 'BICSUPP' then
        insert into deactivated_users (username, email, deactivated_date)
            values (:n1.user_id, :n1.email, :n1.change_date);
    end if;
end;
/

update pm_user_data set changeby_char = 'BICSUPP';

select * from deactivated_users;   
/* output: 
USERNAME             EMAIL                DEACTIVATED_DATE
-------------------- -------------------- ----------------
test                 test@test.com        10-OCT-17       
1 row selected.
*/