(原创)oracle目录及Long类型操作
2007-11-16 00:13
316 查看
--创建一个表
create table ascii_docs
(
id number,
document long
);
--创建一个目录
create or replace directory OUT_PATH as 'c:\temp';
--给目录授予权限
grant read, write on directory OUT_PATH to test;
create or replace function dump_doc(docid in number,filename in varchar2) return varchar2 is
data_chunk varchar2(254);
chunk_size number :=254;
chunk_size_returned number;
--set location to be the directory in which the file should go.
location varchar2(20) := 'OUT_PATH';
mycursor number;
stmt varchar2(1024);
cur_pos number :=0;
rows number;
dummy number;
file_handle utl_file.file_type;
status varchar2(50);
begin
--open the file for writing.
file_handle := utl_file.fopen(location,filename,'w');
--bind the doctoget host variable with the plsql parameter docid
--whitch is passed into the function
stmt := 'select document from ascii_docs where id = :doctoget';
mycursor := dbms_sql.open_cursor;
dbms_sql.parse(mycursor,stmt,dbms_sql.v7);
dbms_sql.bind_variable(mycursor,':doctoget',docid);
--only doing one fetch for the primary key as assuming the whole
--document is stored in one row
dbms_sql.define_column_long(mycursor,1);
dummy := dbms_sql.execute(mycursor);
rows := dbms_sql.fetch_rows(mycursor);
loop
--fetch 'chunks of the long until we have got the lot
dbms_sql.column_value_long(mycursor,1,chunk_size,cur_pos,data_chunk,chunk_size_returned);
utl_file.put(file_handle,data_chunk);
cur_pos := cur_pos + chunk_size;
exit when chunk_size_returned =0;
end loop;
dbms_sql.close_cursor(mycursor);
utl_file.fclose(file_handle);
return('success');
exception
when others then
utl_file.fclose(file_handle);
raise;
return('Fallre');
end dump_doc;
create table ascii_docs
(
id number,
document long
);
--创建一个目录
create or replace directory OUT_PATH as 'c:\temp';
--给目录授予权限
grant read, write on directory OUT_PATH to test;
create or replace function dump_doc(docid in number,filename in varchar2) return varchar2 is
data_chunk varchar2(254);
chunk_size number :=254;
chunk_size_returned number;
--set location to be the directory in which the file should go.
location varchar2(20) := 'OUT_PATH';
mycursor number;
stmt varchar2(1024);
cur_pos number :=0;
rows number;
dummy number;
file_handle utl_file.file_type;
status varchar2(50);
begin
--open the file for writing.
file_handle := utl_file.fopen(location,filename,'w');
--bind the doctoget host variable with the plsql parameter docid
--whitch is passed into the function
stmt := 'select document from ascii_docs where id = :doctoget';
mycursor := dbms_sql.open_cursor;
dbms_sql.parse(mycursor,stmt,dbms_sql.v7);
dbms_sql.bind_variable(mycursor,':doctoget',docid);
--only doing one fetch for the primary key as assuming the whole
--document is stored in one row
dbms_sql.define_column_long(mycursor,1);
dummy := dbms_sql.execute(mycursor);
rows := dbms_sql.fetch_rows(mycursor);
loop
--fetch 'chunks of the long until we have got the lot
dbms_sql.column_value_long(mycursor,1,chunk_size,cur_pos,data_chunk,chunk_size_returned);
utl_file.put(file_handle,data_chunk);
cur_pos := cur_pos + chunk_size;
exit when chunk_size_returned =0;
end loop;
dbms_sql.close_cursor(mycursor);
utl_file.fclose(file_handle);
return('success');
exception
when others then
utl_file.fclose(file_handle);
raise;
return('Fallre');
end dump_doc;
相关文章推荐
- oracle xml数据类型常见操作
- JDBC 对oracle 的clob ,blob类型的操作方式
- 用Java操作Oracle日期类型字段
- C#中通过OleDb操作Oracle Blob数据类型
- jdbctemplate oracle date类型操作
- oracle对BLOB类型数据的操作与性能问题
- 用java 操作 oracle 日期类型字段
- oracle 性能优化操作二:避免不必要的类型转换
- Hibernate框架映射Oracle中long类型字段
- 关于oracle中LONG数据类型使用上的一些总结
- [导入](C#)如何实现磁盘文件以及目录树型结构显示(Longever原创)
- oracle 每日一题-LONG数据类型
- C# 操作 XML 数据库类型、Oracle XMLType
- PHP文件目录操作问题 列出目录下的东西时 如何先列目录,再列文件 文件也按照名称或时间排序或者类型
- Oracle数据类型Long需要注意的问题
- Oracle基本操作,Oracle修改列名,Oracle修改字段类型
- java操作Oracle大数据类型BLOB的存取
- J2EE操作Oracle的clob类型字段
- oracle表的管理(数据类型,表创建删除,数据CRUD 操作)
- ORACLE LONG类型转化成VARCHAR2