473,803 Members | 2,946 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pl/sql-package - 4

debasisdas
8,127 Recognized Expert Expert
PACKAGE WITH LOCAL FUNCTION
=============== ==============
Expand|Select|Wrap|Line Numbers
  1. create or replace package my_pkg as
  2. procedure my_proc(arg1 in varchar2);
  3. function my_fun(arg1 in number) return varchar2;
  4. end my_pkg;

PACKAGE BODY
===============
Expand|Select|Wrap|Line Numbers
  1. create or replace package body my_pkg as
  2.  
  3. function my_private_fun(arg1 in number) return varchar2
  4. is
  5. return_val varchar2(20);
  6. begin
  7. select col1 into return_val from tab2 where col2=arg1;
  8. return return_val;
  9. exception
  10. when NO_DATA_FOUND THEN
  11. return 'Sorry no data found.....!';
  12. end  my_private_fun;
  13.  
  14. function my_fun(arg1 in number)return varchar2
  15. is
  16. begin
  17. return my_private_fun(arg1);
  18. end my_fun;
  19.  
  20. procedure my_proc(arg1 in varchar2)
  21. is
  22. begin
  23. update tab1 set col1=col1+1 where col2=arg1;
  24. end my_proc;
  25. end my_pkg;
Note:----In this case the function my_private_fun is a local function in the function body which is not been defined in the package. So this function is local to the package, so it can be accessed from within the package only. It cant be referenced through the package name.

and in PL/SQL the procedures and function must be defined before it is being used. Other wise user will get compilation error.

package
==========
Expand|Select|Wrap|Line Numbers
  1. CREATE OR REPLACE PACKAGE PACK
  2. IS
  3. P_ENAME EMP.ENAME%TYPE;
  4. P_SAL EMP.SAL%TYPE;
  5. P_JOB EMP.JOB%TYPE;
  6. P_REC EMP%ROWTYPE;
  7. CURSOR C IS SELECT * FROM EMP;
  8. C_REC C%ROWTYPE;
  9. PROCEDURE DEPT_INS
  10. (
  11. D_DEPTNO DEPT.DEPTNO%TYPE,
  12. D_DNAME DEPT.DNAME%TYPE,
  13. D_LOC DEPT.LOC%TYPE
  14. );
  15. FUNCTION ANSAL(ENO EMP.EMPNO%TYPE)
  16. RETURN NUMBER;
  17. END;
  18.  
USE OF GLOBAL VARIABLES
-------------------------
Expand|Select|Wrap|Line Numbers
  1. BEGIN
  2. SELECT ENAME,SAL,JOB INTO PACK.P_ENAME,PACK.P_SAL,PACK.P_JOB FROM EMP WHERE EMPNO=&NO;
  3. DBMS_OUTPUT.PUT_LINE(PACK.P_ENAME||' '||PACK.P_SAL||' '||PACK.P_JOB);
  4. END;
  5.  
USE OF CURSOR
---------------------------------
Expand|Select|Wrap|Line Numbers
  1. BEGIN
  2. OPEN PACK.C;
  3. LOOP
  4. FETCH PACK.C INTO PACK.C_REC;
  5. EXIT WHEN PACK.C%NOTFOUND;
  6. DBMS_OUTPUT.PUT_LINE(PACK.C_REC.ENAME);
  7.  
  8. END LOOP;
  9. CLOSE PACK.C;
  10. END;
  11.  
----------------------------------
PACKAGE BODY
----------------------------------
Expand|Select|Wrap|Line Numbers
  1. CREATE OR REPLACE PACKAGE BODY PACK
  2. IS
  3.  
  4. PROCEDURE DEPT_INS
  5. (
  6. D_DEPTNO DEPT.DEPTNO%TYPE,
  7. D_DNAME DEPT.DNAME%TYPE,
  8. D_LOC DEPT.LOC%TYPE
  9. )
  10. IS 
  11. BEGIN
  12. INSERT INTO DEPT VALUES(D_DEPTNO,D_DNAME,D_LOC);
  13. DBMS_OUTPUT.PUT_LINE('1 RECORD INSERTED....');
  14. EXCEPTION
  15. WHEN DUP_VAL_ON_INDEX THEN
  16. DBMS_OUTPUT.PUT_LINE('DUPLICATE RECORD FOUND.....!');
  17. WHEN OTHERS THEN
  18. DBMS_OUTPUT.PUT_LINE('SOME OTHER ERROR......!');
  19. END DEPT_INS;
  20.  
  21. FUNCTION ANSAL
  22. (
  23. ENO EMP.EMPNO%TYPE
  24. )
  25. RETURN NUMBER
  26. AS
  27. SALARY NUMBER(8);
  28. BEGIN
  29. SELECT (SAL+NVL(COMM,0))*12 INTO SALARY FROM EMP WHERE EMPNO=ENO;
  30. RETURN SALARY;
  31. END ANSAL;
  32. END PACK;
  33.  
