Can we define a Procedure in a Package Body without Defining in a Specifica
Hi,
Can we define a Procedure in a Package Body without Defining in a Specification,,
if yes then how...,Please provide me some examples
Please helpme out....
Regards
Nikhil
Yes we can!
But this procedure can then only be called from other procedures/functions in the same package.
Examples?
untested
create or replace package test
as
begin
null
end;
create or replace package body test
as
procedure dummy
as
begin
null;
end dummy;
end;
/
Similar Messages
-
How can i find start line of any functions or procedures stored in package body?
hi
how can i find start line of any functions or procedures stored in package body?
is there any way to write a query from for example user_source?
thankshow can i find start line of any functions or procedures stored in package body?
Why? What will you do differently if a procedure starts on line 173 instead of line 254?
Tell us what PROBLEM you are trying to solve so we can help you find the best way to solve it.
If you use PL_SCOPE that info is available in the *_IDENTIFIERS views. See 'Using PL/Scope in the Advanced Dev Doc
http://docs.oracle.com/cd/B28359_01/appdev.111/b28424/adfns_plscope.htm
Try this simple sample code. The query is modified from that doc sample:
-- tell the compiler to collect the info
ALTER SESSION SET PLSCOPE_SETTINGS='IDENTIFIERS:ALL';
-- recompile the package
CREATE OR REPLACE package SCOTT.pack1 as
PROCEDURE proc1;
PROCEDURE proc2;
END;
CREATE OR REPLACE package BODY SCOTT.pack1 as
PROCEDURE proc1 IS
BEGIN
NULL;
END;
PROCEDURE proc2 IS
BEGIN
proc1;
END;
PROCEDURE proc3 IS
BEGIN
proc1;
proc2;
END;
END;
-- query the info for the package spec
WITH v AS (
SELECT Line,
Col,
INITCAP(NAME) Name,
LOWER(TYPE) Type,
LOWER(USAGE) Usage,
USAGE_ID,
USAGE_CONTEXT_ID
FROM USER_IDENTIFIERS
WHERE Object_Name = 'PACK1'
AND Object_Type = 'PACKAGE'
SELECT LINE, RPAD(LPAD(' ', 2*(Level-1)) ||
Name, 20, '.')||' '||
RPAD(Type, 20)||
RPAD(Usage, 20)
IDENTIFIER_USAGE_CONTEXTS
FROM v
START WITH USAGE_CONTEXT_ID = 0
CONNECT BY PRIOR USAGE_ID = USAGE_CONTEXT_ID
ORDER SIBLINGS BY Line, Col
LINE,IDENTIFIER_USAGE_CONTEXTS
1,Pack1............... package declaration
2, Proc1............. procedure declaration
3, Proc2............. procedure declaration
-- query the info for the package body - change 'PACKAGE' to 'PACKAGE BODY' in the query above
LINE,IDENTIFIER_USAGE_CONTEXTS
1,Pack1............... package definition
2, Proc1............. procedure definition
6, Proc2............. procedure definition
8, Proc1........... procedure call
10, Proc3............. procedure declaration
10, Proc3........... procedure definition
12, Proc1......... procedure call
13, Proc2......... procedure call -
Function call in procedure within Package Body
I am a novice in PL/SQL so that I can't find out where the problem is. I am testing a function call in procedure within a Package Body.
But the PL/SQL Complier doesn't compile the package body but I don't know what I do wrong. Plz let me know how to call a function in procedure within a Package Body?
Here are the Packaget test programs..
CREATE OR REPLACE PACKAGE manage_students
IS
PROCEDURE find_sname;
PROCEDURE find_test;
PROCEDURE find_test_called;
FUNCTION GET_LASTMT
RETURN SEQUENCE_TEST.SEQ_NO%TYPE;
END manage_students;
CREATE OR REPLACE PACKAGE BODY manage_students AS
v_max_nbr SEQUENCE_TEST.SEQ_NO%TYPE;
PROCEDURE find_sname
IS
BEGIN
BEGIN
SELECT MAX(SEQ_NO)
INTO v_max_nbr
from SEQUENCE_TEST;
DBMS_OUTPUT.PUT_LINE('MAX NUMBER is : '||v_max_nbr);
EXCEPTION
WHEN OTHERS
THEN DBMS_OUTPUT.PUT_LINE('Error in finding student_id: ');
RETURN;
END;
COMMIT;
EXCEPTION
WHEN OTHERS
THEN DBMS_OUTPUT.PUT_LINE('Error in finding student_id: ');
END find_sname;
PROCEDURE find_test
IS
BEGIN
BEGIN
DBMS_OUTPUT.PUT_LINE('MAX NUMBER Called from another procedure : '||v_max_nbr);
EXCEPTION
WHEN OTHERS
THEN DBMS_OUTPUT.PUT_LINE('Error in finding student_id: ');
RETURN;
END;
COMMIT;
EXCEPTION
WHEN OTHERS
THEN DBMS_OUTPUT.PUT_LINE('Error in finding student_id: ');
END find_test;
FUNCTION GET_LASTMT
RETURN SEQUENCE_TEST.SEQ_NO%TYPE
IS
v_max_nbr SEQUENCE_TEST.SEQ_NO%TYPE;
BEGIN
SELECT MAX(SEQ_NO)
INTO v_max_nbr
from SEQUENCE_TEST;
RETURN v_max_nbr;
EXCEPTION
WHEN OTHERS
THEN
DECLARE
v_sqlerrm VARCHAR2(250) :=
SUBSTR(SQLERRM,1,250);
BEGIN
RAISE_APPLICATION_ERROR(-20003,
'Error in instructor_id: '||v_sqlerrm);
END;
END GET_LASTMT;
PROCEDURE find_test_called
IS
BEGIN
BEGIN
V_max := Manage_students.GET_LASTMT;
DBMS_OUTPUT.PUT_LINE('MAX_NUMBER :'|| V_max);
EXCEPTION
WHEN OTHERS
THEN DBMS_OUTPUT.PUT_LINE('Error in finding student_id: ');
RETURN NULL;
END;
COMMIT;
EXCEPTION
WHEN OTHERS
THEN DBMS_OUTPUT.PUT_LINE('Error in finding student_id: ');
END find_test_called;
END manage_students;
DECLARE
v_max SEQUENCE_TEST.SEQ_NO%TYPE;
BEGIN
manage_students.find_sname;
DBMS_OUTPUT.PUT_LINE ('Student ID: Execute.');
manage_students.find_test;
manage_students.find_test_called;
END;
-----------------------------------------------------------------------------------------------Hi,
Welcome to the forum!
You'll find that there are a lot of people willing to help you.
Are you willing to help them? Whenever you have a problem, post enough for people to re-create the problem themselves. That includes CREATE TABLE and INSERT statements for all the tables you use.
Error messages are very helpful. Post the complete error message you're getting, including line number. (It looks like your EXCEPTION sections aren't doing much, except hiding the real errors. That's a bad programming practice, but probably not causing your present problem - just a future one.)
Never post unformatted code. Indent the code to show the extent of each procedure, and the blocks within each one.
When posting formatted text on this site, type these 6 characters:
\(all small letters, inside curly brackets) before and after each section of formatted test, to preserve the spacing.
For example, the procedure find_test_called would be a lot easier to read like this:PROCEDURE find_test_called
IS
BEGIN
BEGIN
V_max := Manage_students.GET_LASTMT;
DBMS_OUTPUT.PUT_LINE ('MAX_NUMBER :' || V_max);
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.PUT_LINE ('Error in finding student_id: ');
RETURN NULL;
END;
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.PUT_LINE ('Error in finding student_id: ');
END find_test_called;
It's much easier to tell from the code above that you're trying to return NULL from a procedure. Only functions can return anything (counting NULL); procedures can have RETURN statements, but that single word"RETURN;" is the entire statement. -
Can't see package body in SQL Developer version 2.1.1.64
When I go to the object browser, I can see all of the package specs but can't seem to get to the package body. I can access the package body just fine through Toad, so I don't think it is an Oracle user issue. Help?
I can see any user's Package Body when I'm logged into the database as a DBA, so it must be some privilege that you need. The privilege I would have guessed you need is SELECT ANY DICTIONARY but you say you have that privilege. If you were granted that privilege through a role, make sure that the role is active, or that it is a default role.
Another role it might be looking for is EXECUTE ANY PROCEDURE, but I'm not sure. See if you can do these selects, since these are probably the views that SQL Developer is using:
select * from dba_objects where owner = 'some owner' and object_type = 'PACKAGE BODY';
select * from dba_source where owner = ' some owner' and type = 'PACKAGE BODY';Of course, if your database administrator is willing to grant you the DBA role, that ought to do the trick - works for me. Otherwise, you and your DBA may have to try different system privileges until you find the one that works. -
Use OCIDescribeAny to describe Procedure in a package?
I used the following code retrieve the parameter information for
procedures:
OCIDescribeAny(svchp, errhp, objptr, objp_len, OCI_OTYPE_NAME,0,
OCI_PTYPE_PROC, deschp);
if (OCIAttrGet(deschp, OCI_HTYPE_DESCRIBE, &parmh, 0,
OCI_ATTR_PARAM, errhp))
return ;
if (OCIAttrGet(parmh, OCI_DTYPE_PARAM, &arglst, 0,
OCI_ATTR_LIST_ARGUMENTS, errhp))
return ;
if (OCIAttrGet(arglst,OCI_DTYPE_PARAM, &numargs, 0,
OCI_ATTR_NUM_PARAMS, errhp))
return ;
If I pass a procedure which exists in a package, I will get a
object does not exist error. How can I describe a procedure in a
package using OCIDescribeAny ? Thanks.I tested it in the SQL Worksheet (rather than the PL/SQL editor), but I see the same behaviour as you when I try with your example in the PL/SQL editor. A little testing suggests that the problem is that the completion insight doesn't understand the context of where it is in the PL/SQL and so doesn't know what options to list.
If I try adding the end for the new procedure and then going back to after the "(":procedure Proc_test_call
is
begin
pkg_test2.proc_test2(
end proc_test_call;I just get begin and declare as options - ie completion insight thinks I am no longer in scope of the package (as other package components not listed) and starting a new block.
If I try adding an assignment before the procedure call (not logical, I know, but I had been testing with a function in my schema):procedure Proc_test_call
is
begin
result := pkg_test2.proc_test2(I get what we should (parameters for proc_test2 and local scope items).
Your workaround of adding the closing backet for the procedure call helps the completion insight understand the context of where it is and so it can give the right options.
I have previously avoided parameter completion insight as earlier versions had big performance problems when connected to a schema with a large number of PL/SQL objects (our main schema has 5.5 million records in all_arguments), but the performance has certainly been fixed. However, the PL/SQL editor still seems pretty hit and miss as to whether the parameter completion insight works, which seems largely to be because it doesn't always the context of where it is in the PL/SQL.
theFurryOne -
Package Body in the tree doesn't show all procedures
I am using Sql Developer 1.0.0.14.67 on Win XP Professional,
DB servers Oracle 9i on both Linux Red HAt and Win XP Professional
I have troubles with one of packages - in the tree under Package Body SQL Developer doesn't show all procedures of this package body.
On the right panel all package body source is shown, but in the tree under Package Body it shows names of only procedures up to certain line in the source code - up to line where first Private (not included in Package Spec) procedure code starts.
BUT, there are more Public procedures in package body below this Private procedure - and all of procedures below first private are not included in the tree under Package BodyI find this quite annoying. I cannot use the navigation panel on the left to find the location of all functions and procedures in the package body. The 'missing' procedures are listed under the package spec, and double clicking on them takes me to the spec and not the body.
I'm running v1.2.1.32.13. Is this a know issue and is there a fix planned? -
How to search ONLY in package names, without descriptions?
Hello!
I would like to know how I can search with pacman only in the package names, without searching descriptions?
For example, searching for the rar package (pacman -Ss rar) gives me tons of results with hundreds of packages, where "library" occurs in the description.
I have already read the pacman manual page, but I couldn't find anything suitable.
Greets, Horstperl -e '$search = "rar";$output=`pacman -Ss $search`;while($output=~/^(\S.*?\Q$search\E.*?\n(?:\s.*\n)*)/mgi){print $1}'
This does the normal "pacman -Ss whatever" search, but then it checks that the search term is in the package name. Just replace "rar" in "$search = "rar" with whatever you want to search for.
I tried to make it work with grep using -P, but I still don't know how to make it case-insensitive then ("-i" doesn't seem to work with perl regexes). Here it is anyway though:
pacman -Ss rar | grep -P "^\S.*?rar(?:.*|\n)*?(?=\n\S)"
Aside from being case-sensitive, you also have to replace both instances of "rar" with your search term.
Here's a script version that you can run from the command line:
#!/usr/bin/perl
use strict;
use warnings;
my $search = "@ARGV";
my $output = '';
open(my $pipe,'-|',"pacman -Ss $search") or die "Unable to create pipe to pacman: $!\n";
while (defined(my $line=<$pipe>)){$output.=$line;}
close $pipe;
while($output=~/^(\S.*?\Q$search\E.*?\n(?:\s.*\n)*)/mgi){print $1};
Save it as "search_pkgnames", make it executable, then invoke it with your search term: search_pkgnames rar
Hope this helps. -
Variable declaration in Package and package body
Hi
Kindly reply the difference in declaring a cursor inside a package vs package body
eg:
create or replace package shapak is
cursor shacur is select * from sha;
function shafun return number;
end;
i can declare the above cursor inside the package body withoout declaring in package specification. but what is the difference?
reply appreciated
thanks
shajanIn general..Items declared in the package spec are visible outside the package..so you can say public.where as items declared in the body are restricted to use within the package..such items are called private.
-
Can i create any procedure or function inside a oracle reserve package?
Hi!
Can i create any procedure or function inside a oracle reserve package. Suppose, I want to create a function called x in the dbms_output package. Can i do that? Or can i extend the features of this package and create/derived a function from it like we extend any class in JAVA. I'm not sure - whether this is at all possible. I'll be waiting for your reply.
Thanks in advance.
Satyaki De.No, but you can write a wrapper package and use that instead of using the Built-In package directly. So, instead of calling DBMS_OUTPUT, you call your own Package.
Steven Feuerstein wrote a wrapper for DBMS_OUTPUT, called P:
Re: DBMS_OUTPUT.PUT_LINE -
Can i compile new procedures/packages on my snapshot standby?
Hi
can i compile new procedures/packages on my snapshot standby?
I need to test the new release of the application, which include some changes to current packages
thanksyes you can do it, just that it will be flashbed back to the restore point when it was standby first, do anything on it, but be aware that later you convert from snapshot standby to physical standby, more time it would take for redo to be applied and also it is mandatory to open the snapshot at least once in read-write mode before it can be converted into a physical standby database.
Regards
Karan -
Can we define cursors from in procedure while using .procedure file?
Hi Team,
Can we define cursors from in procedure while using .procedure file?
I have a catalog procedure in which am using cursors and it is working fine. But while trying to create the same procedure using .procedure , the validation is failing with "An error occurred while parsing your procedure".
Request your suggestions.
Regards,
Krishna TanguduHi Krishna,
I also tried to find the validation for procedure and failed. What was on my mind when I posted earlier was related to Window -> Properties -> SAP HANA -> Modeler -> Validation Rules but this is not the same for procedure.
Also the validation error seems to not being raised by Studio but the server, so it's not a frontend validation anyway.
Trying to replicate your error I create two procedures here and both worked fine with cursor.
The behavior you found was the same I found, the .procedure goes to repository and _SYS_BIC after activation and .hdbprocedure goes to catalog only.
As far as I understood as you are moving from catalog (manually) and it worked on catalog (.hdbprocedure), I could check the declaration of table types of header as it's the main difference.
Despite this investigation of declaration, you can try create it on modeler direct and see what you found on .procedure created. This can speed up investigation.
Regards, Fernando Da Rós
BTW: I'm faced an very strange behavior that each caracter I type on .procedure or .hdbprocedure freezes studio by around 15 seconds ?!?!?!?! (studio rev73) -
Can I call a function in another package?
Dear all,
Can I call a function in another package?
Say I have package A, and package B.
Is it possible for me to call a function in inside package A, within a function inside package B?
If yes, what's the syntax.
Thanks in advance!The variable in the calling package that will receive the value of the function in the other package needs to be defined based on that type in the other package directly:
sql>create or replace package pkg_a
2 is
3 type testTable is table of varchar2(10) index by binary_integer;
4
5 function f_a return testTable;
6 end;
7 /
Package created.
sql>create or replace package body pkg_a
2 is
3 function f_a
4 return testTable
5 is
6 v_table testTable;
7 begin
8 v_table(1) := 'One';
9 v_table(2) := 'Two';
10 return v_table;
11 end;
12 end;
13 /
Package body created.
sql>create or replace package pkg_b
2 is
3 procedure p_b;
4 end;
5 /
Package created.
sql>create or replace package body pkg_b
2 is
3 procedure p_b
4 is
5 v_table pkg_a.testTable; -- this variable has to be based on the type in pkg_a
6 begin
7 v_table := pkg_a.f_a;
8 for i in 1..v_table.count loop
9 dbms_output.put_line( v_table(i) );
10 end loop;
11 end;
12 end;
13 /
Package body created.
sql>exec pkg_b.p_b
One
Two
PL/SQL procedure successfully completed. -
Oracle stored procedure in a package
Hello,
I'm working on a Web service -> XI -> Oracle scenario.
In the receiver side I'm using JDBC Adapter to call to stored procedure.
I have stored procedure in a package.
For example: package "price_list_pk" and stored procedure "is_pl".
When I try to enter the stored procedure path to XML tags I need to separate between the package and the stored procedure with dot "." and dot is not allowed in XML tag.
I want to now if you have answer for this problem
Have other way to work with stored procedure in packages?
EladHey everyone,
What Elad means is that in the XML structure of JDBC there are 2 places you define the DB\SP name:
1. Defined in the structure itself as an element name. (DT)
2. Mapped with a constant to a subelement called TABLE. (MM)
The MM shouldn't be a problem as a value can get the dot character.
But, in the DT structure, because you define here a XSD (XML structure) there is a problem naming the element with the dot character being part of the name as this character is not accepted in a XML tagname.
The right question is if anyone knows of a special XML attribute with which you could define that the element name would contain a dot character? Or else a creative way to call a Stored Procedure inside a Package despite the disabilities above?
Ben -
How to import only procedures, functions, and packages only
Hi everybody...
How to import only procedures, functions, and packages only from one user to another user.
Thanks in advance
palThanks for your reply...i did the following..can you please help from this how to proceed
---------------- getcode.sql -------------------------------
set feedback off
set heading off
set termout off
set linesize 1000
set trimspool on
set verify off
spool &1..sql
prompt set define off
select decode( type||'-'||to_char(line,'fm99999'),
'PACKAGE BODY-1', '/'||chr(10),
null) ||
decode(line,1,'create or replace ', '' ) ||
text text
from user_source
where name = upper('&&1')
order by type, line;
prompt /
prompt set define on
spool off
set feedback on
set heading on
set termout on
set linesize 100
------------------- getallcode.sql -------------------------
set termout off
set heading off
set feedback off
set linesize 50
spool c:\xtmpx.sql
select '@getcode ' || object_name
from user_objects
where object_type in ( 'PROCEDURE', 'FUNCTION', 'PACKAGE' )
spool off
spool c:\getallcode_INSTALL
select '@' || object_name
from user_objects
where object_type in ( 'PROCEDURE', 'FUNCTION', 'PACKAGE' )
spool off
set heading on
set feedback on
set linesize 130
set termout on
@xtmpx.sql
I did this one user and created the xtmpx.sql
and getallcode_INSTALL.LST.
From this, how to proceed to run these in another user.
Thanks,
Pal -
Procedures inside Oracle Packages
Hello All,
Can I execute an procedure defined inside an Oracle package using jdbc?
Are the procedures defined inside Oracle packages are same as stored procedures ?
Any help would be grately appreciated.
regards,
Abhishek.Yes you can execute a procedure defined inside an Oracle package. Use the prepareCall method eg
String param1 = 'some value';
oracleCStmt = oracleConn.prepareCall("begin package_name.proc_name(?); end;");
oracleCStmt.setString(1,param1);
oracleCStmt.executeUpdate();Yes a stored procedure in a package is no different to on inside a package. A package is just a collection of PL/SQL objects.
Richard
Maybe you are looking for
-
HELP! Does anyone know a "Data Recovery Expert" for I-Phone? - My calender disappeared during transfer of data from my old I-Phone 4 to my new I-Phone 5s. It was on both I-Phones then vanished. (It was evidently not syncing during back-ups on the lap
-
Mail 8.1 won't open links from messges
When reading a message, links within the message won't open. When I 2 finger click on the link, the drop-down window ask "open, open link behind mail, copy link, services" . None of them work. Before Yosemite. I could 2 finger click and choose what
-
When doing a type="simple" in a CFSEARCH, I am replacing the spaces in the criteria with commas. The issue comes when the words AND or OR appear in the criteria. So, Love and Logic changes to Love,and,Logic. For some reason, I get an error when this
-
ORA-28536 & ORA-28508 & global_names
Hi all, I set global_names to TRUE. I am working on db_link between Oracle and MS sql server. The init file: HS_FDS_CONNECT_INFO=MyHost,1433/master HS_FDS_TRACE_LEVEL=debug HS_FDS_RECOVERY_ACCOUNT=RECOVER HS_FDS_RECOVERY_PWD=RECOVER HS_DB_DOMAIN=MyDo
-
An enemy to follow me around the screen but not too fast
Hi I'm building English teaching apps but through games. I'd like a BUG enemy to follow me around but NOT TOO fast as I have little kids of 5 years old using this, Would it be something like get the coordinates of my HERO character and send the BUG t