-
Notifications
You must be signed in to change notification settings - Fork 0
/
Write-a-PLSQL-function-to-concatenate-first-name-and-last-name.html
359 lines (298 loc) · 12.8 KB
/
Write-a-PLSQL-function-to-concatenate-first-name-and-last-name.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
<!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 write a PL/SQL function that effortlessly concatenates first names and last names. Follow this simple guide on DarkSoul Git Blogs for an easy and conversational step-by-step tutorial!" />
<meta name="keywords" content="Write a PL/SQL function to concatenate first name and last name, PL/SQL function to concatenate first name and last name of the employees, Create a Function to combine first name and last name of the employees 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>Write a PL/SQL function to concatenate first name and last name - 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;">Write a PL/SQL Function to Concatenate First Name and Last Name</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> - July 07, 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/Write a PLSQL function to concatenate first name and last name.webp" alt="Write a PLSQL function to concatenate first name and last name - cover image" class="img-fluid rounded justify-content-center" style="margin: auto;">
</div>
<p>Write a PL/SQL function to concatenate first name and last name of an employee. Pass employee id as an input to the function CONCAT_NAME.</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>FIRST_NAME</td>
<td>VARCHAR2(25)</td>
<td>NOT NULL</td>
</tr>
<tr>
<td>LAST_NAME</td>
<td>VARCHAR2(25)</td>
<td></td>
</tr>
<tr>
<td>DEPT</td>
<td>VARCHAR2(25)</td>
<td></td>
</tr>
</tbody>
</table>
<p>
<b>Functional Requirement:</b>
FUNCTION CONCAT_NAME(v_id employee.emp_id%type)
</p>
<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 FUNCTION CONCAT_NAME (v_id employee.emp_id%type)
RETURN VARCHAR2
IS
name VARCHAR2(50);
BEGIN
SELECT FIRST_NAME || LAST_NAME INTO name FROM EMPLOYEE WHERE EMPLOYEE.EMP_ID = v_id;
RETURN name;
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>
<h2>
Step-by-Step Guide to Creating a PL/SQL Function to Concatenate First and Last Names
</h2>
<p>
<b>Start with the Function Declaration:</b>
Begin by using the CREATE OR REPLACE FUNCTION statement to name your function, CONCAT_NAME. Specify one parameter: v_id (employee ID) as the input type from the EMPLOYEE table.
</p>
<p><b>Define the Return Type:</b>
Indicate that your function will return a string using the RETURN VARCHAR2 clause.
</p>
<p><b>Begin the Function Body:</b>
Use the IS keyword to start the function body.
</p>
<p><b>Declare a Variable:</b>
Inside the function, declare a variable name to hold the concatenated result. Use a VARCHAR2 with a length of 50.
</p>
<p><b>Implement the Logic:</b>
Inside the BEGIN and END; keywords, write the logic to concatenate the first and last names. Select FIRST_NAME and LAST_NAME from the EMPLOYEE table where EMP_ID matches the input v_id, and store the result in the name variable.
</p>
<p><b>Return the Result:</b>
Use the RETURN statement to output the concatenated name.
</p>
<p>
By following the steps above, you have successfully created a PL/SQL function, CONCAT_NAME, which concatenates an employee's first and last names based on a given employee ID. This efficient and reusable function can be integrated into larger PL/SQL programs to manage and display employee names with ease.
</p>
<div class="pt-5">
<p>Categories: <a href="category-pl-sql.html">PL/SQL Hands-on</a> Tags: <a href="#">#Write a PL/SQL function to concatenate first name and last name</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>