0% found this document useful (0 votes)
17 views

Practise of PLSQL

Practice sql

Uploaded by

59mansikangs4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Practise of PLSQL

Practice sql

Uploaded by

59mansikangs4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Q1.

SQL> declare

2 n number := &n;

3 begin

4 for i in 1..10 loop

5 dbms_output.put_line(n||' * '||i||' = '||n*i);

6 end loop;

7 end;

8 /

Enter value for n: 2

old 2: n number := &n;

new 2: n number := 2;

2*1=2

2*2=4

2*3=6

2*4=8

2 * 5 = 10

2 * 6 = 12

2 * 7 = 14

2 * 8 = 16

2 * 9 = 18

2 * 10 = 20

PL/SQL procedure successfully completed.

Q2.

1 declare

2 n1 number(2) := &n1;

3 n2 number(2) := &n2;

4 begin

5 dbms_output.put_line('sum = '||to_char(n1+n2));
6 dbms_output.put_line('difference = '||to_char(n1-n2));

7 dbms_output.put_line('product = '||to_char(n1*n2));

8* end;

SQL> /

Enter value for n1: 20

old 2: n1 number(2) := &n1;

new 2: n1 number(2) := 20;

Enter value for n2: 15

old 3: n2 number(2) := &n2;

new 3: n2 number(2) := 15;

sum = 35

difference = 5

product = 300

PL/SQL procedure successfully completed.

SQL> /

Enter value for n1: 30

old 2: n1 number(2) := &n1;

new 2: n1 number(2) := 30;

Enter value for n2: 40

old 3: n2 number(2) := &n2;

new 3: n2 number(2) := 40;

sum = 70

difference = -10

product = 1200

PL/SQL procedure successfully completed.

Q3

1 declare
2 s1 varchar2(30) := '&s1';

3 s2 varchar2(30) := '&s2';

4 begin

5 dbms_output.put_line(s1);

6 dbms_output.put_line(s2);

7 dbms_output.put_line(s1||s2);

8* end;

SQL> /

Enter value for s1: hello world

old 2: s1 varchar2(30) := '&s1';

new 2: s1 varchar2(30) := 'hello world';

Enter value for s2: my name

old 3: s2 varchar2(30) := '&s2';

new 3: s2 varchar2(30) := 'my name';

hello world

my name

hello worldmy name

PL/SQL procedure successfully completed.

Q4:

1 declare

2 a1 number(2) := &a1;

3 a2 number(2) := &a2;

4 a3 number(2) := &a3;

5 begin

6 if (a1>a2 and a1>a3) then

7 dbms_output.put_line('a1 is greatest');

8 elsif(a2>a1 and a2>a3) then

9 dbms_output.put_line(' a2 is the greatest');

10 else
11 dbms_output.put_line('a3 is the greatest');

12 end if;

13* end;

SQL> /

Enter value for a1: 12

old 2: a1 number(2) := &a1;

new 2: a1 number(2) := 12;

Enter value for a2: 34

old 3: a2 number(2) := &a2;

new 3: a2 number(2) := 34;

Enter value for a3: 9

old 4: a3 number(2) := &a3;

new 4: a3 number(2) := 9;

a2 is the greatest

PL/SQL procedure successfully completed.

q-5
SQL> declare

2 n number(2);

3 begin

4 for n in 1..30 loop

5 if(n mod 2 = 0) then

6 dbms_output.put_line(n);

7 end if;

8 end loop;

9 end;

10 /

6
8

10

12

14

16

18

20

22

24

26

28

30

PL/SQL procedure successfully completed.

q-6
SQL> declare

2 n number(2);

3 begin

4 for n in 1..30 loop

5 if(n mod 2 != 0) then

6 dbms_output.put_line(n);

7 end if;

8 end loop;

9 end;

10 /

9
11

13

15

17

19

21

23

25

27

29

PL/SQL procedure successfully completed.

q-7
Wrote file afiedt.buf

1 declare

2 n number(2) := &n;

3 sum1 number(3) := 0;

4 begin

5 for i in 1..n loop

6 sum1 := sum1 + i;

7 end loop;

8 dbms_output.put_line('summation is'||to_char(sum1));

9* end;

10 /

Enter value for n: 6

old 2: n number(2) := &n;


new 2: n number(2) := 6;

summation is21

q-8

1 declare

2 fac number(3) :=1;

3 n number (3) := &n;

4 begin

5 while n>0 loop

6 fac := n*fac;

7 n :=n-1;

8 end loop;

9 dbms_output.put_line ('factorial of number is' || fac);

10* end;

SQL> /

Enter value for n: 4

old 3: n number (3) := &n;

new 3: n number (3) := 4;

factorial of number is24

PL/SQL procedure successfully completed.


q-9:

SQL> declare

2 n number (3) := &n;

3 begin

4 while n>0 loop

5 dbms_output.put_line('reverse is'||n);

6 n := n-1;

7 end loop;

8 end;

9 /

Enter value for n: 7

old 2: n number (3) := &n;

new 2: n number (3) := 7;

reverse is7

reverse is6

reverse is5

reverse is4

reverse is3

reverse is2

reverse is1

PL/SQL procedure successfully completed.

Q10:

1 declare

2 v_id employees.employee_id%type;

3 v_sal employees.salary%type;

4 begin

5 select employee_id, salary into v_id, v_sal from employees where employee_id = &d;

6 dbms_output.put_line('employee id is' || v_id);


7 dbms_output.put_line('sal is '|| v_sal);

8* end;

SQL> /

Enter value for d: 150

old 5: select employee_id, salary into v_id, v_sal from employees where employee_id = &d;

new 5: select employee_id, salary into v_id, v_sal from employees where employee_id = 150;

employee id is150

sal is 10000

PL/SQL procedure successfully completed.

q-11

1 declare

2 v_id employees.employee_id%type;

3 v_job employees.job_id%type;

4 begin

5 select employee_id, job_id into v_id, v_job from employees where employee_id = &d;

6 dbms_output.put_line('employee id is' || v_id);

7 dbms_output.put_line('job id is '|| v_job);

8* end;

SQL> /

Enter value for d: 150

old 5: select employee_id, job_id into v_id, v_job from employees where employee_id = &d;

new 5: select employee_id, job_id into v_id, v_job from employees where employee_id = 150;

employee id is150

job id is SA_REP

PL/SQL procedure successfully completed .


q-12
1 declare
2 v_id employees.employee_id%type;
3 v_dep employees.department_id%type;
4 begin
5 select count(employee_id), department_id into v_id, v_dep from
employees group by department_id having department_id = &d;
6 dbms_output.put_line('department id is '|| v_dep);
7 dbms_output.put_line('count is' || v_id);
8* end;
SQL> /
Enter value for d: 50
old 5: select count(employee_id), department_id into v_id, v_dep from
employees group by departmen
new 5: select count(employee_id), department_id into v_id, v_dep from
employees group by departmen
department id is 50
count is45

PL/SQL procedure successfully completed.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy