1 00:00:00,090 --> 00:00:03,490 Next up, we have care length or cha length. 2 00:00:03,510 --> 00:00:06,990 It's going to tell us the number of characters in a given string. 3 00:00:07,350 --> 00:00:13,590 So if I did something like Car cha length Hello World, it's going to tell me one, two, three, four, 4 00:00:13,590 --> 00:00:17,060 five, six, seven, eight, nine, ten, 11. 5 00:00:17,070 --> 00:00:18,470 And that's what the slide says. 6 00:00:18,480 --> 00:00:20,820 We can trust it or we can just try it ourselves. 7 00:00:20,970 --> 00:00:30,690 Select cha length from and then let's just do hey, exclamation point and we get four. 8 00:00:31,020 --> 00:00:35,610 Now, something that can be confusing is that there's another function, a string function called No, 9 00:00:35,610 --> 00:00:36,430 not left. 10 00:00:36,450 --> 00:00:43,110 Length and length will return the length of a string as well, measured in bytes. 11 00:00:43,260 --> 00:00:50,220 So it might appear the same if I did just regular length of hey, we get four. 12 00:00:50,220 --> 00:00:54,450 And that's because each character here can be stored in a single byte. 13 00:00:54,450 --> 00:00:57,930 But that's not the case with something like this. 14 00:00:57,930 --> 00:01:04,560 This is, I believe, from Chinese characters for Dolphin, and it looks like it's two characters, 15 00:01:04,560 --> 00:01:08,670 but those characters take up more, more storage essentially. 16 00:01:08,760 --> 00:01:10,680 So it's actually six bytes. 17 00:01:11,580 --> 00:01:15,600 And if I really wanted to know the character length, I would use char length. 18 00:01:15,600 --> 00:01:17,850 And it's exactly two characters. 19 00:01:17,850 --> 00:01:19,290 So there is a difference. 20 00:01:19,290 --> 00:01:23,550 Not always, but there is an important distinction between those two functions. 21 00:01:23,550 --> 00:01:28,290 Even if a lot of the time with simple characters, we'll get the same result. 22 00:01:28,530 --> 00:01:30,480 That is not always the case. 23 00:01:30,480 --> 00:01:33,330 Length is going to return a value in bytes. 24 00:01:33,330 --> 00:01:39,030 Char length tells us the number of characters doesn't care about bytes, just characters. 25 00:01:39,030 --> 00:01:50,070 So let's let's find out the character length of the titles in our database, select char length title 26 00:01:50,070 --> 00:01:51,630 from books. 27 00:01:52,290 --> 00:01:57,900 And let's also put well, let's put the book title there as well. 28 00:01:57,900 --> 00:02:04,860 So let's do comma title from books and the clear longest one, just looking at this is what we talk 29 00:02:04,860 --> 00:02:08,400 about when we talk about love stories, but there's still some other long ones, right? 30 00:02:08,400 --> 00:02:13,830 A heartbreaking work of Staggering Genius, The Amazing Adventures of Kavalier and Clay, where I'm 31 00:02:13,830 --> 00:02:17,190 calling from Selected Stories doesn't really matter, right? 32 00:02:17,190 --> 00:02:23,370 The point is that we can find the number of characters in some column for every row. 33 00:02:23,370 --> 00:02:26,280 So in this case it was title that we're working with. 34 00:02:26,280 --> 00:02:31,530 And just like any of these other functions we've been working with, we can alias this. 35 00:02:31,530 --> 00:02:37,830 I could call this as Len if I wanted it to be Len That's the length of the title, or I could call it 36 00:02:37,830 --> 00:02:40,860 title length or title chars or something like that. 37 00:02:40,860 --> 00:02:42,390 But I think that's enough. 38 00:02:42,780 --> 00:02:48,150 It's a simple enough one chart length again gives us the characters in whatever we provide. 39 00:02:48,150 --> 00:02:50,310 Length gives us the bytes.