Oracle 10G: ORA-06575: 函数处于无效状态

发布于 2024-10-20 19:14:06 字数 656 浏览 1 评论 0原文

我创建了一个这样的函数

CREATE OR REPLACE FUNCTION tax 
(p_sal IN  NUMBER(4)) 
RETURN NUMBER 
AS
v_tax NUMBER(4);
BEGIN 
v_tax:= CASE        
WHEN p_sal> 4000 THEN
p_sal*0.33       
WHEN p_sal >2500 THEN 
p_sal*0.25      
WHEN p_sal >1500 THEN 
p_sal*0.20     
ELSE 0         
END; 
RETURN v_tax;
END;
/

当我在插入 stmt 中使用这个税收函数时,

INSERT INTO employees(eno, ename, job, join_date, sal, comm)
VALUES (7784,'allen','salesman',sysdate, 5000, tax(5000));

,就像它显示错误一样,

ERROR: ORA-O6575: package or function tax is in invalid state.

有人可以建议我如何使这个函数处于有效状态吗? 提前致谢。

I created a funcion like this

CREATE OR REPLACE FUNCTION tax 
(p_sal IN  NUMBER(4)) 
RETURN NUMBER 
AS
v_tax NUMBER(4);
BEGIN 
v_tax:= CASE        
WHEN p_sal> 4000 THEN
p_sal*0.33       
WHEN p_sal >2500 THEN 
p_sal*0.25      
WHEN p_sal >1500 THEN 
p_sal*0.20     
ELSE 0         
END; 
RETURN v_tax;
END;
/

when i used this tax function in insert stmt like

INSERT INTO employees(eno, ename, job, join_date, sal, comm)
VALUES (7784,'allen','salesman',sysdate, 5000, tax(5000));

it shows the error like

ERROR: ORA-O6575: package or function tax is in invalid state.

can anyone suggest me how to make this function is in valid state?
thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

不顾 2024-10-27 19:14:06

使用此命令检查错误:

Select * from user_errors where name='Your function name'

Check errors with this command:

Select * from user_errors where name='Your function name'
素食主义者 2024-10-27 19:14:06

函数的编译如下:

alter function tax compile;

然后,检查编译错误:

SHOW ERRORS

Oracle 中的对象无效时有两个主要原因:

  1. 代码无效(并给出了
    当您尝试时出现错误消息
    编译它)。解决办法是
    当然要修复错误,然后
    重新编译它。
  2. 该对象引用了另一个对象,而另一个对象是
    改变了。解决办法是
    重新编译无效对象。

此外,某些数据库连接驱动程序保留对数据库中对象的引用。如果数据库中这些对象的状态发生变化,引用就会过时,您将收到类似于上述错误的错误。

A function is compiled like this:

alter function tax compile;

Then, check for compilation errors with:

SHOW ERRORS

There are two main reasons while an object in Oracle is invalid:

  1. The code is invalid (and gave an
    error message when you tried to
    compile it). The solution is of
    course to fix the error and then
    recompile it.
  2. The object references another object and the other object was
    changed. The solution is to
    recompile the invalid object.

Also, some database connection drivers keep references to objects in the database. If the state of those object change in the database the references go stale and you will get an error similar to the one above.

回忆躺在深渊里 2024-10-27 19:14:06

您可以使用 SHOW ERROR 命令检查错误

SQL> show error function Your_Function_Name;

You can check error(s) with SHOW ERROR command

SQL> show error function Your_Function_Name;
浅语花开 2024-10-27 19:14:06

确保您的函数编译没有错误。这就是 Oracle 通过 ERROR: ORA-06575 告诉您的内容。

使用以下语句创建函数:

CREATE OR REPLACE FUNCTION tax (p_sal IN NUMBER)
   RETURN NUMBER AS 
   v_tax NUMBER(4); 
BEGIN
   v_tax:= CASE
    WHEN p_sal> 4000 THEN p_sal*0.33
    WHEN p_sal >2500 THEN p_sal*0.25
    WHEN p_sal >1500 THEN p_sal*0.20
    ELSE 0
   END;
   RETURN v_tax;   
END;

在参数中声明 NUMBER 时,不需要参数列表中的 (4)

Make sure your function compiled without errors. That's what Oracle's telling you with ERROR: ORA-06575.

Create your function with this statement:

CREATE OR REPLACE FUNCTION tax (p_sal IN NUMBER)
   RETURN NUMBER AS 
   v_tax NUMBER(4); 
BEGIN
   v_tax:= CASE
    WHEN p_sal> 4000 THEN p_sal*0.33
    WHEN p_sal >2500 THEN p_sal*0.25
    WHEN p_sal >1500 THEN p_sal*0.20
    ELSE 0
   END;
   RETURN v_tax;   
END;

You don't need the (4) on the parameter list when declaring a NUMBER in parameter.

时光沙漏 2024-10-27 19:14:06

ORA-O6575: 包或函数税处于无效状态。

表示该函数需要编译。该语句

alter function tax compile;

应该编译该函数,但在某些情况下,它完成时没有错误,但实际上没有执行任何操作。 (dBeaver 就是这种情况)。

在这种情况下,请在 SQL 客户端中找到该函数,然后从菜单或工具栏中选择“编译”函数。

ORA-O6575: package or function tax is in invalid state.

means the function needs to be compiled. This statement

alter function tax compile;

should compile the function, but in some cases it completes without errors, but without actually doing anything. (This is the case in dBeaver).

In that case, locate the function in your SQL client and select the Compile function from a menu or toolbar.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文