Jun 8 '07 #1
0 6264

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3355
by: cooldv | last post by:
i am running a website on Windows 2000 server with ASP 3 webpages and Access 2000 database. (with a hosting company) traffic is slow at this time but expect to grow. lately i have been reading about sql database and sql server, specially this article: http://www.aspfaq.com/show.asp?id=2195 will someone help me understand: 1. with *SQL Server*, do i keep my current Access 2000 database and ASP pages?
2
12665
by: Peter | last post by:
I run most of my SQL scripts via kornshell on AIX. I use the "here-document" to run some of the smaller ones. Example: #!/bin/ksh # Analyze the table. sqlplus ${SCHEMA_NM}/${SCHEMA_PASSWD}@${DB_NM} <<-ANALYZE_TABLE SET TERMOUT ON
0
10220
by: Jan | last post by:
I store sql-commands in a database table. In the first step I get the sql command out of the database table with embedded sql. In the second step I try to execute the command, which i got from the database table, using dynamic sql. Executing 'EXEC SQL DESCRIBE SELECT LIST FOR S INTO select_dp;' the error code -2149 is returned That means "Specified partition does not exist". Does anybody know if it is a database problem or a problem of
10
6744
by: Dagwood | last post by:
Good morning: At least it's morning where I am. :) I have a rather newbie question I'm afraid. I have VisualStudio.NET, and have installed it along with SQL server. However I can't seem to find an administration front-end to SQL, other than the VisualStudio, which is ok for creating databases and adding tables/columns. However when I go to generate create script, I'm told that I need client tools.
6
6787
by: Andreas Lauffer | last post by:
I changed from Access97 to AccessXP and I have immense performance problems. Details: - Access XP MDB with Jet 4.0 ( no ADP-Project ) - Linked Tables to SQL-Server 2000 over ODBC I used the SQL Profile to watch the T-SQL-Command which Access ( who creates the commands?) creates and noticed:
11
4273
by: Mark Yudkin | last post by:
The documentation is unclear (at least to me) on the permissibility of accessing DB2 (8.1.5) concurrently on and from Windows 2000 / XP / 2003, with separate transactions scope, from separate threads of a multithreaded program using embedded SQL. Since the threads do not need to share transaction scopes, the sqleAttachToCtx family of APIs do not seem to be necessary. <quote> In the default implementation of threaded applications against...
1
6647
by: Peter | last post by:
I've purchased VS.NET 2005 Standard and have tried to install SQL Server 2005 Express, but get the following error in the error log. Please could someone help me.... Microsoft SQL Server 2005 Express Edition x86: Component Microsoft SQL Server 2005 Express Edition x86 returned an unexpected value. ***EndOfSession***? Microsoft SQL Server 2005 Express Edition x86: Component Microsoft SQL Server 2005 Express Edition x86 returned an...
6
2508
by: Fuzzydave | last post by:
I am back developing futher our Python/CGI based web application run by a Postgres DB and as per usual I am having some issues. It Involves a lot of Legacy code. All the actual SQL Querys are stored in the .py files and run in the .cgi files. I have the problem that I need to construct a row from two seprate SQL Querys, I have tried combining the two Querys but all that does is create a Query that returns nothing after a long period...
14
3048
by: Developer | last post by:
Hello All, i have recently installed VS2005 and was trying to install SQL sever 2000. I have Win XP' SP2. But when I tried installing, it only installed client tools and not the database. Can anyone please help me with this as I want to install SQL server and also wouold be grateful, if you can suggest me any workaround to dealwith this problem.(Like should I install any new OS etc). Any help would be appreciated.
5
9291
by: dbrother | last post by:
Access 2003 Win XP Pro SP3 Using SQL /ADO Recordsets in a Do Loop Hello, I'm using a random number generator based on an integer input from a user from a form that will get X number of random records from an external Oracle source using a SQL statement. The SQL statement works as expected when the loop code is commented out, but I receive an error "SQL command not properly ended" when the loop is active. Do Until intLoop = UserNum ...
0
10555
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10317
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10300
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9127
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7607
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5503
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.