zoukankan      html  css  js  c++  java
  • ORA-01790 错误处理

    今天在练手的时候出现了一个ORA-01790 的错误,决定把他写下来保留起来。
    先来创建两张测试用的简单的表。
    SQL> create table test01 (id number(3),name varchar2(12));
    Table created.
    SQL> create table test02 (id varchar2(6),name varchar2(12));
    Table created.
    分别插入一条记录用来测试。
    SQL> insert into test01 values (100,'baidu');
    1 row created.
    SQL> insert into test02 values ('101','sina');
    1 row created.
    SQL> commit;
    Commit complete.
    执行带union 或者union all 的语句。
    SQL> select id,name from test01
      2  union 
      3  select id,name from test02;
    select id,name from test01
           *
    ERROR at line 1:
    ORA-01790: expression must have same datatype as corresponding expression
    出现上述错误的原因是因为 test01 中的id 列的定义是number,而test02 中id 列的定义
    是varchar2。所以在union 或者union all 的时候造成了数据类型不一致。出现上述错误应该根据不同的情况使用不同类型转换函数,比如to_char,to_number,to_date
    改写上面的语句:
    SQL> select to_char(id) as id,name from test01
      2  union 
      3  select id,name from test02;
    ID                                       NAME
    ---------------------------------------- ------------
    100                                      baidu
    101                                      sina
    
    ---- 动动手指关注我!或许下次你又能在我这里找到你需要的答案!ZZZZW与你一起学习,一起进步!
  • 相关阅读:
    数组
    做了个进制转换图
    类的练习
    3.10l练习
    c#学习第二课
    c#第四课习题
    c#学习第三课
    学习PHP&MYSQL之——字符编码篇(一)
    中缀表达式转换成后缀表达式
    模板方法模式(Template Pattern)
  • 原文地址:https://www.cnblogs.com/zzzzw/p/5669716.html
Copyright © 2011-2022 走看看