麻烦问一下 我写了一个查询select *  from cc  where hm='123456'
我查出来里面有几个结果
hm          mc         jine
123456      白菜       12.00但是我2个表连个查询的时候  
select hm,mc,jine from (
select hm,mc,jine from cc  where hm='123456'
union
select hm,mc,jine from bb  where hm='123456'
)
bb表里面是没有的
这个这个查询结果查出来的时候
hm          mc         jine
123456      白菜       12金额变成12了 不是12.00了 这个是怎么回事啊?
怎么保持12.00???
谢谢

解决方案 »

  1.   

    --这样试试
    select hm,mc,to_char(jine,99999.99) from (
    select hm,mc,jine from cc where hm='123456'
    union
    select hm,mc,jine from bb where hm='123456'
    )
      

  2.   

    我写的是存储过程 
    select hm,mc,to_char(jine,99999.99) from (
    select hm,mc,jine from cc where hm='123456'
    union
    select hm,mc,jine from bb where hm='123456'
    )
       这样写的时候 一直不能在执行  很久都没结束
      

  3.   

    麻烦问一下 我写了一个查询select * from cc where hm='123456'
    我查出来里面有几个结果
    hm mc jine
    123456 白菜 12.00但是我2个表连个查询的时候   
    select hm,mc,jine from (
    select hm,mc,jine from cc where hm='123456'
    union
    select hm,mc,jine from bb where hm='123456'
    union
    select hm,mc,jine from aa where hm='123456'
    )
    比如bb,cc表里面是没有的
    这个这个查询结果查出来的时候
    hm mc jine
    123456 白菜 12金额变成12了 不是12.00了 这个是怎么回事啊?
    怎么保持12.00???后来我发aa,bb,cc三张表 的jine这个字段 有些是num 有些是varchar不一样
    联合查询后 jine这个字段都统一成varchar类型了这种的话 我不是让他保留小数点后面2位
    而是要他联合查询的时候 jine查询出来是什么类型就是什么类型因为要是我用用to_char(jine,‘999999.99’)
    这种的话 查出来始终要保留小数点后面2位
    我不是要让他保留 而是想查出来是什么类型就是什么类型
      

  4.   

    try this:select hm,mc,jine from (
    select hm,mc,to_number(jine) jine from cc where hm='123456'
    union
    select hm,mc,to_number(jine) jine from bb where hm='123456'
    union
    select hm,mc,to_number(jine) jine from aa where hm='123456'
    )
      

  5.   

    楼主用的是oracle哪个版本,如果是11G的话,union两边的SQL查出的字段类型必须要一样,否则必须通过类型转换才可以,其它版本的我不太清楚。但如果楼主这些代码能执行的话,因为在自动类型转换过程中,number比char的优先级别高,对于楼主下面的代码
    select hm,mc,jine from (
    select hm,mc,jine from cc where hm='123456'
    union
    select hm,mc,jine from bb where hm='123456'
    union
    select hm,mc,jine from aa where hm='123456'
    )括号里的子查询因为jine在aa,bb表里的字段是number型,但cc是char型,所以cc里的字段jine会自动转换成number型,如果你想要保持查询结果一至的话,最好把aa,bb里的jine字段转成varchar类型。