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;
/
相关推荐
A.说学逗唱的Coke21 小时前
【大模型专题】向量数据库深度解析:从原理到实战,构建企业级 AI 知识检索底座
数据库·人工智能
果丁智能1 天前
智能锁赋能网约房民宿数字化管控:身份核验+远程授权,筑牢安全防线、降本增效
网络·数据库·人工智能·安全·智能家居
无敌的牛1 天前
redis学习过程
数据库·redis·学习
IT北辰1 天前
神通数据库管理系统V7.0.251210 for Windows(x86 64bit)安装部署
数据库·神通
北顾笙9801 天前
MySQL-day2
数据库·mysql
Demons_kirit1 天前
新项目如何连接上自己本地的数据库
数据库
洪晓露1 天前
将 rke2 集群证书延长至 10 年
运维·服务器·数据库
程序猿乐锅1 天前
【MySQL | 第八篇】MySQL 视图
数据库·mysql
jieyucx1 天前
SQL 查询终极高阶通鉴:从零基础拆解到工业级多表联查、窗口函数与索引优化
数据库·sql
ai_coder_ai1 天前
论 NoSQL 数据库技术及其应用
数据库·nosql