在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的常见方法。通过这些方法,可以实现数据操作、流程控制和错误处理等功能。