Oracle
 sql >> Teknologi Basis Data >  >> RDS >> Oracle

Bagaimana Cara Menghasilkan Paket Tabel API di Oracle SQL Developer?

Di Oracle SQL Developer, ada opsi untuk menghasilkan Paket API Tabel yang dengannya Anda dapat dengan mudah mengelola penyisipan, pembaruan, dan penghapusan untuk sebuah tabel. Selanjutnya, Anda dapat memodifikasi lebih banyak untuk menambahkan perubahan yang diperlukan.

Langkah-Langkah Membuat Paket Tabel API di Oracle SQL Developer (Versi 18.1)

  1. Di Oracle SQL Developer, sambungkan ke pengguna database dan di sisi kiri (panel koneksi) perluas node tabel.
  2. Pilih tabel dan lakukan klik kanan pada tabel untuk membuka menu pintasan.
  3. Dari menu, pilih Buat Tabel API pilihan dan klik di atasnya.
  4. Ini akan menghasilkan skrip paket untuk tabel yang dipilih dan akan terbuka di sisi kanan editor SQL.
  5. Sekarang Anda dapat menjalankan skrip untuk membuat paket dalam skema database Anda.

Anda dapat membuat paket DML online, periksa tautan ini: Buat Paket DML Online

Di bawah ini adalah contoh skrip paket untuk Tabel API. Dihasilkan dari tabel Karyawan skema SDM.

Contoh Skrip Tabel API

CREATE OR REPLACE PACKAGE EMPLOYEES_tapi
IS
   TYPE EMPLOYEES_tapi_rec IS RECORD (
      JOB_ID           EMPLOYEES.JOB_ID%TYPE,
      EMPLOYEE_ID      EMPLOYEES.EMPLOYEE_ID%TYPE,
      SALARY           EMPLOYEES.SALARY%TYPE,
      HIRE_DATE        EMPLOYEES.HIRE_DATE%TYPE,
      DEPARTMENT_ID    EMPLOYEES.DEPARTMENT_ID%TYPE,
      LAST_NAME        EMPLOYEES.LAST_NAME%TYPE,
      EMAIL            EMPLOYEES.EMAIL%TYPE,
      PHONE_NUMBER     EMPLOYEES.PHONE_NUMBER%TYPE,
      FIRST_NAME       EMPLOYEES.FIRST_NAME%TYPE,
      COMMISSION_PCT   EMPLOYEES.COMMISSION_PCT%TYPE,
      MANAGER_ID       EMPLOYEES.MANAGER_ID%TYPE
   );

   TYPE EMPLOYEES_tapi_tab IS TABLE OF EMPLOYEES_tapi_rec;

   -- insert
   PROCEDURE ins (
      p_JOB_ID           IN EMPLOYEES.JOB_ID%TYPE,
      p_EMPLOYEE_ID      IN EMPLOYEES.EMPLOYEE_ID%TYPE,
      p_SALARY           IN EMPLOYEES.SALARY%TYPE DEFAULT NULL,
      p_HIRE_DATE        IN EMPLOYEES.HIRE_DATE%TYPE,
      p_DEPARTMENT_ID    IN EMPLOYEES.DEPARTMENT_ID%TYPE DEFAULT NULL,
      p_LAST_NAME        IN EMPLOYEES.LAST_NAME%TYPE,
      p_EMAIL            IN EMPLOYEES.EMAIL%TYPE,
      p_PHONE_NUMBER     IN EMPLOYEES.PHONE_NUMBER%TYPE DEFAULT NULL,
      p_FIRST_NAME       IN EMPLOYEES.FIRST_NAME%TYPE DEFAULT NULL,
      p_COMMISSION_PCT   IN EMPLOYEES.COMMISSION_PCT%TYPE DEFAULT NULL,
      p_MANAGER_ID       IN EMPLOYEES.MANAGER_ID%TYPE DEFAULT NULL);

   -- update
   PROCEDURE upd (
      p_JOB_ID           IN EMPLOYEES.JOB_ID%TYPE,
      p_EMPLOYEE_ID      IN EMPLOYEES.EMPLOYEE_ID%TYPE,
      p_SALARY           IN EMPLOYEES.SALARY%TYPE DEFAULT NULL,
      p_HIRE_DATE        IN EMPLOYEES.HIRE_DATE%TYPE,
      p_DEPARTMENT_ID    IN EMPLOYEES.DEPARTMENT_ID%TYPE DEFAULT NULL,
      p_LAST_NAME        IN EMPLOYEES.LAST_NAME%TYPE,
      p_EMAIL            IN EMPLOYEES.EMAIL%TYPE,
      p_PHONE_NUMBER     IN EMPLOYEES.PHONE_NUMBER%TYPE DEFAULT NULL,
      p_FIRST_NAME       IN EMPLOYEES.FIRST_NAME%TYPE DEFAULT NULL,
      p_COMMISSION_PCT   IN EMPLOYEES.COMMISSION_PCT%TYPE DEFAULT NULL,
      p_MANAGER_ID       IN EMPLOYEES.MANAGER_ID%TYPE DEFAULT NULL);

   -- delete
   PROCEDURE del (p_EMPLOYEE_ID IN EMPLOYEES.EMPLOYEE_ID%TYPE);
END EMPLOYEES_tapi;
/

