您的位置:程序门 -> oracle -> 开发



下面语句是什么问题,急!


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


下面语句是什么问题,急![已结贴,结贴人:splory]
发表于:2007-04-04 15:29:06 楼主
update   t_search   set   fields=b.fields,selecttype=b.selecttype   from   t_search   a,(select   distinct   fields,fieldsnames,selecttype   from   t_search   where   fields   is   not   null)   b   where   a.fieldsnames=b.fieldsnames;

这语句会报错:ora-00933   命令未正确结束

语法我感决没错阿
用惯了sql   server,刚学oracle

谢谢各位的解答!!!
发表于:2007-04-04 15:45:041楼 得分:20
update   t_search   set   fields=b.fields,selecttype=b.selecttype   from   t_search   a,(select   distinct   fields,fieldsnames,selecttype   from   t_search   where   fields   is   not   null)   b   where   a.fieldsnames=b.fieldsnames;
====> > >
update   t_search   set   (fields,selecttype)   =   (select   distinct   b.fields,   b.selecttype   from   t_search   b   where   fieldsnames=b.fieldsnames)
where   exists   (select   1   from   t_search   b   where   fieldsnames=b.fieldsnames);
大致就是这样,确保两个字段关联后,查询是唯一的,否则会报错

具体看下oracle的语法,oracle和mssql是不一样的
发表于:2007-04-04 15:45:422楼 得分:0
oracle不支持distinct   吧
发表于:2007-04-04 15:51:293楼 得分:0
to   love_2008(love2008):
update   t_search   set   (fields,selecttype)   =   (select   distinct   b.fields,   b.selecttype   from   t_search   b   where   fieldsnames=b.fieldsnames)
where   exists   (select   1   from   t_search   b   where   fieldsnames=b.fieldsnames);

这还是会报错:单行子查询返回多余一个行
发表于:2007-04-04 15:54:554楼 得分:0
这个错误就是我所说的要确保唯一

那说下你的需求吧       列举出例子来      

发表于:2007-04-04 16:03:565楼 得分:0
我要到达的效果就是在本表中用某个字段(不为空的记录去更新其他为空的记录)
不为空的可由下面的到:
(select   distinct   fields,fieldsnames,selecttype   from   t_search   where   fields   is   not   null)
发表于:2007-04-04 16:11:506楼 得分:0
你的查询应该是根据这个字段fieldsnames

以这个字段分组,不为空的记录会有几条     若是多与1条我用哪条去更新哪?
例如

fieldsnames       fields         fieldsnames
1                           空                 空
1                           wwe               ee
1                           rr                 tt

这样的话     fieldsnames为1的且fields   不为空的有两条   我应该用哪条去更新哪
发表于:2007-04-04 16:32:417楼 得分:0
1                           wwe               ee
1                           rr                 tt
没有这种情况
发表于:2007-04-04 16:49:188楼 得分:0
那有没有   fieldsnames值为1而fields全部为空的

还是我给你做个测试吧

发表于:2007-04-04 16:55:579楼 得分:0
sql>   select   *   from   a;

                id             field                 val
----------   ----------   ----------
                  1
                  1                     2                     3
                  2                     3                     4
                  2
                  2                                           5
sql>   update   a   set   (field,val)=(select   b.field,b.val   from   a   b   where   a.id=b.id   and   b.field   is   not   null
    2       and   a.field   is   null)
    3     where   exists(select   1   from   a   b   where   a.id=b.id   and   b.field   is   not   null
    4       and   a.field   is   null);

已更新3行。

sql>   select   *   from   a;

                id             field                 val
----------   ----------   ----------
                  1                     2                     3
                  1                     2                     3
                  2                     3                     4
                  2                     3                     4
                  2                     3                     4
若是你更新后结果不对的话,说明你的数据有问题,也就是不唯一     或者有其他情况
发表于:2007-04-04 16:56:1210楼 得分:0
那种情况就不用更新先


快速检索

最新资讯
热门点击