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

tipe data tidak konsisten:saat mengembalikan tabel dari kursor dalam fungsi paket - ORACLE

Coba ini:

        out_rec cst_record;

        CURSOR C1 IS
        SELECT ...;

  BEGIN

    open c1;
    LOOP
    FETCH c1 INTO out_rec;

  exit when c1%notfound;

    PIPE ROW(out_rec);

  END LOOP;

  close c1;

  RETURN;

END fnc_get_contractor_id;

KODE DIPERBARUI:

CREATE OR REPLACE PACKAGE pkg_contrator_of_consultant AS

    TYPE cst_record IS RECORD(
       consultant_id NUMBER(10));

    TYPE cst_id_type IS TABLE OF cst_record;

    FUNCTION fnc_get_contractor_id(cst_username IN VARCHAR2)
        RETURN cst_id_type
        PIPELINED;
END;
/

CREATE OR REPLACE PACKAGE BODY pkg_contrator_of_consultant AS 
FUNCTION fnc_get_contractor_id(cst_username IN VARCHAR2 )
    RETURN cst_id_type
    PIPELINED IS    

    CURSOR c1 IS
    SELECT plc.FK2_CONTRACTOR_ID
        FROM lds_consultant cons
        INNER JOIN lds_account acc on cons.consultant_id = acc.fk1_consultant_id 
        INNER JOIN lds_placement plc on acc.account_id = plc.FK1_ACCOUNT_ID
        WHERE UPPER(cons.USERNAME) = UPPER(cst_username)
        AND UPPER(plc.PLT_TO_PERMANENT) = UPPER('Y');

        out_rec cst_record;
    BEGIN

        open c1;
        LOOP
        FETCH c1 INTO out_rec;

      exit when c1%notfound;

        PIPE ROW(out_rec);

      END LOOP;

      close c1;

      RETURN;

    END fnc_get_contractor_id;
END;
/



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Pilih klausul di dalam fungsi pl/sql mengembalikan nilai yang salah

  2. Mengapa penyebaran xcopy ODP.NET 11 tidak berfungsi pada mesin dengan Oracle DB 10 diinstal?

  3. Fungsi NVL2 di Oracle

  4. Oracle Database Enforce CHECK pada beberapa tabel

  5. Menjalankan Prosedur Tersimpan Dari JMeter