Oracle11g中ORA-01790

     问题源于群里有人问如何让查询的结果值+1,方法其实很简单,直接在SQL语句中+1就可以,如果有空可以用NVL处理。

但是测试的时候我使用了UNION ALL(测试的字段是varchar2类型),结果报错ORA-01790。测试代码如下:

SELECT t.rearrangement13n+1 AS rearrangement13n  FROM t_plan t WHERE t.id = 97

UNION ALL

SELECT t.rearrangement13n FROM t_plan t WHERE t.id=97

  之后感觉应该是进行类型转换,查了下文档。

OERR: ORA 1790 expression must have same datatype as corresponding expression 

Error:  ORA 1790

Text:   expression must have same datatype as corresponding expression

-------------------------------------------------------------------------------

Cause:  A SELECT list item corresponds to a SELECT list item with a different

        datatype in another query of the same set expression.

Action: Check that all corresponding SELECT list items have the same datatypes.

        Use the TO_NUMBER, TO_CHAR, and TO_DATE functions to do explicit data

        conversions.

  更改代码为:

SELECT to_char(t.rearrangement13n+1) FROM t_plan t WHERE t.id = 97

UNION ALL

SELECT t.rearrangement13n FROM t_plan t WHERE t.id=97

    问题解决。但是Oracle是如何进行转换的呢?而且Oracle中如何输出select后的字段类型呢?在文档中没有找到。(待解决)

你可能感兴趣的:(oracle11g)