Oracle
 sql >> Database >  >> RDS >> Oracle

Converti i dati Oracle CLOB in stringa in c#

Puoi utilizzare la funzione (il contrario di questa risposta ):

CREATE FUNCTION blob_to_clob(
  value            IN BLOB,
  charset_id       IN INTEGER DEFAULT DBMS_LOB.DEFAULT_CSID,
  error_on_warning IN NUMBER  DEFAULT 0
) RETURN CLOB
IS
  result       CLOB;
  dest_offset  INTEGER := 1;
  src_offset   INTEGER := 1;
  lang_context INTEGER := DBMS_LOB.DEFAULT_LANG_CTX;
  warning      INTEGER;
  warning_msg  VARCHAR2(50);
BEGIN
  DBMS_LOB.CreateTemporary(
    lob_loc => result,
    cache   => TRUE
  );

  DBMS_LOB.CONVERTTOCLOB(
    dest_lob     => result,
    src_blob     => value,
    amount       => LENGTH( value ),
    dest_offset  => dest_offset,
    src_offset   => src_offset,
    blob_csid    => charset_id,
    lang_context => lang_context,
    warning      => warning
  );
  
  IF warning != DBMS_LOB.NO_WARNING THEN
    IF warning = DBMS_LOB.WARN_INCONVERTIBLE_CHAR THEN
      warning_msg := 'Warning: Inconvertible character.';
    ELSE
      warning_msg := 'Warning: (' || warning || ') during BLOB conversion.';
    END IF;
    
    IF error_on_warning = 0 THEN
      DBMS_OUTPUT.PUT_LINE( warning_msg );
    ELSE
      RAISE_APPLICATION_ERROR(
        -20567, -- random value between -20000 and -20999
        warning_msg
      );
    END IF;
  END IF;

  RETURN result;
END blob_to_clob;
/

Quindi, se hai il CLOB_TO_BLOB funzione da questa risposta e i dati:

CREATE TABLE table_name ( value BLOB );

INSERT INTO table_name (value ) VALUES ( CLOB_TO_BLOB( 'abcdefg' ) );

Quindi:

SELECT BLOB_TO_CLOB( value ) FROM table_name;

Uscite:

db<>violino qui