oracle根據不同條件給字段賦不同的值

2021-09-03 08:52:42 字數 966 閱讀 2145

話不多說,先貼**

declare

cursor my_cur is

select t.empno, t.deptno, t.sal

from scott.emp t

where t.empno > '7698'

for update of sal;--鎖定sal這一列,不允許其他session更新sal列的資料

num number;

begin

for emp_row in my_cur loop

num := trunc(to_number(emp_row.empno) / nullif(to_number(substr(emp_row.deptno,1,2)),0));

if mod(emp_row.empno,10) = 0

then

update scott.emp t

set t.sal = trunc(to_number(emp_row.empno) / num)

where current of my_cur;

else if mod(emp_row.empno,11) = 0 then

update scott.emp t

set t.sal = trunc(to_number(emp_row.empno) / num)

where current of my_cur;

else

update scott.emp t

set t.sal = 100

where current of my_cur;

end if;

end if;

end loop;

commit;

end;

根據emp表中empno的不同值,擷取deptno的字段作為 除數,更改sal欄位。

where current of my_cur--指定當前游標行

DataTemplate 根據條件選擇不同模板

msdn datatemplate 為了不同的條件選擇模板,可以實現乙個datatemplateselector。1 模板選擇器是繼承自datatemplateselector,並重寫了selecttemplate方法並返回所需要的模板的類 public class persontemplatese...

MySQL order by基於不同字段條件排序

從資料庫上查詢資料的時候,按要求排序,在某個欄位的不同值的基礎上再選擇不同的字段進行排序,具體描述如下 1 首先有乙個基礎欄位status status 的取值分別為 1 2 3 4 2 先對status 進行排列,但是要求順序為 2 1 3 4 其實每個值都代表一種含義,簡單處理就是,將1和2代表...

MyBatis根據條件批量修改字段

conttoller restcontroller work public class workcontroller service service public class workservice public inte ce xml examine update work set isenabl...