473,320 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,320 developers and data experts.

PL/SQL-PROCEDURES - 2

debasisdas
8,127 Expert 4TB
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 3317

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

Similar topics

3
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...
2
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...
0
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...
2
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...
11
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...
4
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...
1
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...
6
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...
14
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...
5
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.