Oracle存储过程返回游标有两种实现方法一种是声明系统游标,一种是声明自定义游标,本文将详细介绍,需要了解的朋友可以参考下
有俩种方法:一种是声明系统游标,一种是声明自定义游标,然后后面操作一样,参数类型为
in out 或out
(1)声明个人系统游标.(推荐)
代码如下:
create or replace p_temp_procedure
(
cur_arg out sys_refcursor; --方法1
)
begin
open cur_arg for select * from tablename;
end
调用
代码如下:
declare
cur_calling sys_refcursor;
begin
p_temp_procedure(cur_calling); --这样这个游标就有值了
for rec_next in cur_calling loop
....
end loop;
end;
(2)在包头中申明一个游表类型,然后调用者申明一个这个类型的游标变量,传给返回游标的存储过程 ,存储过程out这个结果集,这种方法很麻烦.游标类型不能像索引表一样使用create or replace type方法来创建,所以只能在包中申明,并且需要使用/来执行,后面的存储过程才认这个游标类型.(不推荐,但是建议要知道并且要会这种方式,毕竟它有它存在的道理)
代码如下:
--定义全局变量
create or replace package pkg_package
as
type type_cursor is ref cursor;
type type_record is record
(
test01 varchar2(32),
test02 varchar2(32),
test03 varchar2(32)
);
end;
--创建返回游标的存储过程
代码如下:
create or replace procedure p_temp_procedure
(
cur_out_arg out pkg_package.type_cursor
)
is
begin
open cur_out_arg for select * from test;
end;
--调用
代码如下:
declare
cur_out_arg pkg_package.type_cursor;
rec_arg pkg_package.type_record;
begin
p_temp_procedure(cur_out_arg);
fetch cur_out_arg into rec_arg;
dbms_output.put_line(rec_arg.test01);
dbms_output.put_line(rec_arg.test02);
dbms_output.put_line(rec_arg.test03);
end;

This article explores optimizing MySQL memory usage in Docker. It discusses monitoring techniques (Docker stats, Performance Schema, external tools) and configuration strategies. These include Docker memory limits, swapping, and cgroups, alongside

This article addresses MySQL's "unable to open shared library" error. The issue stems from MySQL's inability to locate necessary shared libraries (.so/.dll files). Solutions involve verifying library installation via the system's package m

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

This article compares installing MySQL on Linux directly versus using Podman containers, with/without phpMyAdmin. It details installation steps for each method, emphasizing Podman's advantages in isolation, portability, and reproducibility, but also

This article provides a comprehensive overview of SQLite, a self-contained, serverless relational database. It details SQLite's advantages (simplicity, portability, ease of use) and disadvantages (concurrency limitations, scalability challenges). C

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

This guide demonstrates installing and managing multiple MySQL versions on macOS using Homebrew. It emphasizes using Homebrew to isolate installations, preventing conflicts. The article details installation, starting/stopping services, and best pra

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
