expression must have same datatype as corresponding expression
来源:互联网 发布:教师网络研修日志 编辑:程序博客网 时间:2024/06/12 17:28
ORA-01790错误提示信息是“expression must have same datatype as corresponding expression”,如果使用oerr命令查看,没有过多的描述信息。
单纯从错误信息的内容其实就可以大概看出问题出处,是由于数据类型不一致引起的报错。
这里我通过一个实验模拟一下这个错误,然后给出一个解决方法。
实验中我们将使用UNION ALL操作来模拟这个错误,因为UNION ALL要求多个UNION内容对应字段的数据类型要严格一致。
1.创建三个实验用表T1、T2和T3
sec@ora10g> create table t1 (x varchar2(10), y varchar2(10));
Table created.
sec@ora10g> create table t2 (x varchar2(10), y varchar2(10));
Table created.
sec@ora10g> create table t3 (x int, y varchar2(10));
Table created.
注意T1和T2表的所有字段类型均为“VARCHAR2”,T3表的X字段类型是“INT”。
2.每张表初始化一条记录
sec@ora10g> insert into t1 values ('1', 'secooler');
1 row created.
sec@ora10g> insert into t2 values ('2','HOU');
1 row created.
sec@ora10g> insert into t3 values (3,'Andy');
1 row created.
sec@ora10g> commit;
Commit complete.
3.先看正确的使用方法
sec@ora10g> select * from t1
2 union all
3 select * from t2;
X Y
---------- ----------
1 secooler
2 HOU
由于T1表和T2表的字段类型相同,故此处可以得到正确的结果。
4.使用T2和T3表来模拟ORA-01790错误
sec@ora10g> select * from t1
2 union all
3 select * from t3;
select * from t1
*
ERROR at line 1:
ORA-01790: expression must have same datatype as corresponding expression
由于是我们设计的场景,此时我们真切的经历了ORA-01790错误发上过程。
原因是显然的,T1表的X列类型是VARCHAR2,这与T3表X列INT类型不符。
5.规避ORA-01790错误的一种方法
针对这个案例,这里我们采用TO_CHAR函数强制将T3表的X列转换为字符串类型的方法来处理。
sec@ora10g> select * from t1
2 union all
3 select to_char(x),y from t3;
X Y
---------------------------------------- ----------
1 secooler
3 Andy
6.MOS中的参考信息[ID 19128.1]
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.
7.小结
在使用UNION时,需要注意用到的字段类型要保证一致;
不要放过任何报错信息后面隐含的真实原因,处理问题的过程就是自身提高的过程。
Good luck.
secooler
10.02.20
-- The End --
单纯从错误信息的内容其实就可以大概看出问题出处,是由于数据类型不一致引起的报错。
这里我通过一个实验模拟一下这个错误,然后给出一个解决方法。
实验中我们将使用UNION ALL操作来模拟这个错误,因为UNION ALL要求多个UNION内容对应字段的数据类型要严格一致。
1.创建三个实验用表T1、T2和T3
sec@ora10g> create table t1 (x varchar2(10), y varchar2(10));
Table created.
sec@ora10g> create table t2 (x varchar2(10), y varchar2(10));
Table created.
sec@ora10g> create table t3 (x int, y varchar2(10));
Table created.
注意T1和T2表的所有字段类型均为“VARCHAR2”,T3表的X字段类型是“INT”。
2.每张表初始化一条记录
sec@ora10g> insert into t1 values ('1', 'secooler');
1 row created.
sec@ora10g> insert into t2 values ('2','HOU');
1 row created.
sec@ora10g> insert into t3 values (3,'Andy');
1 row created.
sec@ora10g> commit;
Commit complete.
3.先看正确的使用方法
sec@ora10g> select * from t1
2 union all
3 select * from t2;
X Y
---------- ----------
1 secooler
2 HOU
由于T1表和T2表的字段类型相同,故此处可以得到正确的结果。
4.使用T2和T3表来模拟ORA-01790错误
sec@ora10g> select * from t1
2 union all
3 select * from t3;
select * from t1
*
ERROR at line 1:
ORA-01790: expression must have same datatype as corresponding expression
由于是我们设计的场景,此时我们真切的经历了ORA-01790错误发上过程。
原因是显然的,T1表的X列类型是VARCHAR2,这与T3表X列INT类型不符。
5.规避ORA-01790错误的一种方法
针对这个案例,这里我们采用TO_CHAR函数强制将T3表的X列转换为字符串类型的方法来处理。
sec@ora10g> select * from t1
2 union all
3 select to_char(x),y from t3;
X Y
---------------------------------------- ----------
1 secooler
3 Andy
6.MOS中的参考信息[ID 19128.1]
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.
7.小结
在使用UNION时,需要注意用到的字段类型要保证一致;
不要放过任何报错信息后面隐含的真实原因,处理问题的过程就是自身提高的过程。
Good luck.
secooler
10.02.20
-- The End --
阅读全文
0 0
- expression must have same datatype as corresponding expression
- java.sql.SQLException: ORA-01790: expression must have same datatype as corresponding expression
- The expression after ELSE should have the same type as those after THEN: "bigint" is expected but "i
- [SQL ERROR 800]Corresponding types must be compatible in CASE expression.
- [[ expression ]]
- expression
- Expression
- Expression
- Expression
- 在keil mdk中的error: #28: expression must have a constant value
- path must precede expression错误
- find: paths must precede expression
- Nhibernate: Foreign key must have same number of columns as the referenced primary key
- error #2153: expression must have class type(低级错误:看是指针还是对象->和.的使用要正确)
- E0137 expression must be a modifiable lvalue
- Expression Expression tree Expression evaluation
- Same org.omg.CORBA.Object with different IOR string expression
- find: paths must precede expression Usage: find [-H] [-L] [-P] [path...] [expression]
- iOS 【自适应长度标题栏-类似于滴滴打车】
- Spring事务管理
- mac安装go环境
- 中断线程化的意义和如何注册一个有中断线程化的irq
- C++ / Opencv 学习笔记 (Vector用法 )
- expression must have same datatype as corresponding expression
- 修改textFieldplaceholder字体颜色和大小
- Swift 协议
- 从Eclipse转 Intellij Idea 需要做的设置 快捷键设置
- 一套完整的设计分析思路
- HTTP与HTTPS的区别
- NodeMcu关于ADS1115的理解
- 资料视频收集
- Android实现简单的闹钟