This repository has been archived by the owner on Oct 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Procedures&Functions.txt
198 lines (109 loc) · 3.89 KB
/
Procedures&Functions.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
1) Write a PL/SQL procedure to print the Armstrong number.
create or replace procedure armstrong as
n number := &no;
s number := 0;
r number ;
len number ;
m number ;
begin
m := n;
len := length(to_char(n)) ;
while n > 0
loop
r: = mod(n,10)
s: = s + power(r,len);
n: = trunc(n/10);
end loop;
if m = s then
dbms_output.put_line('YES');
else
dbms_output.put_line('NO') ;
end if ;
end ;
/
Enter value for no: 153
SQL> execute armstrong;
YES
PL/SQL procedure successfully completed.
2) Write a PL/SQL code to reverse a given number.
declare
n number := &no;
rev number := 0;
last_digit number ;
begin
n := &n;
while n > 0
loop
last_digit : = mod(n,10)
rev : = (rev * 10) + last_digit;
n: = trunc(n/10);
end loop;
dbms_output.put_line('Reverse Is '||rev);
end ;
/
Enter value for no: 1234
Reverse Is 4321
PL/SQL procedure successfully completed.
3) Write a PL/SQL function to reverse a given string.
create or replace function reverse(str varchar2)
return varchar2 is
rev_string varchar2(50);
len number;
begin
len := length(str) ;
for i in reverse 1.... len loop
rev_string := rev_string || substr(str,i,1);
end loop;
return rev_string;
end ;
/
Function created.
DECLARE
rev_string varchar2(50);
BEGIN
rev_string := reverse('&string') ;
dbms_output.put_line(rev_string);
END;
Enter value for string: hello
olleh
PL/SQL procedure successfully completed.
4) Write a PL/SQL code to raise the salary of employee by 10% where their designation is ‘Assistant Professor’.
begin
update employee set salary = salary + (salary * 0.1) where desig = 'Assistant Professor';
end ;
PL/SQL procedure successfully completed.
5) Create a package to perform insert and delete operation on to the employee table.
create or replace package id_package as
procedure insertion(enamee.name%type,sale.salary%type,e_ide.eid%type,e_desige.designation%type);
procedure deletion(e_ide.eid%type);
end id_package ;
create or replace package body id_package as
procedure insertion(enamee.name%type,sale.salary%type,e_ide.eid%type,e_desige.designation%type) is
begin
insert into e values(ename,sal,e_id,e_desig);
end insertion;
procedure deletion(e_ide.eid%type) is
begin
delete e where e_id = eid ;
end deletion;
end id_package ;
begin
id_package.insertion('&name','&salary',&eid,'&designation');
id_package.deletion(&eid);
end;
Package created.
Package body created.
PL/SQL procedure successfully completed.
6) Write a PL/SQL procedure to check whether the eno=1001 exist. If it is not raise an exception.
create or replace procedure record_check as
emp_no number
begin
select empno into emp_no from employee where empno = 1001 ;
dbms_outputput_line('RECORD FOUND');
exception
when no_data_found then
dbms_outputput_line('RECORD NOT FOUND');
end;
SQL> execute record_check;
RECORD NOT FOUND
PL/SQL procedure successfully completed.