我有两个表:
create table test2 (
id integer not null primary key, first_name varchar(100), last_name varchar(100)
)
create table test3 (
id integer not null primary key, home_address varchar(100), work_address varchar(100)
)
我创建了一个存储过程,该存储过程从每个表中选择一些列:
CREATE PROCEDURE "BLUADMIN"."REST_PROCTEST1_1_0"()
LANGUAGE SQL
DYNAMIC RESULT SETS 1
BEGIN
DECLARE C1 CURSOR WITH RETURN FOR
SELECT T2.FIRST_NAME, T2.LAST_NAME, T3.HOME_ADDRESS, T3.WORK_ADDRESS
FROM TEST2 T2 INNER JOIN TEST3 T3 ON T2.ID=T3.ID;
OPEN C1;
END
我想获得结果集的描述。我可以像这样使用Db2命令行处理器描述SQL查询的结果:
db2 => describe SELECT T2.FIRST_NAME, T2.LAST_NAME, T3.HOME_ADDRESS, T3.WORK_ADDRESS FROM BLUADMIN.TEST2 T2 INNER JOIN BLUADMIN.TEST3 T3 ON T2.ID=T3.ID
Column Information
Number of columns: 4
SQL type | Type length | Column name | Name length
449 VARCHAR | 100 | FIRST_NAME | 10
449 VARCHAR | 100 | LAST_NAME | 9
449 VARCHAR | 100 | HOME_ADDRESS | 12
449 VARCHAR | 100 | WORK_ADDRESS | 12
我正在使用Golang driver for Db2,并且正在寻找一种在程序中获取类似信息的方法。
答案 0 :(得分:0)
可能不是您想要的答案,但是您可以将SQL创建为临时视图,然后查询目录
例如
CREATE VIEW TEMP AS SELECT T2.FIRST_NAME, T2.LAST_NAME, T3.HOME_ADDRESS, T3.WORK_ADDRESS FROM BLUADMIN.TEST2 T2 INNER JOIN BLUADMIN.TEST3 T3 ON T2.ID=T3.ID;
SELECT COLNO, COLNAME, TYPENAME, LENGTH, SCALE, NULLS --etc
FROM SYSCAT.COLUMNS WHERE TABSCHEMA = CURRENT SCHEMA AND TABNAME = 'TEMP';
DROP VIEW TEMP;