Oracle学习之PL/SQL块
1.简单开始
DECLARE
name varchar2(20);
BEGIN
select first_name into name from hr.employees where employee_id=&no;
dbms_output.put_line(name);
EXCEPTION
WHEN NO_DATA_FOUND THEN
dbms_output.put_line('该雇员不存在!');
END;
/
2. 简单---
DECLARE
TYPE emp_record_type IS RECORD (
name emp.ename%TYPE,
salary emp.sal%TYPE
);
TYPE ename_table_type IS TABLE OF emp_record_type;
ename_table ename_table_type;
BEGIN
SELECT ename,sal BULK COLLECT INTO ename_table FROM emp;
FOR i IN 1..ename_table.COUNT LOOP
--dbms_output.put_line(ename_table(i).name);
dbms_output.put(rpad(ename_table(i).name,20,' '));
dbms_output.put_line(rpad(ename_table(i).salary,10,' '));
END LOOP;
END;
/