2014-03-06 2 views
0

프로 시저에서 다음 업데이트 줄을 실행해야합니다. 한 줄로 업데이트 할 수 있습니까? 여기에 하나의 테이블 만 있습니다.여러 열 업데이트

UPDATE magic_table SET first_col=0,last_col=my_value where first_col is not null; 
    UPDATE magic_table SET second_col=0,last_col=my_value where second_col is not null; 
    UPDATE magic_table SET third_col=null,last_col=my_value where third_col is not null; 

그렇다면 성능이 향상됩니까?

답변

2
update magig_table 
    set first_col = nvl2(first_col , 0, first_col), 
     second_col = nvl2(second_col, 0, second_col), 
     third_col = nvl2(third_col , 0, third_col), 
     last_col = my_value 
    where first_col is not null or 
     second_col is not null or 
     third_col is not null; 
+0

'third_col = nvl2 (third_col, null, third_col) '가 유효합니까? 'UPDATE magic_table SET third_col = null, last_col = my_value와 같이 third_col이 null이 아닌 것처럼 세번째 라인을 업데이트한다면 ?? – NaaN

0

이 시도 :

update magig_table 
set first_col = case when first_col is not null then 0 end, 
    second_col = case when second_col is not null then 0 end, 
    third_col = null, 
    last_col = my_value 
where coalesce(first_col,second_col,third_col) is not null; 

이 방법은 다음 nvl2의 사용을 더욱 확대됨입니다. 세 번째 열은 null이되므로 확인하지 않아도됩니다.

+0

답변에 '또는'이 추가됩니다. 또한 세번째 라인을'UPDATE magic_table SET third_col = null, last_col = my_value, third_col이 null이 아닌 곳으로 업데이트한다면' – NaaN

+0

; 당신의 질문이 잘못되었다는 것을 처음으로 다시 썼습니다. – smnbbrv

+0

그러나''합치는 데이터 타입 : incarsistent datatypes : expected CHAR got NUMBER' 라인에서 오류를 보여줍니다. 'first_col'이 varchar인데. – NaaN