-
Notifications
You must be signed in to change notification settings - Fork 0
/
Insert-Employee-details-into-Employee-table.html
414 lines (340 loc) · 15.2 KB
/
Insert-Employee-details-into-Employee-table.html
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name='robots' content='index, follow, max-image-preview:large, max-snippet:-1, max-video-preview:-1' />
<meta name="referrer" content="strict-origin-when-cross-origin">
<meta name="author" content="DarkSoul">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
<meta name="description" content="Learn how to insert employee details into the Employee table with clear, step-by-step instructions on the DarkSoul-Git website. Access, copy, and learn from meticulously documented code to enhance your PL/SQL programming skills" />
<meta name="keywords" content="Insert Employee details into Employee table, Inserting Employee details into Employee table PL/SQL, Insert Employee details into Employee table using plsql, DarkSoul Git Blogs, PL/SQL, DarkSoul plsql" />
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Work+Sans:wght@400;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="fonts/icomoon/style.css">
<link rel="stylesheet" href="fonts/flaticon/font/flaticon.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.1/font/bootstrap-icons.css">
<link rel="stylesheet" href="css/aos.css">
<link rel="stylesheet" href="css/glightbox.min.css">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/flatpickr.min.css">
<title>Insert Employee details into Employee table - DarkSoul Git Blogs</title>
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Organization",
"url": "https://darksoul-git.github.io/",
"name": "DarkSoul - Best UI/UX Designs and blogs for better understanding",
"description": "DarkSoul, your number-one source for all things. We're dedicated to giving you the very best of designs and blogs with an emphasis on technical, graphical, and logical",
"logo": "https://darksoul-git.github.io/images/logo.png",
"sameAs": [
"https://codepen.io/DarkSoul-/",
"https://dribbble.com/DarkSoulinDribble/"
]
}
</script>
<style>
@font-face
{
font-family: "icomoon";
src: url("https://darksoul-git.github.io/fonts/icomoon/fonts/icomoon.ttf?");
font-display: swap;
}
h2, h3{
font-family: 'Ubuntu', sans-serif;
}
.content
{
font-family: "Work Sans", sans-serif !important;
text-align: justify;
color: black;
line-height: 1.6;
}
.content h3, .content h2
{
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}
h4
{
font-weight: bolder !important;
color: white !important;
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}
.date{ color: black !important;}
.blog-entry{color: black !important;}
textarea
{
margin-top: 55px;
margin-bottom: 15px;
margin-left: auto;
margin-right: auto;
resize: none;
font-size: large;
min-height: 400px;
width: 700px;
background-color: rgb(255, 255, 255);
border: 0.1px solid rgb(210, 210, 210);
border-radius: 8px;
box-shadow: 0px 0px 50px rgb(230, 230, 230);
font-weight: 500;
color: rgb(0, 0, 0);
}
/* width */
::-webkit-scrollbar
{
width: 5px;
}
/* Track */
::-webkit-scrollbar-track
{
background-color: rgba(226, 247, 255, 0);
}
/* Handle */
::-webkit-scrollbar-thumb
{
background: #adadad;
border-radius: 10px;
height: 10px;
width: 3px;
}
::selection
{
background-color: #202020;
color: white;
}
</style>
<script type="text/javascript">
(function(c,l,a,r,i,t,y){
c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
})(window, document, "clarity", "script", "iir3jmgyug");
</script>
<!-- Google tag (gtag.js)-->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-015RX6GMQJ"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-015RX6GMQJ');
</script>
</head>
<body>
<!-- Mobile Navigation Bar -->
<div class="site-mobile-menu site-navbar-target" id="mobilenav">
</div>
<!-- Desktop Navigation Bar -->
<nav class="site-nav bg-dark" id="header">
</nav>
<div class="site-cover site-cover-sm same-height overlay single-page bg-dark">
<div class="container">
<div class="row same-height justify-content-center">
<div class="col-md-6" >
<div class="post-entry text-left" >
<h1 class="mb-4" style="font-weight: 800;">Insert Employee details into Employee table</h1>
<div class="post-meta align-items-center text-left">
<figure class="author-figure mb-0 me-3 d-inline-block"><img src="favicon.ico" alt="Image" class="img-fluid" width="640" height="360"></figure>
<span class="d-inline-block mt-1">By DarkSoul</span>
<span> - May 31, 2024</span>
</div>
</div>
</div>
</div>
</div>
</div>
<section class="section">
<div class="container">
<div class="row blog-entries element-animate">
<div class="main-content">
<div class="post-content-body content">
<div class="col-md-12 mb-4" style="display: flex;">
<img src="images/Insert-Employee-details-into-Employee-table.webp" alt="Insert-Employee-details-into-Employee-table - cover image" class="img-fluid rounded justify-content-center" style="margin: auto;">
</div>
<p>Create a PL/SQL Procedure to insert employee details into Employee table. Before inserting, check whether the employee age is eligible or not. Employee age should be 18 or greater. Values are passed as argument to the procedure.
If age valid, insert employee record into table and print the message "Age valid - Record inserted", else print the message "Age invalid - Record not inserted" by raising an exception.</p>
<p>Table: EMPLOYEE</p>
<table class="table table-hover table-dark table-striped mt-4 mb-4" style="max-width: 400px;">
<thead>
<tr>
<th>COLUMN</th>
<th>DATATYPE</th>
<th>CONS.</th>
</tr>
</thead>
<tbody>
<tr>
<td>EMPID</td>
<td>NUMBER(5)</td>
<td>PK</td>
</tr>
<tr>
<td>EMPNAME</td>
<td>VARCHAR2(25)</td>
<td>NOT NULL</td>
</tr>
<tr>
<td>AGE</td>
<td>NUMBER(3)</td>
<td></td>
</tr>
</tbody>
</table>
<pre>
Sample Input 1:
CHECK_AGE_ELIGIBILITY(103, 'Robert', 24);
Sample Output 1:
Age valid - Record inserted
Sample Input 2:
CHECK_AGE_ELIGIBILITY(104,'Riya', 4);
Sample Output 2:
Age invalid - Record not inserted
</pre>
<strong>(Hint: Data is case sensitive. Use '/' to terminate the PLSQL block)</strong>
<div class="col-md-12 mb-4" style="display: flex;">
<textarea disabled id="plsql">
CREATE OR REPLACE PROCEDURE check_age_eligibility
(v_id in employee.empid%type,
v_name in employee.empname%type,
v_age in employee.age%type)
AS
Not_ValidException exception;
BEGIN
IF v_age > 18 THEN
INSERT INTO employee VALUES(v_id, v_name, v_age);
DBMS_OUTPUT.PUT_LINE('Age valid - Record inserted');
ELSE
RAISE Not_ValidException;
END IF;
EXCEPTION
WHEN Not_ValidException THEN
DBMS_OUTPUT.PUT_LINE('Age invalid Record not inserted');
END;
/
</textarea>
</div>
<div class="col-md-12 mb-4" style="display: flex;">
<button id="button" class="btn btn-outline-dark m-auto" style="width: fit-content; height: fit-content;" onclick="copy()">Copy</button>
</div>
<script>
var textarea = document.getElementById('plsql');
var button = document.getElementById('button');
function copy() {
textarea.select();
navigator.clipboard.writeText(textarea.value);
button.innerHTML = 'COPIED!';
}
</script>
<p>
Let's break down the procedure step-by-step in a simple understandable way:
</p>
<p>
<b>Procedure Declaration:
</b>
<ul>
<li>The procedure is named check_age_eligibility.</li>
<li> It accepts three input parameters: v_id, v_name, and v_age.</li>
<li>These parameters correspond to the employee's ID, name, and age, respectively.</li>
</ul>
</p>
<p><b>Parameter Types:</b>
<ul>
<li>The types of these parameters (employee.empid%type, employee.empname%type, employee.age%type) are derived from the employee table columns. This ensures the parameters match the data types of the respective table columns.</li>
</ul>
</p>
<p><b>Exception Declaration:
</b>
<ul>
<li>An exception named Not_ValidException is declared. This will be used to handle cases where the age is not valid (i.e., 18 or younger).</li>
</ul>
</p>
<p> <b>Begin Block:</b>
<ul>
<li>The main logic of the procedure starts here.</li>
</ul>
</p>
<p><b>Age Check:
</b>
<ul>
<li>The procedure checks if the input age (v_age) is greater than 18.</li>
<li>If v_age is greater than 18, it proceeds to insert the employee details into the employee table.</li>
</ul>
</p>
<p><b>Insert Statement:</b>
<ul>
<li>The INSERT INTO employee VALUES(v_id, v_name, v_age); statement adds the new employee record to the table.
</li>
<li>A message is displayed using DBMS_OUTPUT.PUT_LINE('Age valid - Record inserted'); indicating that the age is valid and the record has been inserted successfully.</li>
</ul>
</p>
<p><b>Exception Handling:</b>
<ul>
<li>If the age is not greater than 18, the procedure raises the Not_ValidException.
In the EXCEPTION block, when the Not_ValidException is caught, a message is displayed using DBMS_OUTPUT.PUT_LINE('Age invalid - Record not inserted'); indicating that the age is invalid and the record was not inserted.
</li>
</ul>
</p>
<p><b>End Block:</b>
<ul>
<li> The procedure ends here. </li>
</ul>
</p>
<p>
This procedure checks an employee's age before inserting their details into the employee table. If the age is greater than 18, the details are inserted, and a confirmation message is displayed. If the age is 18 or less, an exception is raised, and a message indicating the invalid age is displayed. </p>
<div class="pt-5">
<p>Categories: <a href="category-pl-sql.html">PL/SQL Hands-on</a> Tags: <a href="#">#Insert Employee details into Employee table</a>, <a href="#">#PL/SQL</a></p>
</div>
<div class="comment-form-wrap pt-5">
<h3 class="mb-5" style="color: black;">Leave a comment</h3>
<form action="https://docs.google.com/forms/d/e/1FAIpQLSfy_pkp3cVBSPDNpS27p2F_zKnwC6O1dNXrFTscjn_XxITQ-w/formResponse" class="p-5 bg-light">
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" id="name" name="entry.505217379" required autocomplete="on">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" id="email" name="entry.1718450961" required autocomplete="on">
</div>
<div class="form-group">
<label for="subject">Subject</label>
<input type="text" class="form-control" id="subject" name="entry.390459327" required autocomplete="on">
</div>
<div class="form-group">
<label for="message">Message</label>
<textarea name="entry.117980495" id="message" cols="30" rows="10" class="form-control" required autocomplete="on"></textarea>
</div>
<div class="form-group">
<input type="submit" value="Post Comment" class="btn btn-outline-dark">
</div>
</form>
</div>
</div>
</div>
<!-- END main-content -->
</div>
</div>
</section>
<!-- /.site-footer -->
<footer class="site-footer bg-dark" id="footer">
</footer>
<!-- Preloader -->
<div id="overlayer"></div>
<div class="loader">
<div class="spinner-border text-primary" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>
<script async src="js/header.js"></script>
<script async src="js/footer.js"></script>
<script src="js/bootstrap.bundle.min.js"></script>
<script src="js/flatpickr.min.js"></script>
<script src="js/aos.js"></script>
<script src="js/glightbox.min.js"></script>
<script src="js/navbar.js"></script>
<script src="js/counter.js"></script>
<script src="js/custom.js"></script>
</body>
</html>