set serveroutput on
declare
v_ename emp.ename%type;
v_sal emp.sal%type;
v_rowid varchar2(40);
begin
for i in 65.. 78 loop
v_rowid := 'AAASbbAAHAAASLWAA'||chr(i);
select ename, sal into v_ename, v_sal
from emp
where rowid = v_rowid;
dbms_output.put_line(v_ename || ' ' || v_sal);
end loop;
end;
/
---------------------------------------
for 문에서 최대한 숫자를 사용하지 않는 방법?
set serveroutput on
declare
v_ename emp.ename%type;
v_sal emp.sal%type;
v_rowid varchar2(40);
v_cnt number;
begin
select count(*) into v_cnt from emp;
for i in 1.. v_cnt loop
v_rowid := 'AAASbbAAHAAASLWAA'||chr(i+64);
select ename, sal into v_ename, v_sal
from emp
where rowid = v_rowid;
dbms_output.put_line(v_ename || ' ' || v_sal);
end loop;
end;
/
결과
KING 5000
BLAKE 2850
CLARK 2450
JONES 2975
MARTIN 1250
ALLEN 1600
TURNER 1500
JAMES 950
WARD 1250
FORD 3000
SMITH 800
SCOTT 3000
ADAMS 1100
MILLER 1300
PL/SQL 프로시저가 성공적으로 완료되었습니다.