华为云云数据库GaussDBTYPE_云淘科技
功能描述
定义一个新的数据类型。当运行带有-c选项的ecpg的时候,仅仅标识该命令。
语法格式
TYPE type_name IS ctype
参数说明
type_name
数据类型名称。
ctype
C语言数据类型说明。
示例
EXEC SQL TYPE customer IS struct { varchar name[50]; int phone; }; EXEC SQL TYPE cust_ind IS struct ind { short name_ind; short phone_ind; }; EXEC SQL TYPE c IS char reference; EXEC SQL TYPE ind IS union { int integer; short smallint; }; EXEC SQL TYPE intarray IS int[AMOUNT]; EXEC SQL TYPE str IS varchar[BUFFERSIZ]; EXEC SQL TYPE string IS char[11];
使用EXEC SQL TYPE的示例(注意以下示例使用时在ecpg预处理阶段需要添加-c参数):
#include #include #include EXEC SQL WHENEVER SQLERROR SQLPRINT; EXEC SQL TYPE tt IS struct { varchar v[256]; int i; }; EXEC SQL TYPE tt_ind IS struct ind { short v_ind; short i_ind; }; int main(void) { EXEC SQL BEGIN DECLARE SECTION; tt t; tt_ind t_ind; EXEC SQL END DECLARE SECTION; EXEC SQL CONNECT TO testdb AS con1; EXEC SQL SELECT pg_catalog.set_config('search_path', '', false); EXEC SQL COMMIT; EXEC SQL SELECT current_database(), 256 INTO :t:t_ind LIMIT 1; printf("t.v = %s ", t.v.arr); printf("t.i = %d ", t.i); printf("t_ind.v_ind = %d ", t_ind.v_ind); printf("t_ind.i_ind = %d ", t_ind.i_ind); EXEC SQL DISCONNECT con1; return 0; }
该示例输出为:
t.v = testdb t.i = 256 t_ind.v_ind = 0 t_ind.i_ind = 0
父主题: 嵌入式SQL命令
同意关联代理商云淘科技,购买华为云产品更优惠(QQ 78315851)
内容没看懂? 不太想学习?想快速解决? 有偿解决: 联系专家