473,549 Members | 5,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PL/SQL-PROCEDURES - 2

debasisdas
8,127 Recognized Expert Expert
SAMPLE EXAMPLE TO SHOW USE OF PROCEDURE WITH IN MODE
=============== =============== =============== ========
Expand|Select|Wrap|Line Numbers
  1. CREATE OR REPLACE PROCEDURE REVNUM (NUM NUMBER)
  2.  IS
  3.  REV INTEGER;
  4.  NUM1 NUMBER;
  5.  BEGIN
  6.  NUM1:=NUM;
  7.  REV:=0;
  8.  WHILE NUM1>0
  9.  LOOP
  10.  REV:=REV * 10 + MOD(NUM1,10);
  11.  NUM1:=TRUNC(NUM1/10);
  12.  END LOOP;
  13.  DBMS_OUTPUT.PUT_LINE(REV);
  14.  END REVNUM;
  15.  
SAMPLE PROGRAM TO SHOW USE OF EXECUTE IMMEDIATE WITH IN PROCEDURE & PROCEDURE WITH DEFAULT PARAMETER.
=============== =============== =============== ========

Expand|Select|Wrap|Line Numbers
  1. CREATE OR REPLACE PROCEDURE delete_rows
  2. (
  3. table_name IN VARCHAR2,
  4. condition IN VARCHAR2 DEFAULT NULL
  5. )
  6. AS
  7. where_clause VARCHAR2(100) := ' WHERE ' || condition;
  8. BEGIN
  9. IF condition IS NULL THEN where_clause := NULL;
  10. END IF;
  11. --EXECUTE IMMEDIATE is used to dynamically execute any SQL statment at run time.
  12. EXECUTE IMMEDIATE 'DELETE FROM ' || table_name || where_clause;
  13. END;
  14.  

SAPMLE PROCEDURE WITH OUT PARAMETERS
=============== =============== =========
Expand|Select|Wrap|Line Numbers
  1. create or replace procedure display
  2. (
  3. eno in emp.empno%type,
  4. name out emp.ename%type,
  5. job out emp.job%type, 
  6. salary out emp.sal%type, 
  7. location out dept.loc%type
  8. )
  9. is
  10. begin
  11. --the values are selected into the out paramater.
  12. select ename,job,sal,loc into name,job,salary,location from emp e,dept d
  13. where e.deptno=d.deptno AND empno=eno;
  14. end;
  15.  
NOTE:----If a procedure contains any OUT or IN OUT parameter, it can't be executed from SQL prompt it must be called from with in an anonymous block.

To execute the above procedure.

Expand|Select|Wrap|Line Numbers
  1. declare
  2. name emp.ename%type;
  3. job emp.job%type;
  4. salary emp.sal%type;
  5. location dept.loc%type;
  6. begin
  7. --only the frist parameter accepts the value and the rest 4 returns after processing.
  8. display(7839,name,job,salary,location);
  9. dbms_output.put_line(name||'  '||job||'  '||salary||'  '||location);
  10. end;
  11.  

Also check PL/SQL-PROCEDURES - 3
May 30 '07 #1
0 3328

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

Similar topics

3
3340
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...
2
12645
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
10173
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...
2
15211
by: Ken Lindner | last post by:
I have a need to become familiar with SQL Server 2000 for work. Needless to say I am new to SQL Server any version, but not IT in general. My employer has provided me with the SQL Server 2000 Personal disk from the SQL Server 2000 Enterprise kit as this is reported here on the MSDN web site to be the version that is supported on Windows XP. ...
11
4232
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...
4
7293
by: coosa | last post by:
Hi, I was installing SQL Server on my machine and during installation my PC freezed. It happens frequently on my machine. So i tried after restarting to install it again and since then i always get the same error message: "An error occurred while creating one or more registry entries. Please see C:\WINDOWS\sqlstp.log for details. The...
1
6606
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...
6
2478
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...
14
3005
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...
5
9267
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...
0
7526
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7723
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. ...
0
7962
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...
0
6050
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...
1
5373
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...
0
5092
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3504
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...
1
1949
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
1
1063
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.