on 2018 Feb 16 4:36 AM
Hi all, How can i get a list of alias column names of the result set for a query? begin declare t_msg long varchar; set t_msg = 'begin select 123 as "col name 1",456 as "col name 2" end'; message 'describe list: '+(select list(name) from sa_describe_query(t_msg)); end result -> SqlCode: -894, SqlState: "0AW14", Message: "Plan cannot be generated for this type of statement" begin declare t_msg long varchar; set t_msg = 'begin select 123 as "col name 1",456 as "col name 2" end'; begin declare crsr cursor using t_msg; open crsr; message 'cursor list: '+(select list(name) from sa_describe_cursor('crsr')); close crsr; end end result -> cursor list: expression,expression begin declare t_msg long varchar; set t_msg = 'begin select 123 as "col name 1",456 as "col name 2" end'; drop procedure if EXISTS tt; execute IMMEDIATE 'create procedure tt() begin '+t_msg+' end;'; message 'procedure list: '+(select list(parm_name) from sysprocparm join sysprocedure where parm_type = 1 and proc_name = 'tt') to client; end result -> procedure list: col name 1,col name 2 Is there another way to get alias column names of the result set for a query without creating a procedure? Regards, Veselin Ivanov
It's way easier, you can use the procedure sa_describe_query() in the FROM clause and access its result set that way, such as:
select name from sa_describe_query('select 123 as "col name 1", 456 as "col name 2"') sp order by column_number;
which returns
col name 1
col name 2
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
IMHO, that is a misunderstanding. The procedure is meant to describe a single query but not a code block, so you cannot use it with BEGIN/END statements as you tried.
When using stored procedures, you need to use them as part of the FROM clause, not via a CALL statement. This works fine:
call sa_describe_query('select * from sa_conn_info() s');
User | Count |
---|---|
67 | |
10 | |
10 | |
10 | |
10 | |
8 | |
8 | |
7 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.