得到主键的下一个值。
如:表中有testID(key) testName,testDescription
1001, name1, 1001Description
1002, name2, 1001Description
1003, name3, 1001Description
1004, name4, 1001Description
1005, name5, 1001Description
1006, name1, 1001Description
....
.....
当testId = 1001 and testName = name1时,做一个循环,怎么得到1006的。 谢谢这个是本人写的一个方法 写的这个循环老友问题。 请那位高手给指点下 小弟谢谢了。
SELECT to_char(nvl(to_number(LOG_ID),0)) INTO new_log_id_ FROM RUN_LOG_tab rl
WHERE rl.LOG_ID = log_id_ AND rl.ORG_CODE = org_code_;
IF direction_=1 THEN loop
new_log_id_ := to_char(to_number(new_log_id_)-1);
SELECT count(*) INTO log_count FROM RUN_LOG_tab rl
WHERE rl.LOG_ID = new_log_id_ AND rl.ORG_CODE = org_code_;
if log_count <> 0 then
--new_log_id_ := to_char(to_number(new_log_id_)-1);
Dbms_output.put_line('+++++++++++++1'||new_log_id_);
exit;
return new_log_id_;
ELSif log_count = 0 then
new_log_id_ := to_char(to_number(new_log_id_)-1);
end if;
end loop;
如:表中有testID(key) testName,testDescription
1001, name1, 1001Description
1002, name2, 1001Description
1003, name3, 1001Description
1004, name4, 1001Description
1005, name5, 1001Description
1006, name1, 1001Description
....
.....
当testId = 1001 and testName = name1时,做一个循环,怎么得到1006的。 谢谢这个是本人写的一个方法 写的这个循环老友问题。 请那位高手给指点下 小弟谢谢了。
SELECT to_char(nvl(to_number(LOG_ID),0)) INTO new_log_id_ FROM RUN_LOG_tab rl
WHERE rl.LOG_ID = log_id_ AND rl.ORG_CODE = org_code_;
IF direction_=1 THEN loop
new_log_id_ := to_char(to_number(new_log_id_)-1);
SELECT count(*) INTO log_count FROM RUN_LOG_tab rl
WHERE rl.LOG_ID = new_log_id_ AND rl.ORG_CODE = org_code_;
if log_count <> 0 then
--new_log_id_ := to_char(to_number(new_log_id_)-1);
Dbms_output.put_line('+++++++++++++1'||new_log_id_);
exit;
return new_log_id_;
ELSif log_count = 0 then
new_log_id_ := to_char(to_number(new_log_id_)-1);
end if;
end loop;
select min(testID) from table where testName='name1' and testID>'1001'