(原创)oracle目录及Long类型操作

简介: --创建一个表 create table ascii_docs ( id number, document long ); --创建一个目录 create or replace directory OUT_PATH as 'c:\temp'; --给目录授予权限 grant rea...

--创建一个表
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;

目录
相关文章
|
11月前
|
Oracle 关系型数据库 MySQL
【YashanDB知识库】oracle dblink varchar类型查询报错记录
这篇文章主要介绍了 Oracle DBLINK 查询崖山 DB 报错的相关内容,包括 ODBC 安装配置、数据源配置、dblink 环境配置、问题原因分析及规避方法。问题原因是 dblink 连接其他数据库时 varchar 类型转换导致的,还介绍了 long 类型限制、char 等类型区别,规避方法是修改参数 MAX_STRING_SIZE 支持 32K。
|
Oracle 关系型数据库 数据库
【YashanDB知识库】oracle dblink varchar类型查询报错记录
在使用Oracle DBLink查询VARCHAR类型数据时,可能会遇到多种报错。通过了解常见错误原因,采取合适的解决方法,可以有效避免和处理这些错误。希望本文提供的分析和示例能帮助你在实际工作中更好地处理DBLink查询问题。
423 10
|
编译器 C#
c# - 运算符<<不能应用于long和long类型的操作数
在C#中,左移运算符的第二个操作数必须是 `int`类型,因此需要将 `long`类型的位移计数显式转换为 `int`类型。这种转换需要注意数据丢失和负值处理的问题。通过本文的详细说明和示例代码,相信可以帮助你在实际开发中正确使用左移运算符。
210 3
|
编译器 C#
c# - 运算符<<不能应用于long和long类型的操作数
在C#中,左移运算符的第二个操作数必须是 `int`类型,因此需要将 `long`类型的位移计数显式转换为 `int`类型。这种转换需要注意数据丢失和负值处理的问题。通过本文的详细说明和示例代码,相信可以帮助你在实际开发中正确使用左移运算符。
339 2
|
编译器 C#
c# - 运算符<<不能应用于long和long类型的操作数
在C#中,左移运算符的第二个操作数必须是 `int`类型,因此需要将 `long`类型的位移计数显式转换为 `int`类型。这种转换需要注意数据丢失和负值处理的问题。通过本文的详细说明和示例代码,相信可以帮助你在实际开发中正确使用左移运算符。
250 0
|
前端开发 Java 数据库
Java系列之 Long类型返回前端精度丢失
这篇文章讨论了Java后端实体类中Long类型数据在传递给前端时出现的精度丢失问题,并提供了通过在实体类字段上添加`@JsonSerialize(using = ToStringSerializer.class)`注解来确保精度的解决方法。
|
分布式计算 Oracle 大数据
MaxCompute产品使用合集之没有数据源,只是将批量状态和时间写入Oracle表里,该如何操作
MaxCompute作为一款全面的大数据处理平台,广泛应用于各类大数据分析、数据挖掘、BI及机器学习场景。掌握其核心功能、熟练操作流程、遵循最佳实践,可以帮助用户高效、安全地管理和利用海量数据。以下是一个关于MaxCompute产品使用的合集,涵盖了其核心功能、应用场景、操作流程以及最佳实践等内容。
201 8
|
存储 Oracle 关系型数据库
关系型数据库Oracle备份类型与频率
【7月更文挑战第21天】
328 6
|
Oracle 关系型数据库 数据库
|
SQL Oracle 关系型数据库
关系型数据库Oracle备份类型
【7月更文挑战第18天】
310 2

热门文章

最新文章

推荐镜像

更多