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

Ekspor Data ke File JSON di Oracle 11g Menggunakan PL/SQL

Pada artikel ini, saya memberikan contoh untuk mengekspor data ke file JSON di Oracle 11g menggunakan PL/SQL.

Ikuti Langkah-Langkah Ini untuk Mengekspor Data ke File JSON di Oracle 11g

  1. Pertama, unduh paket utilitas Alexandria PL/SQL dari GITHUB menggunakan tautan berikut:Unduh paket alexandria_plsql_utility.
  2. Setelah mengunduh file zip, ekstrak dan temukan JSON_UTIL_PKG di direktori "alexandria-plsql-utils-master\alexandria-plsql-utils-master\ora".
  3. Instal spesifikasi dan isi paket JSON_UTIL_PKG ke dalam skema Anda
  4. Setelah itu unduh prosedur PL/SQL "WRITE_CLOB_TO_FILE" dari tautan berikut:Unduh Write_Clob_To_File.
  5. Instal prosedur ini juga ke dalam skema Anda.

Sekarang Anda dapat membuat file JSON dari tabel Oracle menggunakan PL/SQL, seperti yang ditunjukkan pada contoh di bawah ini.

Contoh Oracle 11g SQL ke JSON

Pada contoh berikut, kita akan memasukkan data ke dalam variabel CLOB menggunakan fungsi JSON_UTIL_PKG.SQL_TO_JSON dan kemudian kita akan menulis bahwa CLOB memiliki data JSON ke dalam FILE menggunakan prosedur WRITE_CLOB_TO_FILE . Kami akan meneruskan tiga parameter ke prosedur WRITE_CLOB_TO_FILE, dan mereka adalah sebagai berikut:nama file, nama objek direktori, dan variabel CLOB.

DECLARE
c CLOB;
BEGIN
SELECT json_util_pkg.sql_to_json('select EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO from emp2')
INTO c
FROM DUAL;

WRITE_CLOB_TO_FILE ('emp.json', 'JSON_DIR', c);
END;
/

Sekarang Anda dapat memeriksa lokasi objek direktori JSON_DIR, dan Anda akan menemukan file JSON seperti yang ditunjukkan pada contoh output di bawah ini:

{"ROWSET":[{"EMPNO":7369,"ENAME":"SMITH","JOB":"CLERK","MGR":7902,"HIREDATE":"17-DEC-80","SAL":800,"COMM":null,"DEPTNO":21},{"EMPNO":7499,"ENAME":"ALLEN","JOB":"SALESMAN","MGR":7698,"HIREDATE":"20-FEB-81","SAL":1600,"COMM":300,"DEPTNO":30},{"EMPNO":7521,"ENAME":"WARD","JOB":"SALESMAN","MGR":7698,"HIREDATE":"22-FEB-81","SAL":1250,"COMM":500,"DEPTNO":30},{"EMPNO":7566,"ENAME":"JONES","JOB":"MANAGER","MGR":7839,"HIREDATE":"04-FEB-81","SAL":2975,"COMM":null,"DEPTNO":20},{"EMPNO":7654,"ENAME":"MARTIN","JOB":"SALESMAN","MGR":7698,"HIREDATE":"28-SEP-81","SAL":1250,"COMM":1400,"DEPTNO":30},{"EMPNO":7698,"ENAME":"BLAKE","JOB":"MANAGER","MGR":7839,"HIREDATE":"05-JAN-81","SAL":2850,"COMM":null,"DEPTNO":30},{"EMPNO":7782,"ENAME":"CLARK","JOB":"MANAGER","MGR":7839,"HIREDATE":"06-SEP-81","SAL":2450,"COMM":null,"DEPTNO":10},{"EMPNO":7788,"ENAME":"SCOTT","JOB":"ANALYST","MGR":7566,"HIREDATE":"19-APR-87","SAL":3000,"COMM":null,"DEPTNO":20},{"EMPNO":7839,"ENAME":"KING","JOB":"PRESIDENT","MGR":null,"HIREDATE":"17-NOV-81","SAL":5000,"COMM":null,"DEPTNO":10},{"EMPNO":7844,"ENAME":"TURNER","JOB":"SALESMAN","MGR":7698,"HIREDATE":"09-AUG-81","SAL":1500,"COMM":0,"DEPTNO":30},{"EMPNO":7876,"ENAME":"ADAMS","JOB":"CLERK","MGR":7788,"HIREDATE":"23-MAY-87","SAL":1100,"COMM":null,"DEPTNO":20},{"EMPNO":7900,"ENAME":"JAMES","JOB":"CLERK","MGR":7698,"HIREDATE":"12-MAR-81","SAL":950,"COMM":null,"DEPTNO":30},{"EMPNO":7902,"ENAME":"FORD","JOB":"ANALYST","MGR":7566,"HIREDATE":"12-MAR-81","SAL":3000,"COMM":null,"DEPTNO":20},{"EMPNO":7934,"ENAME":"MILLER","JOB":"CLERK","MGR":7782,"HIREDATE":"23-JAN-82","SAL":1300,"COMM":null,"DEPTNO":10}]}

Lihat juga:

  • Ekspor Data ke Excel Menggunakan PLSQL
  • Ekspor Data ke CSV Menggunakan PL/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. Cari Tahu Simbol Mata Uang Yang Digunakan Sesi Anda di Oracle

  2. Membuat Layar Login Kustom Di Oracle Forms 10g

  3. Oracle PL/SQL:Periksa Apakah BLOB atau CLOB Kosong

  4. SEC_CASE_SENSITIVE_LOGON Tidak digunakan lagi dalam 12c

  5. Bagaimana cara memeriksa apakah file ada di PL/SQL?