lightdb oracle模式支持sys_refcursor类型

背景

在业务产品中,存在Oracle移植过来的函数以及存储过程。它们把sys_refcursor作为参数的类型。

LightDB 23.4版本对此进行了支持。

示例

准备环境

复制代码
create database test_oracle with lightdb_syntax_compatible_type  oracle;
\c test_oracle

准备数据

复制代码
create table customer_address
(
    ca_address_sk             integer               not null,
    ca_address_id             char(16)              not null,
    ca_street_number          char(10)                      ,
    ca_street_name            varchar(60)                   ,
    ca_street_type            char(15)                      ,
    ca_suite_number           char(10)                      ,
    ca_city                   varchar(60)                   ,
    ca_county                 varchar(30)                   ,
    ca_state                  char(2)                       ,
    ca_zip                    char(10)                      ,
    ca_country                varchar(20)                   ,
    ca_gmt_offset             decimal(5,2)                  ,
    ca_location_type          char(20)                      ,
    primary key (ca_address_sk)
);

declare
    i_id                   integer := 1;
    address_id             char(16);
    street_number          char(10);
    street_name            varchar(60) ;
    street_type            char(15);
    suite_number           char(10);
    city                   varchar(60);
    county                 varchar(30);
    state                  char(2);
    zip                    char(10);
    country                varchar(20);
    gmt_offset             decimal(5,2);
    location_type          char(20);
begin
    -- insert
    address_id     := 'address_id';
    street_number  := '3588' ;
    street_name    := 'street_name';
    street_type    := 'street_type';
    suite_number   := '1';
    city           := 'Hang Zhou';
    county         := 'Bin Jiang';
    state          := 'CN';
    zip            := '000000';
    country        := 'China';
    gmt_offset     := 1.02;
    location_type  := 'location_type';

    INSERT INTO customer_address(ca_address_sk, ca_address_id, ca_street_number, ca_street_name, ca_street_type, ca_suite_number, ca_city, ca_county, ca_state, ca_zip, ca_country, ca_gmt_offset, ca_location_type)
    VALUES (i_id, address_id, street_number, street_name, street_type, suite_number, city, county, state, zip, country, gmt_offset, location_type);
END;
/

定义使用sys_refcursor的函数

复制代码
CREATE OR REPLACE PROCEDURE getCustomerAddress(cur OUT sys_refcursor) IS
begin
    open cur for select * from customer_address;
end;
/

调用

复制代码
declare
	ad   sys_refcursor;
	res  customer_address%rowtype;
begin
	getCustomerAddress(ad);
	loop 
    FETCH ad INTO res;
    EXIT WHEN ad%NOTFOUND;
    dbms_output.put_line('ca_address_sk:' || res.ca_address_sk);
	dbms_output.put_line('ca_address_id:' || res.ca_address_id);
	dbms_output.put_line('ca_street_number:' || res.ca_street_number);
	dbms_output.put_line('ca_street_name:' || res.ca_street_name);
	dbms_output.put_line('ca_street_type:' || res.ca_street_type);
	dbms_output.put_line('ca_suite_number:' || res.ca_suite_number);
	dbms_output.put_line('ca_city:' || res.ca_city);
	dbms_output.put_line('ca_county:' || res.ca_county);         
	dbms_output.put_line('ca_state:' || res.ca_state);    
	dbms_output.put_line('ca_zip:' || res.ca_zip);    
	dbms_output.put_line('ca_country:' || res.ca_country);     
	dbms_output.put_line('ca_gmt_offset:' || res.ca_gmt_offset);   
	dbms_output.put_line('ca_location_type:' || res.ca_location_type);
	end loop;
end;
/
相关推荐
SelectDB1 小时前
SelectDB x 同辕开发:在 ARM 架构下实现 25% 分析性能提升
大数据·数据库·华为
华科云商xiao徐1 小时前
Rust+Python双核爬虫:高并发采集与智能解析实战
数据库·python·rust
Techie峰1 小时前
Redis Key过期事件监听Java实现
java·数据库·redis
lwb_01182 小时前
【数据库】使用Sql Server创建索引优化查询速度,一般2万多数据后,通过非索引时间字段排序查询出现超时情况
java·服务器·数据库
吴声子夜歌4 小时前
PostgreSQL——索引
数据库·postgresql·oracle
hj10439 小时前
redis开启局域网访问
数据库·redis·缓存
源代码•宸11 小时前
MySQL 索引:索引为什么使用 B+树?(详解B树、B+树)
数据结构·数据库·经验分享·b树·mysql·b+树·b-树
睡觉的时候不会困11 小时前
MySQL 数据库表操作与查询实战案例
数据库·mysql
秋已杰爱12 小时前
Redis常见命令
数据库·redis·缓存
一个有梦有戏的人12 小时前
软考架构师:数据库的范式
数据库·oracle