[英]Oracle sql adding custom column name as 1st row of the resultSet
How do I get the column name as the 1st row of the result set.I tried below but getting the error as shown below如何将列名作为结果集的第一行。我在下面尝试但得到如下所示的错误
select 'First Name', 'Last Name', 'Middle Name', 'Term Number', 'BID', 'BTitle', 'SubB Name', 'LNum' from dual
UNION
select
pa.first_name as first_name,
pa.last_name as last_name,
pa.MIDDLE_INITIAL as middle_name,
bi.bi_num as num,
bi.b_id as bId,
b.name as b_title,
bi.sub_board_name as sub_b_name,
pa.L_NUMBER as lNum
from
M_INFO pa,
B_INV bi,
Blot b,
users u,
roles r
where
bi.assigned_to = u.bi_num(+)
and bi.bi_num = pa.bi_num(+)
and u.role_id = r.id(+)
and bi.b_id = b.id
and bi.delete_dt is null
and bi.delete_by is null
and bi.ARCHIVED_DT is null
and bi.b_id = '40' and bi.sub_b_name = 'TEST';
ORA-01790: expression must have same datatype as corresponding expression
01790. 00000 - "expression must have same datatype as corresponding expression"
*Cause:
*Action:
Error at Line: 1 Column: 50
I would recommend two changes to your query.我建议对您的查询进行两项更改。
UNION
to UNION ALL
.UNION
到UNION ALL
。 This way your union will not look for duplicates between the two parts of the union.bi.bi_num
to TO_CHAR(bi.bi_num)
bi.bi_num
更改为TO_CHAR(bi.bi_num)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.