-
Notifications
You must be signed in to change notification settings - Fork 0
/
Retrieve-all-the-information-about-each-department.html
379 lines (310 loc) · 14.4 KB
/
Retrieve-all-the-information-about-each-department.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
<!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="Discover how to gather all the details about different departments using PL/SQL on DarkSoul Git Blogs. Learn step-by-step methods for retrieving department information efficiently and effectively." />
<meta name="keywords" content="Retrieve all the information about each department using PL/SQL, solution to Retrieve all the information about each department using PL/SQL, 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>Retrieve all the information about each department using PL/SQL - 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;">Retrieve all the Information about each Department</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 12, 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/Retrieve all the information about each department.webp" alt="Retrieve all the information about each department - cover image" class="img-fluid rounded justify-content-center" style="margin: auto;">
</div>
<p>Create a PL/SQL block to retrieve all the information about each department from the DEPARTMENT table and display the information on the screen, incorporating a PL/SQL table of records.</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>DEPARTMENT_ID</td>
<td>NUMBER(5)</td>
<td>PK</td>
</tr>
<tr>
<td>DEPARTMENT_NAME</td>
<td>VARCHAR2(25)</td>
<td>NOT NULL</td>
</tr>
<tr>
<td>LOCATION_ID</td>
<td>VARCHAR2(15)</td>
<td></td>
</tr>
</tbody>
</table>
<h3>Sample Output: </h3>
<pre>
Department Details are :
1000, ADMIN, HQ-101
1010, DEVELOPMENT, CBE-103 10 DEVELOPMENT
1020, TESTING, CHN-102
</pre>
<strong>(Hint: Data is case sensitive. Use '/' to terminate the PL/SQL block)</strong>
<div class="col-md-12 mb-4" style="display: flex;">
<textarea disabled id="plsql">
SET SERVEROUTPUT ON;
DECLARE
depid DEPARTMENT.DEPARTMENT_ID%type;
depname DEPARTMENT.DEPARTMENT_NAME%type;
locid DEPARTMENT.LOCATION_ID%type;
CURSOR dept IS SELECT * FROM DEPARTMENT;
BEGIN
DBMS_OUTPUT.PUT_LINE('Department Details are :');
OPEN dept;
LOOP
FETCH dept INTO depid, depname, locid;
EXIT WHEN dept%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(depid || ', ' || depname || ', ' ||locid);
END LOOP;
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 what's happening in this PL/SQL code step by step: </p>
<p>
<b>Setting up:</b> The line SET SERVEROUTPUT ON; is like turning on a printer so that anything we ask the program to "print out" will actually show up.</p>
<p><b>Declaring variables:</b> Here, we're creating three variables: depid, depname, and locid, which will hold the values of department ID, department name, and location ID respectively. These variables are based on the data types of these columns in the DEPARTMENT table.
</p>
<p><b>Defining a cursor: </b>
Think of a cursor as a pointer or a tool that helps us go through the rows of a table one by one. Here, we're creating a cursor named dept that selects all columns from the DEPARTMENT table.
</p>
<p>
<b>Starting the program: </b> The BEGIN keyword marks the beginning of our actual PL/SQL program.</p>
<p><b>Printing a message: </b>
We're using DBMS_OUTPUT.PUT_LINE to print out the message "Department Details are :" to let the user know what kind of information they're about to see.
</p>
<p><b>Opening the cursor: </b>
OPEN dept; is like opening a door to start using our cursor. Now we can start fetching rows from the DEPARTMENT table.
</p>
<p><b>Looping through the rows: </b>
With LOOP, we're starting a loop that will continue until there are no more rows left in our cursor.
</p>
<p><b>Fetching a row: </b>
FETCH dept INTO depid, depname, locid; grabs the values of depid, depname, and locid from the current row that the cursor is pointing to and stores them in our variables.
</p>
<p><b>Checking for the end: </b>
EXIT WHEN dept%NOTFOUND; checks if we've reached the end of our cursor. If there are no more rows to fetch, the loop will stop.
</p>
<p><b>Printing the row: </b>
DBMS_OUTPUT.PUT_LINE(depid || ', ' || depname || ', ' ||locid); prints out the values we fetched from the current row, separated by commas.
</p>
<p><b>Ending the loop and program: </b>
Once we've gone through all the rows, the loop ends, and then the program ends with the /.
</p>
<p>In essence, this code fetches information about departments from a table one row at a time and prints out each row's details.</p>
<div class="pt-5">
<p>Categories: <a href="category-pl-sql.html">PL/SQL Hands-on</a> Tags: <a href="#">#Retrieve all the information about each department using PL/SQL</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>