begin dbms_output.enable(20000); crs := dbms_sql.open_cursor; dbms_sql.parse(crs ,'select text from dba_views where view_name=''DBA_USERS''' ,dbms_sql.v7); dbms_sql.define_column_long(crs,1); prsd := dbms_sql.execute_and_fetch(crs); dbms_sql.column_value_long(crs ,1 ,str_len ,str_start -1 ,outval ,outval_length); dbms_sql.close_cursor(crs); outval := translate(outval,CHR(10),' '); dbms_output.put_line(outval); end;
方法二 declare /* Modify the SQL in cursor v_cur and take out the test ROWNUM code. */ cursor v_cur is select rowidtochar(rowid) c_rowid, DCONTENT l_longraw from tst03 where rownum < 100;
v_max_length number :=0; v_length number :=0; v_rowid varchar(18) := ' ';
begin for v_row in v_cur loop v_length := lengthb(v_row.l_longraw); if v_length > v_max_length then v_max_length := v_length; v_rowid := v_row.c_rowid; end if; end loop; dbms_output.put('RowID: '||v_rowid||' Max Length: '||v_max_length); dbms_output.new_line; end;
方法三,用copy命令 set long 30000 copy to /@ - insert - (columns in destination table),- from ;
例子: SET LONG 30000 SET COPYCOMMIT 1 SET ARRAYSIZE 1000
COPY TO TOlogin/TOpassword@TOconnectname - APPEND TOowner.tablename - USING - SELECT * FROM FROMowner.FROMtablename;
CREATE OR REPLACE PROCEDURE cesp_get_long ( i_table IN VARCHAR2, -- table name i_row_id_fld IN VARCHAR2, -- name of column to id row i_row_id IN VARCHAR2, -- data in row id oolumn i_col_pos IN NUMBER, -- long column position within row io_nextseg IN INTEGER, -- start of long chuck (start with byte zero) o_data OUT VARCHAR2,-- 2000 byte long chunk to send back to calling program io_seglengh OUT INTEGER -- actual length of chunk returned
) IS
/* In order to get any long field out of any table you must send this proc the following information in this order from either another calling PL/SQL proc or from something like VB;
- Table name of the table that has the long data type in it. - Column name of the column by which you want to access the row with the long data. NOTE; this is not the LONG column - What in the column name you are looking for (used in a where clause - Position in the table of the LONG column - The starting segment byte with which to start getting chunks of the long column. 0 starts at the beginning - The (up too) 2000 byte chunk is put sent back in this parameter - The actual lengh of the column chunk being sent back. If less than 2000 than no more data exists in the long column. This should be used to determine if the calling program needs to come back if more data exists.
- SAMPLE calling program to access this program..
DECLARE h_data VARCHAR2(2000) := NULL; seg_length INTEGER := 0; seg_out INTEGER := 0; next_byte INTEGER := 0; begin LOOP cesp_get_long('sw_basic_script', 'swname', 'CE Site Ratings I', 6, next_byte, h_data, seg_length); insert into md_dummy values (h_data); DBMS_OUTPUT.PUT_LINE(seg_length); IF seg_length = 0 OR seg_length < 2000 THEN EXIT; END IF; next_byte := next_byte + seg_length; END LOOP; commit; end;