How To Commit Just One Data Block Changes In Oracle Forms

來源:互聯網
上載者:User

標籤:ica   label   top   else   end   https   技術   this   ide   

You have an Oracle Form in which you have multiple data blocks and requirement is to commit just one data block changes and not to effect any other data blocks. But suppose you have a commit_form button also in form which will commit all the data block changes and that functionality is ok and it should be there. But for a specific block there is a requirement to commit only that block changes when edited.

If you got this kind of requirement then you can insert and update records from that data block to database externally, I mean using insert and update statements and not by Oracle form‘s default commit behavior.

To accomplish this task you need to give a push button to the user to save explicitly that data block changes. I have created a form for this example and below is the screen shot of this form:

You can download this form with the following button: Download


As you can see in above picture, there are two blocks, first one is Department and the second one is Employees and there is a push button labeled Commit Employees. In this form if user will change the data in both data blocks and presses the Commit Employees button then it will save only the Employees data block changes.

Following is the code is written in Commit Employees button to perform this task:

DECLARE
   CURSOR c_emp (p_emp emp.empno%TYPE)
   IS
      SELECT ‘Y‘
        FROM emp
       WHERE emp.empno = p_emp;

   v_exists   VARCHAR2 (1);
BEGIN
   GO_BLOCK (‘Emp‘);
   FIRST_RECORD;

   LOOP
      IF :SYSTEM.record_status = ‘CHANGED‘
         OR:SYSTEM.record_status = ‘INSERT‘
      THEN
         OPEN c_emp (:emp.empno);

         FETCH c_emp INTO v_exists;

         CLOSE c_emp;

         IF NVL (v_exists, ‘N‘) = ‘Y‘
         THEN
            UPDATE emp
               SET ename = :emp.ename,
                   job = :emp.job,
                   mgr = :emp.mgr,
                   hiredate = :emp.hiredate,
                   sal = :emp.sal,
                   comm = :emp.comm,
                   deptno = :emp.deptno
             WHERE empno = :emp.empno;
         ELSE
            INSERT INTO emp (empno,
                             ename,
                             job,
                             mgr,
                             hiredate,
                             sal,
                             comm,
                             deptno)
                VALUES (:emp.empno,
                        :emp.ename,
                        :emp.job,
                        :emp.mgr,
                        :emp.hiredate,
                        :emp.sal,
                        :emp.comm,
                        :emp.deptno);
         END IF;
      END IF;

      IF :SYSTEM.LAST_RECORD = ‘TRUE‘
      THEN
         EXIT;
      END IF;

      NEXT_RECORD;
   END LOOP;

   FORMS_DDL (‘commit‘);
   -- REQUERY TO REFRESH CHANGES
   CLEAR_BLOCK (no_validate);
   GO_BLOCK (‘dept‘);
   CLEAR_BLOCK (no_validate);
   EXECUTE_QUERY;
EXCEPTION
   WHEN OTHERS
   THEN
      FORMS_DDL (‘rollback‘);
      MESSAGE (‘error occurred.‘);
END;

What this above code will do is, it will check if record status is changed or new and then it will check from database that the record exists or not and if exists then it will update else will insert a new record.

How To Commit Just One Data Block Changes In Oracle Forms

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.