Solution of table through changing packages

Hello

Help to the understanding of the changing table is necessary.

There is a programming pretty good book by Steven Feuerstein Oracle PL/SQL, where he described a traditional solution based on packaging.

I'm placing the inscription of the book below.

There are two approaches for data integrity suporting but I can't why they are used when the values of package variables are unique for some session.

  • First why the starting_corrections procedure is used (i.e. line 94)?

My guess is to protect the collection internal g_emp_info of change in call fair make_ parallel proceedings in the same session.

  • Second, what is the purpose of the command LOCK TABLE used in EXCLUSIVE MODE (line 129)?

I have no idea on the neseccity of the present.

BY l_max _allowed

Please sew someone please explain to me why this safe methods have been applied?

/*
The rule is: your new salary cannot be more than 
25x the lowest salary in your department. So at
the row level we set the salaries, and keep track
of whose salaries were changed. Then at the statement
level, we get the lowest salary, compute the new
equitable maximum, and then apply it to any salaries which 
exceeded that. 
*/ 

CREATE OR REPLACE PACKAGE equitable_salaries_pkg
IS
   PROCEDURE initialize;


   PROCEDURE add_employee_info (
      employee_id_in IN employees.employee_id%TYPE
    , salary_in IN employees.salary%TYPE
   );


   PROCEDURE make_equitable;
END equitable_salaries_pkg;
/

CREATE OR REPLACE PACKAGE BODY equitable_salaries_pkg
IS
   TYPE id_salary_rt IS RECORD (
      employee_id   employees.employee_id%TYPE
    , salary        employees.salary%TYPE
   );


   TYPE g_emp_info_t IS TABLE OF id_salary_rt
      INDEX BY PLS_INTEGER;


   g_emp_info                 g_emp_info_t;
   g_corrections_in_process   BOOLEAN      := FALSE;


   PROCEDURE initialize
   IS
   BEGIN
      g_emp_info.DELETE;
   END initialize;


   PROCEDURE finished_corrections
   IS
   BEGIN
      g_corrections_in_process := FALSE;
   END finished_corrections;


   PROCEDURE starting_corrections
   IS
   BEGIN
      g_corrections_in_process := TRUE;
   END starting_corrections;


   FUNCTION corrections_in_process
      RETURN BOOLEAN
   IS
   BEGIN
      RETURN g_corrections_in_process;
   END corrections_in_process;


   PROCEDURE add_employee_info (
      employee_id_in IN employees.employee_id%TYPE
    , salary_in IN employees.salary%TYPE
   )
   IS
      l_index   PLS_INTEGER := g_emp_info.COUNT + 1;
   BEGIN
      IF NOT corrections_in_process
      THEN
         g_emp_info (l_index).employee_id := employee_id_in;
         g_emp_info (l_index).salary := salary_in;
         --
          END IF;
   END add_employee_info;


   PROCEDURE make_equitable
   IS
      l_max_allowed   employees.salary%TYPE;
      l_index         PLS_INTEGER;
   BEGIN
      IF NOT corrections_in_process
      THEN
         starting_corrections;


         SELECT MIN (salary) * 25
           INTO l_max_allowed
           FROM employees;


        WHILE (g_emp_info.COUNT > 0)
         LOOP
            l_index := g_emp_info.FIRST;
            --
           IF l_max_allowed < g_emp_info (l_index).salary
            THEN
               UPDATE employees
                  SET salary = l_max_allowed
                WHERE employee_id = g_emp_info (l_index).employee_id;
            END IF;


            g_emp_info.DELETE (g_emp_info.FIRST);
         END LOOP;


         finished_corrections;
      END IF;
   END make_equitable;
END equitable_salaries_pkg;
/


CREATE OR REPLACE TRIGGER equitable_salaries_bstrg
   before INSERT OR UPDATE 
   ON employees
BEGIN
   LOCK TABLE employees IN EXCLUSIVE MODE;
   equitable_salaries_pkg.initialize;
END;
/


CREATE OR REPLACE TRIGGER equitable_salaries_rtrg
   AFTER INSERT OR UPDATE OF salary
   ON employees
   FOR EACH ROW
