2023-01-11

[Oracle]CLOB_TO_BLOB

  
  FUNCTION CLOB_TO_BLOB(P_DATA IN CLOB) RETURN BLOB AS
    L_BLOB         BLOB;
    L_DEST_OFFSET  PLS_INTEGER := 1;
    L_SRC_OFFSET   PLS_INTEGER := 1;
    L_LANG_CONTEXT PLS_INTEGER := DBMS_LOB.DEFAULT_LANG_CTX;
    L_WARNING      PLS_INTEGER := DBMS_LOB.WARN_INCONVERTIBLE_CHAR;
    B              BLOB;
    C              BLOB;
  BEGIN
  
    DBMS_LOB.CREATETEMPORARY(LOB_LOC => L_BLOB, CACHE => TRUE);
  
    DBMS_LOB.CONVERTTOBLOB(DEST_LOB     => L_BLOB,
                           SRC_CLOB     => P_DATA,
                           AMOUNT       => DBMS_LOB.LOBMAXSIZE,
                           DEST_OFFSET  => L_DEST_OFFSET,
                           SRC_OFFSET   => L_SRC_OFFSET,
                           BLOB_CSID    => DBMS_LOB.DEFAULT_CSID,
                           LANG_CONTEXT => L_LANG_CONTEXT,
                           WARNING      => L_WARNING);
  
    --RETURN L_BLOB;
    BEGIN
      SELECT 'EFBBBF' INTO B FROM DUAL;
      DBMS_LOB.CREATETEMPORARY(C, TRUE);
      DBMS_LOB.APPEND(C, B);
      DBMS_LOB.APPEND(C, L_BLOB);
    END;
    RETURN C;
  END;

沒有留言:

張貼留言