在PL/SQL中運行SQL語句有多種方式:
BEGIN
EXECUTE IMMEDIATE 'SELECT * FROM employees WHERE employee_id = 100';
END;
DECLARE
emp_name employees.last_name%TYPE;
BEGIN
SELECT last_name INTO emp_name FROM employees WHERE employee_id = 100;
DBMS_OUTPUT.PUT_LINE('Employee Name: ' || emp_name);
END;
DECLARE
CURSOR c_emp IS SELECT * FROM employees WHERE salary > 5000;
emp_rec employees%ROWTYPE;
BEGIN
OPEN c_emp;
LOOP
FETCH c_emp INTO emp_rec;
EXIT WHEN c_emp%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(emp_rec.employee_id || ' - ' || emp_rec.last_name);
END LOOP;
CLOSE c_emp;
END;
這些是PL/SQL中運行SQL語句的常見方式,具體使用哪種方式取決于具體的需求和情況。