BEGIN
   equitable_salaries_pkg.add_employee_info (:NEW.employee_id, :NEW.salary);
END;
/


CREATE OR REPLACE TRIGGER equitable_salaries_astrg
   AFTER INSERT OR UPDATE 
   ON employees
BEGIN
   equitable_salaries_pkg.make_equitable;
END;
/


BEGIN
   UPDATE employees
      SET salary = 100000
    WHERE last_name = 'King';


   ROLLBACK;
END;
/

1 procedure make_equitable has updated itself that fires triggers in the same session. That's why we need to prevent correction running code again.

2. you are right, that is to ensure that all updates are are serialized. It is not advisable. The lock must be put on the level of service, for example select... of the Department where deptno =... for update

Tags: Database

Similar Questions

  • Changing table via the package with immediate execution (problem)

    Hello

    I have a unusual problem. I have a package that contains the procedure that via execute immediate statement, creates a table on which he performs different actions for example:

    -alter table some_owner.dummy_table noparallel

    -create index some_owner.idx_name on some_owner.dummy_table (column)...

    But I only managed to run move and create synonym table/public via execute immediate statement. Actions as alter table and create index fails with error ORA-01031: insufficient privileges.

    Note If call these commands outside the package (a simple script) this all done OK.

    I found a way, where I set the AUTHID CURRENT_USER command create package statement. In this way all the actions executed OK.

    I wonder why I can't change the table via the package with immediate execution on a table that is in the tablespace "SOME_TABLESPACE" and the title of owner "SOME_OWNER", without putting the AUTHID command on the package.

    There must be a problem why a package cannot change the table which is owned by the user 'SOME_OWNER '.

    All useful responses would be appreciated.

    I have a unusual problem.

    No - you don't have. This question has been answered SEVERAL times on this forum and others.

    But I only managed to run move and create synonym table/public via execute immediate statement. Actions as alter table and create index fails with error ORA-01031: insufficient privileges.

    OK - your username doesn't have privileges to do these operations or only received privileges through roles.

    Roles are DISABLED in named PL/SQL blocks that use of the AUTHOR's rights.

    Note If call these commands outside the package (a simple script) this all done OK.

    I found a way, where I set the AUTHID CURRENT_USER command create package statement. In this way all the actions executed OK.

    Of course - the roles are NOT disabled in named PL/SQL blocks that use the rights of the APPELLANT or in anonymous blocks.

    I wonder why I can't change the table via the package with immediate execution on a table that is in the tablespace "SOME_TABLESPACE" and the title of owner "SOME_OWNER", without putting the AUTHID command on the package.

    Well now you know!

  • I get an error message after importing a table through Dreamweaver in a page developed by Muse.

    I get a few messages after importing a table through Dreamweaver in a page developed by Muse. I compared the code of the page with the table on page until I inserted table and cannot find anything missing. the web address is http://gourmetdreams.com/weekly-menu.html

    How can I erase this upward?

    I also noticed that when I downloaded the file there was a mistake: "- error - access denied."  The file exists may not be not on-site, can be opened in another program, or there might be a problem of local authorization. »

    Screen Shot 2014-10-30 at 1.53.15 PM.pngScreen Shot 2014-10-31 at 4.39.09 PM.png

    I'm working on a project were I am importing to Dreamweaver html code. I just do all of my changes in Dreamweaver and then re-import the file.

    You can make changes in the file inside Muse. Just right click on your imported html file and select "edit HTML" in the menu list.

    It will bring to the top of the dialog box where you can change the text/code

  • HP ProBook 4530 s: permanent Solution to continue to change fonts

    I need a permanent solution to stop policies changing of large and small without my Commander there.

    This could be a problem with your operating system and programs that are having problems. I looked and problems of fonts online but without shrinkage is where problems arise since you say it happens in place then another again suggests something wrong with your system files are corrupted. So, they can not keep the same font sizes. If you look online there is a police of problems of size and a lot of different software programs. Only thing I can say is turn off your laptop keyboard and use a USB keyboard and try typing with it to see if the font size problem is not related to problems of keyboard? Because yours is not limited to a single program, I think that the problem may be with your keyboard itself?

  • How to know the tables used in packages of a schema.

    How to know the tables used in packages of a pattern that I have connected.

    SELECT DISTINCT referenced_owner, referenced_name

    Of all_dependencies

    Owner WHERE = "MY_USER_NAME".

    AND type ('PACKAGE', 'BODY of PACKAGE')

    AND referenced_type = 'TABLE '.

  • ERROR / T_ITEMS in the TABLE is changing, function of triggering/can not see ORA-06512... ?

    Hi all

    I CREATED THE TRIGGER TO CHECK NOM_ELEMENT BEFORE UPDATE ON THE T_ITEMS TABLE IF AN ANOTHER NOM_ELEMENT LIKE NOM_ELEMENT CURRENT OR NOT, IF AS AN ANOTHER NOM_ELEMENT DON'T SAVE UPDATED CURRENT NOM_ELEMENT.

    MY NO IS:

    1 - I CREATED the FUNCTION CALL CH_UNIQUE_ITEM_NAME

    CREATE OR REPLACE FUNCTION CH_UNIQUE_ITEM_NAME
    (NUMBER OF P_ID, P_ITEM_NAME IN VARCHAR2)
    RETURN NUMBER
    AS
    NUMBER OF X_COUNT;
    -FUNCTION "CH_UNIQUE_ITEM_NAME" TO CHECK NOM_ELEMENT LIKE OTHER NOM_ELEMENT OR NOT.
    BEGIN
    SELECT COUNT (ITEM_NAME)
    IN X_COUNT
    OF T_ITEMS
    WHERE ID! P_ID =
    AND UPPER (ITEM_NAME) AS UPPER (P_ITEM_NAME);
    RETURN X_COUNT;
    END CH_UNIQUE_ITEM_NAME;

    2. I CREATED TRIGGER CALL TRG_CH_UNIQUE_T_ITEMS

    CREATE OR REPLACE 'TRG_CH_UNIQUE_T_ITEMS' before FIRING
    UPDATE
    ON T_ITEMS FOR EACH LINE
    DECLARE
    NUMBER OF X_CHECK;
    BEGIN
    SELECT CH_UNIQUE_ITEM_NAME (: OLD.ID,: NEW.) NOM_ELEMENT) IN DOUBLE X_CHECK;
    IF (: NEW.) NOM_ELEMENT DISLIKES: OLD. Nom_element AND X_CHECK > 0)
    THEN RAISE_APPLICATION_ERROR (-20007, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    END IF;
    END;

    NOW WHEN I UPDATE ANY ITEMS FOUND ERROR "ERROR / T_ITEMS in the TABLE is changing, function of triggering/can not see ORA-06512.

    Form on T_ITEMS22222.png

    Please help me TO RESOLVE THIS ERROR. I TIRED TO SOLVE...

    Thank you

    You don't realize that you have just set a UNIQUE INDEX of several columns?

    create unique index index_name_uq on table_name( user#, upper(item_name) );
    

    In addition, a GUI Design point, (using the terms of the APEX) that you want to validate the data before submit you.

    (use a Page-level Validation)

    MK

  • Cannot update the END_DATE_ACTIVE column in the HZ_CODE_ASSIGNMENTS Table through the API

    Hello

    I'm not able to update the column END_DATE_ACTIVE HZ_CODE_ASSIGNMENTS Table through the API: hz_classification_v2pub.update_code_assignment.
    After running with all the facings that he managed, but it is not properly updated the end_date_active to the date given as parameters when executing the API defines it rather end_date_active to null.

    Please help.

    Thanks and greetings

    Salvation;

    What is your version of the EBS? If you are on r12.x you can hit bug. Please see:
    Unable to update HZ_CODE_ASSIGNMENTS end_date_active with January 1, 2012 [1166367.1 ID]

    Respect of
    HELIOS

  • DDL change packages in Golden Gate

    We have an application that is built entirely using oracle PL/SQL packages. which means that he is no average app. This application is accessed through the Apache web server.
    There is no Golden Gate installed for replication of the data on this server to generate reports. Packages are often being changed and installed (create or replace). Sometimes there are structural changes to tables such as add a new column. In this case, what kind of change control process is recommended?

    I would like to propose that stop us every process GG prerequisites changes and restart after completion. In this case is GG extract be able to enter the changes in the files of trail and propagate to the target, because it's a stop during the changes? Or y at - it another way to manage the change control? We had a few cases in which extract and replicat process erupted when this change was made (CREATE OR REPLACE a PACKAGE / INDEX DUPLICATED / TABLE COLUMN ADDED).

    Please provide your valuable contributions.

    Thank you

    Without regard to regenerate the defgen file (or avoid having to use them altogether), what DOF you want to replicate in the first place? If I had a lot of changes, I would consider not not using the DDL replication. Stop the process, apply the DDL on both ends, and repeat. Or separate the objects where changes occur (put them in their own process group). In this way, not all replication must stop.

  • Backup Tables, triggers and packages/procedures

    Oracle 11.2 and Developer SQL 3.2.

    For the backup of the data, I use OEM/Rman to schedule a backup.  My understanding, these are usually data only (physical backup).

    Now, I want to make the backup of the logic for the tables, packages/procedures and triggers.  I currently use Oracle SQL Developer to export as separate SQL files.

    I wonder if there are any other options to save the tables, procedures and triggers?

    Currently I am guard three types of backups:

    (1) creation of user scripts, role and grant the user privileges.

    (2) tables, packages/procedures and triggers saved via Oracle SQL Developer

    (3) data ora saved through OEM

    Total crash of DB, I'll run the script to create users, role, and grant privileges.  Then log in as an authorized user and run the sql scripts to create the tables, procedures, packages, and triggers; Finally, to recover the data via RMAN.

    Is this a good practice for backup/recovery, or there are ways to do better?

    Thank you.

    Scott

    scottjhn wrote:

    Oracle 11.2 and Developer SQL 3.2.

    For the backup of the data, I use OEM/Rman to schedule a backup.

    Additional OEM backup.

    The backup operation is made by rman.

    My understanding, these are usually data only (physical backup).

    RMAN backup of the physical database.  Technically, it makes copies of data blocks in the data files.  He does not know, nor she cares, that contains a given block.  And this data block "term" is wider than you can imagine.  Consider this: the entire database - tables, indexes, the data dictionary (which itself is nothing more than a collection of tables), stored the DDL, code compiled... everything fits in these data files and data files are all made up of blocks of 'data '.

    Now, I want to make the backup of the logic for the tables, packages/procedures and triggers.  I currently use Oracle SQL Developer to export as separate SQL files.

    I wonder if there are any other options to save the tables, procedures and triggers?

    That's what rman.  backup of tables, procedures, triggers,... everything.

    Currently I am guard three types of backups:

    (1) creation of user scripts, role and grant the user privileges.

    (2) tables, packages/procedures and triggers saved via Oracle SQL Developer

    (3) data ora saved through OEM

    Total crash of DB, I'll run the script to create users, role, and grant privileges.

    DB crash, you want to have a database to run these scripts.  You will FIRST need to restore/recovery database... backups rman.

    Then log in as an authorized user and run the sql scripts to create the tables, procedures, packages and triggers.

    ; You don't have to run all the scripts, because all the tables, procedures/packckages, and triggers will have already been restored by rman when he corrected/restored the database.

    Finally, retrieve the data via RMAN.

    And, precisely, what do you think this means at this point?

    Is this a good practice for backup/recovery, or there are ways to do better?

    There are much better ways.  Especially what you describe will not work.

    You have a serious misunderstanding on what rman is and does.  You need to spend some serious time, read the rman users guide, at https://docs.oracle.com/cd/E11882_01/backup.112/e10642/toc.htm

    And, FWIW, I would NOT recommend depending on the OEM manufacturer to plan backups or perform a recovery.

  • Problems with highlighting of the rows of the table through RTF-model

    Hello!

    Peace im new in the world of BI Publisher. For the moment, I try to create and RTF-model with the Office AddIn for Word Bi-editeur (2010). I want to create a table based on a table of a pdf document existing already. I have all the data in the right format and order and just worked fine - until I wanted to change the background color of some specific lines.
    If I add that a statement such as

    <? If: Variable = "Expressionstring?" > <? attribute@InContext:background-color;' #FFFF80 '? > <? end if? >

    the context of the evolution of the entry. But the fact the line height. It develops. The expressions more that I use more it grows. That of not good, because the table is so great that it only fits on a single page with fine lines... I tried to apply a height specified in the line through the word, but it does not work.
    I searched a couple hours and still didn't find anything regarding this problem. I appreciate any ideas how to solve this problem.

    Tounsiiaa in advance

    Gabriel

    To help those who have a similar problem: it's just like sfr.farhan.fani wrote. I try to give you a general expression:


    <? If@row:ROWNAME=VALUE? > (this should work with = > etc do not forget the ' ' for strings etc..)

    < xsl: attribute name = 'background-color' xdofo:ctx = 'incontext' > lightgray < / xsl: attribute > (lightgray can be changed to hexa% and %valeurs)

    <? end if? >

    Hello

    Try the following expression

    5000? >

    LightGray

  • a loop in a table to change the visibility of the MC

    Hey to anyone, let's say I have a loop for (), which creates an instance of a movieClip newText that contains the textfields on the inside that is pushed through a table and displayed by the table when my application is restarted.

    and newText, I also have a button inside of it deletes the information (options), and when this button is pressed a different MC (delete) appears on newText.

    What is my best way to check if this key has been pressed? should I create another table which moves to 'true' in the table and check if (arrayCheck ["?"] == true) {what I'm doing here};... etc I'm lost.

    because I want to do MC (delete) visibility = true; When the application is restarted for instances of newText, when (options) button has been clicked. any ideas would be highly appreciated?

    HERE'S MY FOR LOOP, I HAVE ALREADY

    __________________________________________________________________________________________ ______________________________________________________________________________________

    Kellog var: number = - 5;

    This variable defines array to 1 index

    general var: number = - 1;

    for (var i: number = 0; i < mySaveNewT.data.myNText; ++ I) {}

    newText = new tbox();

    newText.x = - 220;

    newText.y =-513 + i * 0 * 69 + 3.8.

    Kellog += 6;  as a result, each correct index in array to textfield in newText

    Kellogs += 6; / / as a result, each correct index in array to textfield in newText

    trace (kellogs, "total cereal");

    newText.CN.text = String (unwrap.mySaveData.data.myDataArray [kellog]);

    newText.DF.text = String (unwrap.mySaveData.data.myDataArray [2 + General kellog]);

    newText.Ad.text = String (unwrap.mySaveData.data.myDataArray [3 + General kellog]);

    newText.PN.text = String (unwrap.mySaveData.data.myDataArray [4 + General kellog]);

    newText.tap.text = String (unwrap.mySaveData.data.mynText [kellogs]);

    newText.tip.text = String (unwrap.mySaveData.data.mynText [kellogs + General]);

    newText.OT.text = String (unwrap.mySaveData.data.myDataArray [5 + General kellog]);

    VWD.addChild (newText);


    myDataArrayInProgram = unwrap.mySaveData.data.myDataArray;

    myNTextAddition = unwrap.mySaveData.data.mynText;

    }

    then why are assign you to I have?

    again, use the code I suggested, but change the btn to options (if that's really your name of buttons).

    var so:SharedObject = SharedObject.getLocal ("kellogs", "/");

    If (SO. Data.btnClickA & so. Data.btnClickA.Length > 0) {}

    for (var i: int = 0; i<>

    trace ("button", so.data.btnClickA [i], "has been clicked")

    }

    } else {}

    [from = so.data.btnClickA];

    }

    for (var i: number = 0; i)< mysavenewt.data.myntext;="" ++i)="">

    newText = new tbox();

    newText.x = - 220;

    newText.options.addEventListener (MouseEvent.CLICK, buttonF);

    newText.ivar = i;

    .

    }

    function buttonF(e:MouseEvent):void {}

    var i: int is MovieClip (e.currentTarget.parent) .ivar;.

    {if (SO. {(Data.btnClickA.IndexOf (i) ==-1)}

    so.data.btnClickA.push (i);

    }

    }

  • Update Manager, set change packages, target database is not picking up the connection ID

    We have recently improved of PeopleTools 8.53.02 to PeopleTools 8.53.08 to upgrade to 9.2 HCM.  Therefore, a package must be created for tax updates through image 003.  However, when you attempt to set a 'new' package, the login id on the target patching database information is empty.  The process will not move forward on the creation of the package of changes.  Environments (London) have all been deleted and recreated without exception.

    Thank you

    To address this problem, I had to open settings changing Assistant for the demonstration system environment.  I added the connection id to this environment and now it works like a charm.

  • How to access a table for changes

    I'm an iteration through the FMP objects in a stream, and for each of them, waiting for the anchors in the table. I find the anchor point of the table, then what should I do to access its object Tbl and doing things with him? Just trying to know if there is some changebars in the table. I don't think using Doc.FirstTblInDoc will help me because I'm starting with a text TblAnchor element.

    I run this code on a doc that has only one paragraph with an anchor of the inside table:

    function test() {}

    doc = app. ActiveDoc;

    FMP var is doc. MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;

    While (FMP. ObjectValid()) {}

    var textitems is bmp. GetText (Constants.FTI_TblAnchor);

    var aa = textitems [0];

    Console ("what is it:"+ aa ");

    PGF = bmp. NextPgfInFlow;

    }

    }

    This displays "what: [object TextItem]."

    Looks like I'd be able to do something like that to get the object Tbl:

    myTable = textitems [0] .idata;

    Am I hot? Once I get the object Tbl, I hope it's a simple matter of the use of GetText for changes, then find a changebar.

    Thank you

    Mark

    This should give you the object Tbl (table):

    myTable = textItems[0].obj;
    
  • I want to allow users to update the table through Web pages, but not directly

    Hi guys,.

    I have a question. There is a Web page that people are going to and through that they get into stuff and delete stuff. Therefore, it must be select, insert, delete and update on the table. Because they can only do so via the buttons on the Web page, they are not able to remove the other stuff of users.
    However, nothing to prevent them from being able to connect via sqlplus say and removing stuff directly in the table. How to work around this problem?

    Thank you

    OracleGuy777 wrote:
    (1) for the joint account, everyone will still be need to know the password, Yes? Otherwise, how would they be able to connect? If they need the password, what is to prevent them from logging in via sqlplus using shared account and then delete stuff?

    N ° the password on behalf of shared database would not be known by users, it could just be stored on the server somewhere intermediate (intermediate level different servers have different options for storing secure passwords on the middle tier). Then create you users of the application (i.e. an array of USERS with a user_name and a hashed_password column) and do check this hash name & password of the user when the user tries to log on by your application.

    (2) Let's say I control access via a stored procedure and call it my request. users can still connect via sqlplus and call him too much, they don't? so removing the stuff?

    Yes, if your users have a data account, and this account has access EXECUTE on the stored procedure, they could connect through SQL * more and run it. If you gave them permission to delete a particular entity, however, why is - this important if they do it through your app through SQL * Plus, or via another utility? If you put the logic for change, to verify that the user is allowed to delete the particular line, etc. in the stored procedure, the audit security implications should not depend on the front end.

    Justin

  • accidentally credited the poster of evil with a solution, how can I change?

    So, this is my third post to this community. My first post asked for a solution to a problem I had. My second post was to thank the poster who provided the solution, and then click the correct answer in the box of the poster. At least that is what I thought I did. However my second post has now determined in the thread that the post correct answer. Shortly after, I received a private message the poster who correctly answered to my question, angry with me to credit me instead of the correct poster for having responded to the question. How can I fix this error? I have checked and don't see any obvious way to cancel my previous answer mouse click.

    You can not fix it. Once the post is marked solved and points to be awarded, it cannot be changed. It was a good faith mistake. Don't worry about this.

Maybe you are looking for