【问题标题】:PLSQL call procedure from function从函数调用 PLSQL 过程
【发布时间】:2014-10-31 22:05:42
【问题描述】:

我有一个从选择查询中调用的函数,下面是完美运行的函数。如果 boolean = 1 将值插入登录表,我想调用以下过程:

create or replace FUNCTION isLoggedIn(x IN VARCHAR2, y IN VARCHAR2)
RETURN number IS
boolean number(1) := 0;
BEGIN
SELECT count(*) into boolean
FROM VIEWLOGIN
WHERE username = x AND password = y;

IF boolean = 1 THEN
    PROCDURELOGIN
    RETURN boolean;     
ELSE
    RETURN 0;
END IF;
END;

这是我的程序:

create or replace PROCEDURE PROCDURELOGIN
IS 
BEGIN
   INSERT INTO "SW3"."LOGIN" (LOGINID, MEMBERID) 
   VALUES (seqLogin.NEXTVAL, '1');
   Commit;
END;

Create view VIEWLOGIN
SELECT firstname, surname, username, password
FROM member

但是当我运行查询时出现错误:

Error starting at line : 1 in command -
SELECT firstname, surname, isLoggedIn(username, password)
FROM VIEWLOGIN
WHERE username = 'fionawalshe' AND password = 'qwertyu8'
Error report -
SQL Error: ORA-14551: cannot perform a DML operation inside a query 
ORA-06512: at "SW3.PROCDURELOGIN", line 4
ORA-06512: at "SW3.ISLOGGEDIN", line 10
14551. 00000 -  "cannot perform a DML operation inside a query "
*Cause:    DML operation like insert, update, delete or select-for-update
           cannot be performed inside a query or under a PDML slave.
*Action:   Ensure that the offending DML operation is not performed or
           use an autonomous transaction to perform the DML operation within
           the query or PDML slave.

【问题讨论】:

  • 就这样吧。问题是什么?
  • 请编辑您的问题并添加 VIEWLOGIN 视图的来源。谢谢。

标签: stored-procedures plsql stored-functions


【解决方案1】:

Oracle 在错误信息中明确指出,什么是问题。试试这个:

create or replace PROCEDURE PROCDURELOGIN
IS
pragma autonomous_transaction; 
BEGIN
   INSERT INTO "SW3"."LOGIN" (LOGINID, MEMBERID) 
   VALUES (seqLogin.NEXTVAL, '1');
   Commit;
END;

顺便说一句,我不喜欢这样的程序,建议尽可能不要使用它们。

【讨论】:

  • 完美排序。
猜你喜欢
  • 2015-03-09
  • 2013-05-18
  • 2016-12-23
  • 2016-08-24
  • 2013-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多