小工具知识网

当前位置: 首页 > 行业知识 > LightDB - ecpg 支持dml 中使用 return into 【24.1】

行业知识

LightDB - ecpg 支持dml 中使用 return into 【24.1】

2026-10-20 19:12:52 来源:互联网转载

在之前���版本中ecpg 中只能使用returning into 来给c 变量赋值,如下:

()
exec sql update t1 set c ='aa' where id = 2 returning c into :c_val;

为了兼容oracle pro*c 中return into 的用法,从24.1 开始, LightDB 也支持通过return into 来返回return 的值到c变量中。使用方式如下:

示例

#include #include #include static voidprint_sqlca(){    fprintf(stderr, "==== sqlca ====\n");    fprintf(stderr, "sqlcode: %ld\n", sqlca.sqlcode);    fprintf(stderr, "sqlerrm.sqlerrml: %d\n", sqlca.sqlerrm.sqlerrml);    fprintf(stderr, "sqlerrm.sqlerrmc: %s\n", sqlca.sqlerrm.sqlerrmc);    fprintf(stderr, "sqlstate: %5s\n", sqlca.sqlstate);    fprintf(stderr, "===============\n");}int main() {exec sql begin declare section;char c_val[100] = {0};exec sql end declare section;ECPGdebug(1, stderr);EXEC SQL CONNECT TO tcp:postgresql://127.0.0.1:5432/test_o;EXEC SQL SET AUTOCOMMIT TO ON;EXEC SQL WHENEVER SQLWARNING SQLPRINT;EXEC SQL WHENEVER SQLERROR CALL print_sqlca();exec sql create table t1(id integer,t text,d1 numeric,d2 float8,c char(10));exec sql insert into t1 values(1, 'a', 1.0, 1, 'a'),(2, null, null, null, null),(4, 'd', 4.0, 4, 'd');exec sql update t1 set c ='aa' where id = 2 return c into :c_val;exec sql delete from t1 where id = 2 return c into :c_val;exec sql insert into t1 values(2,null, null,null,  'bb') return c into :c_val;exec sqlDo $$Beginupdate t1 set c ='aa' where id = 2 return c into :c_val;end;$$ Language plorasql;exec sqlDo $$Begindelete from t1 where id = 2 return c into :c_val;end;$$ Language plorasql;exec sqlDo $$Begininsert into t1 values(2,null, null,null,  'bb') return c into :c_val;end;$$ Language plorasql;EXEC SQL DROP table t1;exec sql disconnect;return 0;}
()

上一篇:服务器如何安装linux系统?

下一篇:饥荒开服务器推荐怎么开?