Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
170 views
in Technique[技术] by (71.8m points)

oracle - Getting error when calling any function in SQL query in a package without declaring function in package specification

I have created a function which return NUMBER type in a package, but not declare this function in the Package Specification.

I am calling this function in SQL query in anther function with in same package body. I am getting error.

When i declare function in Package Specification Then its fine & working.

I want to know reason behind it. Please anybody explain it.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Nothing to do with forward declaration at all.

This deals with the fact that you are using a SQL query to call the function. It seems like when using a statement to invoke a function, you are no longer inside the scope of the PL/SQL package, thus you can only call publicly available functions.

As for the why, I can only guess, so don't take it as granted, but PL/SQL and SQL have different engines. So, when doing a sql query, even inside your pl/sql package, you go to the level of SQL where it'll check again the permissions according to the SQL engine. So it has no idea it is executed from within a PL/SQL package and you should be allowed to call the private function.

I think the difference of engines can be checked easily, try to use a varchar2 of 32000, it'll work within your pl/sql function. Now, if you call your pl/sql function returning a varchar2(32000), it'll fail. Thi is a problem I ran into, but I don't have any databse to give you a snippet.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...