Skip to main content

Update one table from another which had a join

Update First Table Employee_id with 2nd Table Employee ID

SET TABLEOUTPUT ON
DECLARE
  CURSOR CUR1
  IS
    SELECT A.ID,
      A.EMPLOYEE_ID
    FROM TABLE2 A,
      WHERE A.EMPLOYEE_NAME= 'NEW';
COUNT_UP NUMBER;
BEGIN
  BEGIN
   COUNT_UP := 0;
    FOR CUR2 IN CUR1
    LOOP
      UPDATE TABLE1
      SET EMPLOYEE_ID = CUR2.EMPLOYEE_ID
      WHERE ID = CUR2.ID;
      COUNT_UP := COUNT_UP + 1;
    END LOOP;
  EXCEPTION
  WHEN OTHERS THEN
    NULL;
  END;
  DBMS_OUTPUT.PUT_LINE('Record Update : '||COUNT_UP);
END;

Comments

Popular posts from this blog

Behavior Driven Development

Behavior Driven Development (BDD) is a development process that originally associated with Test-Driven Development (TDD).  BDD is written in a readable format in an understandable language for anyone involved in software development.  BDD Features Providing better readability and visibility.  Verifying the software against customer requirements.  Assure the implementation of the system is correct. Derives examples of different expected behaviors of the system. Uses examples as acceptance tests. Focus on customer requirements throughout the development. BDD Practice There are two practices in BDD:-  Specification by Example (SbE). Test-Driven Development (TDD). Specification by example (SbE) uses examples in conversation to illustrate the business rules and the behavior of the software.  This uses to have a better understanding for Business Analyst, Product Owners, Testers and the Developers to reduce the misunderstanding abou...