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;
/

你可能感兴趣的:(lightdb,数据库,lightdb)