ps1 = conn.prepareStatement("select firstprice,averagePrice from (select rownum as rn,t.* from stockquotation t where code=? and thedate>? and rownum <60 ) where rn=1");
ps1.setString(1, code);
ps1.setString(2, “2008-01-01”);
rs1 = ps1.executeQuery();
我用的是oracle 10g,里面的code和thedate字段一开始都是char类型,我这样查询的话,结果集查不到任何东西,后来我查了下资料,网上也有人遇到过这样的问题,他说只要把char类型改成
varchar2()就行了,然后我也把类型改了下,继续运行程序,还是查询不到任何结果,请知道的朋友告诉我下..
另外,这条sql语句我放到plsql里面查的话有用,没用报错,我是这样查的select firstprice,averagePrice from (select rownum as rn,t.* from stockquotation t where code=000002 and thedate>‘2008-01-01’ and rownum <60 ) where rn=1");实在不知道什么原因,那段代码如果我用mysql的话就有用,换了oracle以后就没用了

解决方案 »

  1.   

     (select rownum as rn,t.* from stockquotation t where code=000002 and thedate>‘2008-01-01’ and rownum <60 ) where rn=1");
    后面这句应该只能做为查询条件吧,能从结果里再查结果吗? select firstprice,averagePrice from 这句FROM后面应该加表名
      

  2.   

    char 型如果有指定位数的话,在填入数据后会在不足位后自动添加空格,vvarchar2则不会,所以你在char型时,"a"和"a  "是不能匹配的
      

  3.   

    那可能是因为你之前用char的时候code字段已经被空字符占了,你再改回varchar2的时候那些空字符还在那里,你把code字段改成varvhar2,code字段的数据全部删了,改成新的数据看看