CREATE OR REPLACE PACKAGE BODY EMPLOYEES_tapi
IS
   -- insert
   PROCEDURE ins (
      p_JOB_ID           IN EMPLOYEES.JOB_ID%TYPE,
      p_EMPLOYEE_ID      IN EMPLOYEES.EMPLOYEE_ID%TYPE,
      p_SALARY           IN EMPLOYEES.SALARY%TYPE DEFAULT NULL,
      p_HIRE_DATE        IN EMPLOYEES.HIRE_DATE%TYPE,
      p_DEPARTMENT_ID    IN EMPLOYEES.DEPARTMENT_ID%TYPE DEFAULT NULL,
      p_LAST_NAME        IN EMPLOYEES.LAST_NAME%TYPE,
      p_EMAIL            IN EMPLOYEES.EMAIL%TYPE,
      p_PHONE_NUMBER     IN EMPLOYEES.PHONE_NUMBER%TYPE DEFAULT NULL,
      p_FIRST_NAME       IN EMPLOYEES.FIRST_NAME%TYPE DEFAULT NULL,
      p_COMMISSION_PCT   IN EMPLOYEES.COMMISSION_PCT%TYPE DEFAULT NULL,
      p_MANAGER_ID       IN EMPLOYEES.MANAGER_ID%TYPE DEFAULT NULL)
   IS
   BEGIN
      INSERT INTO EMPLOYEES (JOB_ID,
                             EMPLOYEE_ID,
                             SALARY,
                             HIRE_DATE,
                             DEPARTMENT_ID,
                             LAST_NAME,
                             EMAIL,
                             PHONE_NUMBER,
                             FIRST_NAME,
                             COMMISSION_PCT,
                             MANAGER_ID)
          VALUES (p_JOB_ID,
                  p_EMPLOYEE_ID,
                  p_SALARY,
                  p_HIRE_DATE,
                  p_DEPARTMENT_ID,
                  p_LAST_NAME,
                  p_EMAIL,
                  p_PHONE_NUMBER,
                  p_FIRST_NAME,
                  p_COMMISSION_PCT,
                  p_MANAGER_ID);
   END;

   -- update
   PROCEDURE upd (
      p_JOB_ID           IN EMPLOYEES.JOB_ID%TYPE,
      p_EMPLOYEE_ID      IN EMPLOYEES.EMPLOYEE_ID%TYPE,
      p_SALARY           IN EMPLOYEES.SALARY%TYPE DEFAULT NULL,
      p_HIRE_DATE        IN EMPLOYEES.HIRE_DATE%TYPE,
      p_DEPARTMENT_ID    IN EMPLOYEES.DEPARTMENT_ID%TYPE DEFAULT NULL,
      p_LAST_NAME        IN EMPLOYEES.LAST_NAME%TYPE,
      p_EMAIL            IN EMPLOYEES.EMAIL%TYPE,
      p_PHONE_NUMBER     IN EMPLOYEES.PHONE_NUMBER%TYPE DEFAULT NULL,
      p_FIRST_NAME       IN EMPLOYEES.FIRST_NAME%TYPE DEFAULT NULL,
      p_COMMISSION_PCT   IN EMPLOYEES.COMMISSION_PCT%TYPE DEFAULT NULL,
      p_MANAGER_ID       IN EMPLOYEES.MANAGER_ID%TYPE DEFAULT NULL)
   IS
   BEGIN
      UPDATE EMPLOYEES
         SET JOB_ID = p_JOB_ID,
             SALARY = p_SALARY,
             HIRE_DATE = p_HIRE_DATE,
             DEPARTMENT_ID = p_DEPARTMENT_ID,
             LAST_NAME = p_LAST_NAME,
             EMAIL = p_EMAIL,
             PHONE_NUMBER = p_PHONE_NUMBER,
             FIRST_NAME = p_FIRST_NAME,
             COMMISSION_PCT = p_COMMISSION_PCT,
             MANAGER_ID = p_MANAGER_ID
       WHERE EMPLOYEE_ID = p_EMPLOYEE_ID;
   END;

   -- del
   PROCEDURE del (p_EMPLOYEE_ID IN EMPLOYEES.EMPLOYEE_ID%TYPE)
   IS
   BEGIN
      DELETE FROM EMPLOYEES
            WHERE EMPLOYEE_ID = p_EMPLOYEE_ID;
   END;
END EMPLOYEES_tapi;

Bagaimana Cara Menggunakan Tabel API?

Sekarang misalkan Anda ingin menghapus catatan karyawan dari tabel Karyawan, kemudian gunakan prosedur API paket EMPLOYEES_TAPI.DEL sebagai berikut:

DECLARE 
  P_EMPLOYEE_ID NUMBER;

BEGIN 
  P_EMPLOYEE_ID := 105;

  EMPLOYEES_TAPI.DEL ( P_EMPLOYEE_ID );
  COMMIT; 
END;

Lihat juga:

  • Membuat Tabel di Pengembang Oracle SQL

  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Apa cara terbaik untuk keluar dari karakter non-format di Oracle's to_char?

  2. Sesi tidak aktif di Oracle oleh JDBC

  3. Pengantar Metode Pengumpulan PL/SQL Dalam Database Oracle

  4. NVL2() Fungsi di Oracle

  5. Permintaan Oracle sederhana:literal tidak cocok dengan string format