语句:
select a.sp_code,b.sp_name
from VIEW_ST_SP_SMS a, VIEW_SP_INFO b
where a.sp_code=b.sp_id and a.bal_month='200508';
一执行就报这个错误,但是去掉条件中的"and a.bal_month='200508'"时可以正确执行.
大家知道这个错误怎么解决吗?原因是什么?
先谢啦.
select a.sp_code,b.sp_name
from VIEW_ST_SP_SMS a, VIEW_SP_INFO b
where a.sp_code=b.sp_id and a.bal_month='200508';
一执行就报这个错误,但是去掉条件中的"and a.bal_month='200508'"时可以正确执行.
大家知道这个错误怎么解决吗?原因是什么?
先谢啦.
selct a, b, sum(c) from x
where ...
group by a, b报的错如题:
ORA-01446:无法从含DISTINCT, GROUP BY等子句的视图中选择ROWID
Cause: A SELECT statement attempted to select ROWIDs from a view containing columns derived from functions or expressions. Because the rows selected in the view do not correspond to underlying physical records, no ROWIDs can be returned. 你把建视图的语句和查询视图的语句放在一块,是什么样的?问题可能就在其中。
create or replace view VIEW_ST_SP_SMS as
select bal_month, acc_prov, sp_code, sum(info_fee) as info_fee,
sum(month_fee) as month_fee --有好多sum(...)
from ST_SP_SMS
group by bal_month, acc_prov, sp_codecreate or replace view view_sp_info as
select sp_id, sp_name from sp_info where (sp_id, valid_date)
in (select sp_id, max(valid_date) valid_date from sp_info group by sp_id)第二个视图,由于sp_info表中同一sp_id可能有多条记录,但valid_date和sp_name不同,而我只要当前仍然生效的数据(sp_id须唯一),我仔细考虑了一下,就写成这个样子.请大家指点,看这个视图创建语句是否有其它方法,但最终目的是要解决以下错误--执行以下语句就报ORA-01446错误:
select a.sp_code, b.sp_name, sum(a.info_fee+a.month_fee)
from VIEW_ST_SP_SMS a, VIEW_SP_INFO b
where a.sp_code=b.sp_id and a.bal_month='200508';
语句不全?view VIEW_ST_SP_SMS 中不是有bal_month字段吗?
from VIEW_ST_SP_SMS a, VIEW_SP_INFO b
where a.sp_code=b.sp_id and a.bal_month='200508'
需要有group by a.sp_code, b.sp_name吧,没分组应该会报错吧。现在不报错吗?
现在看不出a.bal_month有什么特殊之处,所以可能问题在你没写出来的内容里了
查询语句中没有sum, 应该是这样的:
select a.sp_code, b.sp_name, a.info_fee, a.month_fee
from VIEW_ST_SP_SMS a, VIEW_SP_INFO b
where a.sp_code=b.sp_id and a.bal_month='200508';因为原语句涉及很多列,我这里简化了一下,但基本问题覆盖到了,这样也是报同样的错误.
我想问题出在第二个视图中,因为它是"含GROUP BY子句的视图".
这样用如上语句时才会报这个错:
ORA-01446:无法从含DISTINCT, GROUP BY等子句的视图中选择ROWID 问题是我现在也找不到更好的办法(不用GROUP BY子句)来建第二个视图.各位有何高见?
va1:select id,userid,sum(wei) wei from b group by id,userid
va2:select id ,userid from a where (id,wei) in (select id,max(wei) from a group by id)
SQL> select * from va1; ID USERID WEI
---------- ---------- ----------
1 a 276
1 b 112
2 a 5
2 c 111
3 a 60
4 a 130
30 aa,bb,a,us 100
40 aa,bb,a,ab 100已选择8行。SQL> select * from va2; ID USERID
---------- --------------------
1 the first one
1 1df
1 A
2 a
3 c
4 a
5 a
11 the first
12 first天安门
13 first 天安门
14 the first 天安门 ID USERID
---------- --------------------
15 b
16 b
17 a
18 c
19 b已选择16行。SQL> select a.id,b.userid,a.wei from va1 a,va2 b where a.id=b.id and a.userid='a
'; ID USERID WEI
---------- -------------------- ----------
1 the first one 276
1 1df 276
1 A 276
2 a 5
3 c 60
4 a 130已选择6行。SQL>
你的语句中有没有用到rowid?
别用视图了,直接写吧,直接写就没有约束了。
我完全参照这几个视图的创建语句,在一个同一个库上建了两个视图,就不会有这个问题
如果两个视图在不同的库上,就会有这个问题waterfirer(水清):
你能把两个视图建在不同的库上试试看吗?这到底是什么原因啊?郁闷!
bal_month的类型是不是Date,如果的话不能直接比较的!
对,我的确用的是db-link但是我的建视图语句中又确实有DISTINCT, GROUP BY子句,最痛苦的莫过于知道了错误代码却不知道原因和解决办法的事情了:(
最后的解决方案是绑定一个本地表(我用的是dual表,因为本地表不需要参与),问题解决了。参考代码如下:select * from myview@mydblink where ...; -- oracle 抛出错误select * from myview@mydblink, dual where ...; -- 工作正常你不彷试一下。