473,320 Members | 2,133 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.

Oracle PL/SQL 9i/10g - Sample Programs

debasisdas
8,127 Expert 4TB
Sample PL/SQL programs
=====================

To print EVEN numbers 1--100

Expand|Select|Wrap|Line Numbers
  1. BEGIN
  2. FOR I IN  1..100 LOOP
  3. --if the number is divisible by 2 then it is a even number.
  4. IF MOD(I,2)=0 THEN 
  5. --display the number.
  6. dbms_output.put_line(I);
  7. END IF;
  8. END LOOP;
  9. END;
  10.  
Sample program to REVERSE A NUMBER

Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2. MNUM INTEGER;
  3. MREV  INTEGER:=0;
  4. BEGIN
  5. MNUM:=&MNUM;
  6. WHILE(MNUM>0) LOOP
  7. MREV:=MREV*10 +MOD(MNUM,10);
  8. MNUM:=TRUNC(MNUM/10);
  9. END LOOP;
  10. DBMS_OUTPUT.PUT_LINE('THE REVERSE IS: '||MREV);
  11. END;
  12.  
Sample program showing use of XOR (Exclusive OR )

Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2. I BOOLEAN:=FALSE;
  3. J BOOLEAN:=FALSE;
  4. K BOOLEAN;
  5. BEGIN
  6. K:=XOR(I,J);
  7. IF K=TRUE THEN
  8. DBMS_OUTPUT.PUT_LINE('TRUE');
  9. ELSE
  10. DBMS_OUTPUT.PUT_LINE('FALSE');
  11. END IF;
  12. END;
  13.  
Sample program showing use of EXECUTE IMMEDIATE

Expand|Select|Wrap|Line Numbers
  1. declare
  2. tablename varchar2(100):='&tablename';
  3. rows_deleted number;
  4. str varchar2(30);
  5. begin
  6. str := 'delete  from ';
  7. str :=str||tablename;
  8. execute immediate str;
  9. rows_deleted:=sql%rowcount;
  10. dbms_output.put_line(to_char(rows_deleted));
  11. end;
  12.  
Sample program to REVERSE A STRING

Expand|Select|Wrap|Line Numbers
  1. declare
  2. i varchar2(20):='&i';
  3. j varchar2(20);
  4. k int;
  5. l int;
  6. begin
  7. k:=length(i);
  8. for l in reverse 1..k loop
  9. j:=j||substr(i,l,1);
  10. end loop;
  11. dbms_output.put_line(j);
  12. end;
  13.  
SAMPLE PROGRAM TO PRINT ARMSTRONG NUMBER

Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2. A NUMBER;
  3. B NUMBER;
  4. BEGIN
  5. FOR I IN 1..500 LOOP
  6. A:=I; 
  7. B:=0;
  8. LOOP
  9. EXIT WHEN A<=0;
  10. B:=B+POWER(MOD(A,10),3);
  11. A:=TRUNC(A/10);
  12. END LOOP;
  13. IF B=I THEN
  14. DBMS_OUTPUT.PUT_LINE(I||' IS ARMSTRONG NUMBER');
  15. END IF;
  16. END LOOP;
  17. END;
  18.  
SOME SAMPLE CODE

Expand|Select|Wrap|Line Numbers
  1. declare type nn is table of number index by pls_integer;
  2.  mm nn;
  3.  n number:=1;
  4.  s number:=1;
  5.  begin
  6.  for rec in (select empno from emp) loop
  7.  mm(n):=rec.empno;
  8.  n:=n+1;
  9.  end loop;
  10.  while s<n loop
  11.  dbms_output.put_line(mm(s));
  12.  s:=s+1;
  13.  end loop;
  14.  end ;
  15.  
May 10 '07 #1
0 30591

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

Similar topics

1
by: pleake | last post by:
Following is a logon.asp script. This script works when IIS is reset each day. The epapi object is a vendor api program I do not have the code for! The logon process involves three servers: ...
0
by: daisy | last post by:
To empower your .NET applications with the Oracle Database, download Oracle Data Provider for .NET (ODP.NET) from : http://otn.oracle.com/tech/windows/odpnet/index.html Try out the new features...
28
by: prunoki | last post by:
Hello, I am an SQL server newbie. Our company has a massive application written in PL/SQL. I need to port parts of it to SQL Server. - Which SQL server version should I choose, to have a...
0
by: Daisy | last post by:
Download Oracle Data Provider for .NET (http://otn.oracle.com/tech/windows/odpnet/index.html) today to empower your .NET applications with the Oracle Database! Try out the new features for XML...
0
by: Daisy | last post by:
To empower your .NET web services with the Oracle Database, download Oracle Data Provider for .NET (ODP.NET) from : http://otn.oracle.com/tech/windows/odpnet/index.html Try out the new features...
1
by: ramesh.teja | last post by:
Hi, Vennela Technologies is a Global Oracle Technologies and Oracle Applications services Provider with a good customer base in Middle East and Europe Vennela started its Training division very...
13
by: BigDaDDY | last post by:
Um yeah....In case you haven't figured it out, Microsoft sucks. I'm going to be kicked back in my chair eating popcorn and watching football 10 years from now, while all you clowns are scrambling...
11
by: Rosco | last post by:
Does anyone have a good URL or info whre Oracle and Access are compared to one another in performance, security, cost etc. Before you jump on me I know Oracle is a Cadillac compared to Access the...
0
by: totierne | last post by:
comp.databases.ms-access, I want to know how to use Oracle views with session variables in Access. The parameterised views in access, are migrated to views with per session variables. The...
10
by: www.hitechskill.com | last post by:
HiTechSkill.Com offers free information, tests, and sample interview questions that will help to improve your information technology skills. http://www.hitechskill.com
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
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)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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.