在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语句的常见方式,具体使用哪种方式取决于具体的需求和情况。