4.1 Functions Part 1

Video Activity
Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *
or

Already have an account? Sign In »

Time
7 hours 36 minutes
Difficulty
Beginner
CEU/CPE
3
Video Transcription
00:00
welcome to model for sequel programming to and this module. We're going to go a little deeper into the sequel program and go over some new concepts and then also mix in some of the older concepts with the newer concepts
00:14
and to start off. Where were We are moving into Lesson one sequel functions on The first question you probably have is what is a function, while a function is basically a section of code that serves a specific purpose now this code,
00:30
when you're using my Sequels included functions is abstracted out of your view.
00:35
That is, you don't have to worry about the code that's been written that produces that function. You just need to, ah, know that it works and trust that it works and then apply it where you need it in your own code. Further on in this lesson, we will actually write our own functions that we can use in our queries as well. But first off,
00:54
we're are going to start off with the functions that are included
00:57
in my sequel. We're gonna start off with some easy examples. We're gonna use a couple of variations of functions. We're not gonna go over every function because there are a lot of them. However, I will show you how to use some of the more common ones and some scenarios in which you might want to use them. So with that said, Let's go get Let's go ahead and get started.
01:17
We're actually going to be using the employees database
01:21
that we established on a previous lesson. So go ahead and write. Click that and set that to your active database. If it is not set to your active database and we're going to be working with the employees data table, and if we click on that, we look at the data in here. We'll see that we have a first name and a last name,
01:38
and we don't have a full name like we did in the other database
01:42
in the schematic a database. If you recall, they have the first and last name and then also a full name.
01:49
So let's go ahead and produce a query that creates a full name for us.
01:55
So we're going to select.
01:57
I don't know what I want that so I'm just gonna drop down to the front field from employees
02:04
and we don't need to make any restrictions here, so just go ahead and run. That what? First we need to say what Collins we want to say. See? And I'm gonna say everything, and I'm gonna indicate that with a star
02:15
and there is everything.
02:19
Now we're going to go ahead and just append to this square by putting a comma, and we're going to call the can cat function. And the comm can't function is a function that pens, strings or tax together.
02:35
So, for example, if we say
02:37
come cat,
02:38
that's the name of the function. This function takes two arguments. Now the arguments are separated with a comma. So, for example, if I put first name
02:52
is the first argument
02:54
and then last name only one comma
03:00
as the second argument, we will see a result that is a combination of these
03:06
two strings or tax added together. So
03:09
let me give it an alias as full name. Go ahead and name it.
03:15
Let's go in and run this.
03:17
I'm sure enough it can. Captain ate it. You can't meet him. Them together
03:23
Now we're gonna have Thio actually call this function twice when we use this on the actual data table to cat these two things together. Let me show you what I'm talking about. So we're gonna go ahead and switch this first name.
03:38
Actually, we're going to get rid of both East Fields and we're gonna do it. How? You will see in a lot of places. And that's last name. First name. So first, let's put in the last name
03:46
and we need to. Captain ate the
03:53
comma.
03:58
Once you've contaminated the Kama, let's go out and run that. Make sure that's still working
04:03
and we have the first or the last name with the common. So that's correct.
04:10
Now they can. Cat in my sequel does something really neat.
04:13
Not a lot of, ah programming languages let you do this. Sometimes it's set up this way and it's nice when it is. We can actually just add and other arguments we could say, Comma,
04:25
we can put in the
04:27
first name
04:30
and now we can run this
04:32
on. There we go. We have a full name last name, comma space, first name,
04:38
just like you put on the cat function. Now let's say you were in a scenario because I don't believe this works in every database where that wouldn't work, you couldn't just add on another argument. The function was set for two arguments. That's all you could use.
04:50
How would we could plead that? Would it would it now be impossible? Um, and the answer is no. It wouldn't be what we would do as we do actually call the cap function again.
05:01
We would treat this right here
05:03
as its own object or string off text, because that's what this turns into. Its kind of useful to think of it as data that is bubbling out. So when this query runs, it's going to run this part First. This part is going to become text. Then that is going to be passed into the outer one,
05:24
where it is then going to be inserted back into the function and called again.
05:29
So let's go ahead and put a comma and close off that function call,
05:33
and let's just, uh, let's go ahead and finish it off. We'll put in the first name again.
05:41
So we are opinion the comma here
05:46
in this function that's going to become text, and then once that text results, we're going to send it back into the cat function and attach the first name and we're gonna call. This column is full name. Now. We did accomplish step before by just adding another
06:00
argument into it. And my Sequels. Cat function allows you to do that, which is really neat feature. But this is how you would accomplish the same thing if you couldn't do that. Because it is common to find functions where you can't just add extra arguments.
06:14
So let's see if this works the same way.
06:16
And sure enough, it did. We got the full name. We used the cat function twice,
06:24
um, which, uh, gave us the full name field that we were looking for.
06:29
So this was a brief intro and two functions.
06:33
So I hope you got the king Can't function of working for you. And the next lesson will take a look at some other useful functions. And I hope to see you there. Thank you.
Up Next