2017-05-19 7 views
0

私はストアドプロシージャを持つOracleデータベースを持っています。今度は、ストアドプロシージャを介してのみ挿入、更新、削除して、直接挿入、更新、削除を防ぐ必要があります。オードトームから直接更新と削除を無効にするOracleトリガー

+0

誰かがTOADからストアドプロシージャを実行するとどうなりますか? – APC

+1

より一般的には、解決しようとしているビジネス上の問題を説明してください。これを実行するにはさまざまな方法がありますが、いくつかは予防対策であり、他のものは単なるハードルです。だから、私たちにもっと詳細を伝える必要があります。また、Oracleのどのバージョンおよびどのエディション(エンタープライズ/スタンダード/エクスプレス)? – APC

答えて

1

テーブルのDMLを定義済みのプロシージャセットに制限することはできません。プロシージャの呼び出し方法に関係なく、プロシージャがコールされた場合にのみ、DML操作を許可するという簡単な前提を使用できます。以下はそのためのスケルトンを示しています。上記の場合

Create a package that: 
    1. Define in the SPEC the DML routines. 
    2. Define in the SPEC a function that returns a value indicating whether the DML in allowed or not. 
    3. Create in the BODY the DML procedures and the DML Validation function. 
    4. Define in the BODY a package level control variable indicating DML Allowed or not. 
    5. In the DML routines set he DML Allowed variable to allow the operation. 
    7. In the DML routines always set the DML control variable to disallow the operation completes AND when any exception occurs. 
    8. (optional) Define in the SPEC a user defined error number and message. 

Create a trigger which validates the control variable and throws exception if it's not allowed. 

スケルトン:想定テーブル名=>「My_Special_Table」

Create or Replace package My_Special_Table_DML as 
    Invalid_DML_Requested_num constant number := -20199; --Used define Error 
    Invalid_DML_Requested_msg constant varchar2(80) := 
      'DML on My_Special_Table only allowed through DML routines in Package'; 

    Function Is_DML_Allowed return boolean ; 
    Procedure Delete_My_Special_Table (*parameter list as needed*); 
    Procedure Update_My_Special_Table (*parameter list as needed)*; 
    Procedure Insert_My_Special_Table (*parameter list as needed*); 
end My_Special_Table_DML; 

Create or Replace package My_Special_Table_DML BODY as 
    DML_OK boolean := false;  -- do not allow DML opperation 

    Function Is_DML_allowed return boolean is 
    begin 
    return DML_OK; 
    end Is_DML_Valid ; 

    Procedure Delete_My_Special_Table (*parameter list as needed*) is 
    -- declare local variables 
    Begin 
     DML_OK := true ; 
     ... other code as needed 

     Delete from My_Special_Table .... 

     DML_OK := false ; 
    exception 
    when <expected errors> 
      then 
       DML_OK := false; 
       <code to handle expected errors> 
    when others 
      then 
       DML_OK := false. 
       raise ; 
    end Delete_My_Special_Table; 

    -- *Code for Update and Insert similar to above Delete.* 

end My_Special_Table; 

Create or Replace Trigger My_Special_Table_DML_BIUD 
    before insert or update or delete on My_Special_Table 
is 
begin 
    if not(My_Special_Table_DML.Is_DML_Alloewd) 
    then 
     raise_application_error(Invalid_DML_Requested_num, 
           ,Invalid_DML_Requested_msg 
           ); 
    end if; 
end My_Special_Table_DML_BIUD; 

私はこれのロジックと、なぜそれが動作を把握するためにあなたにお任せします。 しかし、APCの質問に戻る:「誰かがTOADから手順を実行するとどうなりますか?この場合、DMLは、ユーザーがパッケージに対して実行権限を持つ任意のDB接続から許可されます。 TOADを含むがこれに限定されない。

+0

ありがとうございました –

関連する問題