plsql EXECUTE IMMEDIATE动态执行sql

select * from BANK t;

DECLARE
v_money bank.money%TYPE;
BEGIN

--简单执行sql,注意sql字符串不要带分号结束
EXECUTE IMMEDIATE 'SELECT money FROM bank WHERE id = 5';

--带参数,参数使用using传入,按顺序的传入
EXECUTE IMMEDIATE 'SELECT money FROM bank WHERE id = :param1 or id =:param2'
USING '4','5';

--执行sql后,取值,using在赋值后面
EXECUTE IMMEDIATE 'SELECT money FROM bank WHERE id = :param1'
INTO v_money
USING '2';

DBMS_OUTPUT.PUT_LINE( 'Column Variable: ' || v_money );

END;

 

你可能感兴趣的:(plsql EXECUTE IMMEDIATE动态执行sql)