472,368 Members | 2,407 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 472,368 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 30531

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: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

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.