在Oracle中,SELECT INTO语句用于将查询结果存储到一个变量或表中。
具体来说,SELECT INTO语句可以用于以下几个方面:
DECLARE
v_name employee.name%TYPE;
BEGIN
SELECT name INTO v_name FROM employee WHERE id = 1;
DBMS_OUTPUT.PUT_LINE('Name: ' || v_name);
END;
DECLARE
v_name employee.name%TYPE;
v_salary employee.salary%TYPE;
BEGIN
SELECT name, salary INTO v_name, v_salary FROM employee WHERE id = 1;
DBMS_OUTPUT.PUT_LINE('Name: ' || v_name || ', Salary: ' || v_salary);
END;
CREATE TABLE new_employee AS
SELECT name, salary FROM employee WHERE hire_date > SYSDATE - 365;
需要注意的是,SELECT INTO语句只能用于返回单行查询结果。如果查询结果返回多行,则会抛出异常。如果需要处理多行结果,可以使用游标或BULK COLLECT INTO语句。