很遗憾,无法做到这一点,因为在sql语句中使用存储函数是有限制的
请参看http://www.csdn.net/expert/topic/910/910596.xml?temp=.2698328

解决方案 »

  1.   

    在select中调用的存储过程或函数都不能有修改数据库的操作,更不能存在commit,rollback等语句了。所以你的想法根本不能实现。
      

  2.   

    我朋友说function里面是可以用commit的,所以还是把这句话贴在这里,zeng0926(zl)如果看到 可以再给点意见!感谢各位,我这里就结贴了!
      

  3.   

    --------------8i
    -- create the debug table
    CREATE TABLE debug_output (msg VARCHAR2(200));-- create the package spec
    CREATE PACKAGE debugging AS
       FUNCTION log_msg (msg VARCHAR2) RETURN VARCHAR2;
       PRAGMA RESTRICT_REFERENCES(log_msg, WNDS, RNDS);
    END debugging;-- create the package body
    CREATE PACKAGE BODY debugging AS
       FUNCTION log_msg (msg VARCHAR2) RETURN VARCHAR2 IS
          PRAGMA AUTONOMOUS_TRANSACTION;
       BEGIN
          -- the following insert does not violate the constraint
          -- WNDS because this is an autonomous routine
          INSERT INTO debug_output VALUES (msg);
          COMMIT;
          RETURN msg;
       END;
    END debugging;-- call the packaged function from a query
    DECLARE
       my_empno NUMBER(4);
       my_ename VARCHAR2(15);
    BEGIN
       ...
       SELECT debugging.log_msg(ename) INTO my_ename FROM emp
          WHERE empno = my_empno;
       -- even if you roll back in this scope, the insert
       -- into 'debug_output' remains committed because
       -- it is part of an autonomous transaction
       IF ... THEN 
          ROLLBACK;
       END IF;
    END;