系统不是提示了嘛:无法在查询中执行 DML 操作
执行select get_s_seq('aa') from s_seq时,要调用get_s_seq函数,而此函数有执行了dml操作。
解决办法:先单独执行此函数,再查询

解决方案 »

  1.   

    ----in 8i, you can.
    -- 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;
      

  2.   

    select get_s_seq('aa') from dual;
      

  3.   

    是这样的。因为考虑移植的问题。我没有是用oracle的seq。
    准备自己维护一个seq。这样到其他数据库不会有序列的问题。
    各位老大再考虑考虑。