Oracle是10G的
我在PL/SQL执行以下语句3个半钟都没有执行完
update t_p_ds a set
dwbh = (select dwbh from t_p_dw where ROWNUM = 1 and nsrbm = a.col002 and zzjgdm = replace(a.col004,'-','')) where exists(select 1 from t_p_dw where nsrbm = a.col002 and zzjgdm = replace(a.col004,'-',''))
and a.dwbh is null and a.col002 is not null and a.col004 is not null
-------------
执行上面语句3个钟都没完
我是用SQL的,SQL表面上看是效率不好,但是用Update dwbh from T_P_ds a inner join T_P_DW on .... 这种方法Oracle又提示语法错误怎么优化这条SQL
谢谢
我在PL/SQL执行以下语句3个半钟都没有执行完
update t_p_ds a set
dwbh = (select dwbh from t_p_dw where ROWNUM = 1 and nsrbm = a.col002 and zzjgdm = replace(a.col004,'-','')) where exists(select 1 from t_p_dw where nsrbm = a.col002 and zzjgdm = replace(a.col004,'-',''))
and a.dwbh is null and a.col002 is not null and a.col004 is not null
-------------
执行上面语句3个钟都没完
我是用SQL的,SQL表面上看是效率不好,但是用Update dwbh from T_P_ds a inner join T_P_DW on .... 这种方法Oracle又提示语法错误怎么优化这条SQL
谢谢
解决方案 »
- 创建表居然提示无效字符?
- 能否根据ref对象表中的数据查询主表的数据
- SELECT NAME FROM MOBILE_MAIN NATURAL JOIN MOBILE_SUB关于natural join
- 请教:oracle中有求两个日期之间相差的自然月吗?
- 请问怎样把一个表的一个分区的查询权限付给另一个用户
- 怎么用sql plus insert 日期型数据
- 求助:关于存储过程的异常处理?
- 表空间使用的问题,大家帮忙看看是什么问题
- windows和unix、linux中数据库问题
- oracle11G中外部表的应用
- 严重: 启动 Database Control 时出错!导致使用pl/sql工具时报:ORA-12560:TNS:协议适配器错误
- 获取高峰数据
最好把rownum=1修改为rownum<2,
另:你子查询有重复数据吗?
------------
可能会有,所以加上rownum=1谢谢
set dwbh = (select dwbh
from t_p_dw
where ROWNUM < 2
and nsrbm = a.col002
and zzjgdm = replace(a.col004,'-',''))
where exists (select 1
from t_p_dw
where nsrbm = a.col002
and zzjgdm = replace(a.col004,'-',''))
and a.dwbh is null
and a.col002 is not null
and a.col004 is not null
--------------------------------------
还是不行。。没有反应
我两个表分别是T_P_DW 40W条 T_P_DS 30W条
有没有更好的写法?
检查一下关键字段的索引 nsrbm 和 a.col002上有索引吗?
test
select b.主键,a.dwbh,a.1
from t_p_dw a,t_p_ds b
where nsrbm = a.col002
and zzjgdm = replace(a.col004,'-','')
and ROWNUM = 1update t_p_ds a
set dwbh =
(
select dwbh
from test
where a.主键 = test.主键
)
where a.dwbh is null
and a.col002 is not null
and a.col004 is not null
and exists
(
select 1
from test
where a.主键 = test.主键
) 大概就是这个意思,好久没有写过ORACLE的代码了.
有些关键词也忘了,凑合的看个意思把.
提高你那sql效率
1,在操作的列上建立索引
2,a is null或a is not null 改用a>0或a>''或a<0 a<''
3,避免在索引上使用not
由此,更改你的sql如下:DECLARE
v_dwbh varhar2(128) := '';
BEGIN
SELECT dwbh
INTO v_dwbh
FROM t_p_dw
WHERE ROWNUM = 1
AND nsrbm = a.col002
AND zzjgdm = REPLACE(a.col004, '-', '');
IF dwbh > ''--若dwbh不为空,则更新,<>号效率底下
THEN
UPDATE t_p_ds a SET dwbh = v_dwbh;
END IF;
END