oracle中的函数和存储过程能不能达到这样的效果,比如,我在PL/SQL中写上 select * from tablea where condition1 = 1 and condition2 = 'aaa'因为条件1和'aaa'未知,我现在需要写在函数或存储过程中,但好像函数或存储过程返回的结果集不能像SELECT语句那样运行后直接显示,那该如何实现?是不是oracle不支持这个???
cursor aa(a in number,b in varchar2) is select * from tablea where condition1 = a and condition2 = b; for v in cursor (1,'aaa') loop ........ end loop;
DECLARE v_condition1 tablea.condition1%TYPE; v_condition2 tablea.condition2%TYPE; v_temp tablea%ROWTYPE; BEGIN SELECT * INTO v_temp FROM tablea WHERE condition1 = v_condition1 and condition2 = v_condition2 ; DBMS_OUTPUT.PUT_LINE (v_temp.v_condition1||'--'||v_temp.v_condition2); END;
select * from tablea where condition1 = a and condition2 = b;
for v in cursor (1,'aaa') loop
........
end loop;
v_condition1 tablea.condition1%TYPE;
v_condition2 tablea.condition2%TYPE;
v_temp tablea%ROWTYPE;
BEGIN
SELECT * INTO v_temp FROM tablea
WHERE condition1 = v_condition1 and condition2 = v_condition2 ;
DBMS_OUTPUT.PUT_LINE
(v_temp.v_condition1||'--'||v_temp.v_condition2);
END;
直接执行就可以
v_condition1 tablea.condition1%TYPE;
v_condition2 tablea.condition2%TYPE;
v_temp tablea%ROWTYPE;
BEGIN
SELECT * INTO v_temp FROM tablea
WHERE condition1 = v_condition1 and condition2 = v_condition2 ;
DBMS_OUTPUT.PUT_LINE
(v_temp.v_condition1 ¦ ¦'--' ¦ ¦v_temp.v_condition2);
END;