在PL/SQL中,Oracle可以使用以下方式:
DECLARE
my_var VARCHAR2(50);
BEGIN
my_var := 'Hello, World!';
DBMS_OUTPUT.PUT_LINE(my_var);
END;
CREATE PROCEDURE my_procedure AS
BEGIN
DBMS_OUTPUT.PUT_LINE('This is a stored procedure');
END;
CREATE FUNCTION my_function
RETURN NUMBER AS
BEGIN
RETURN 10;
END;
IF salary > 5000 THEN
DBMS_OUTPUT.PUT_LINE('High Salary');
ELSE
DBMS_OUTPUT.PUT_LINE('Low Salary');
END IF;
CASE
WHEN day = 'Monday' THEN
DBMS_OUTPUT.PUT_LINE('Today is Monday');
WHEN day = 'Tuesday' THEN
DBMS_OUTPUT.PUT_LINE('Today is Tuesday');
ELSE
DBMS_OUTPUT.PUT_LINE('Today is not Monday or Tuesday');
END CASE;
DECLARE
CURSOR employees_cur IS
SELECT * FROM employees WHERE department_id = 10;
emp_record employees%ROWTYPE;
BEGIN
OPEN employees_cur;
LOOP
FETCH employees_cur INTO emp_record;
EXIT WHEN employees_cur%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(emp_record.employee_name);
END LOOP;
CLOSE employees_cur;
END;
這些是一些在PL/SQL中使用Oracle的常見方法。通過這些方法,可以實(shí)現(xiàn)數(shù)據(jù)操作、流程控制和錯(cuò)誤處理等功能。