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;
/
相关推荐
qq_192779871 天前
高级爬虫技巧:处理JavaScript渲染(Selenium)
jvm·数据库·python
u0109272711 天前
使用Plotly创建交互式图表
jvm·数据库·python
爱学习的阿磊1 天前
Python GUI开发:Tkinter入门教程
jvm·数据库·python
tudficdew1 天前
实战:用Python分析某电商销售数据
jvm·数据库·python
sjjhd6521 天前
Python日志记录(Logging)最佳实践
jvm·数据库·python
Configure-Handler1 天前
buildroot System configuration
java·服务器·数据库
2301_821369611 天前
用Python生成艺术:分形与算法绘图
jvm·数据库·python
电商API_180079052471 天前
第三方淘宝商品详情 API 全维度调用指南:从技术对接到生产落地
java·大数据·前端·数据库·人工智能·网络爬虫
2401_832131951 天前
Python单元测试(unittest)实战指南
jvm·数据库·python
打工的小王1 天前
redis(四)搭建哨兵模式:一主二从三哨兵
数据库·redis·缓存