sql · level 1 · unit 4 · lesson 4
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
Glue text with and change it with functions.
|| glues values together. name || ' the ' || species turns Rex and dog into Rex the dog. Spaces only appear if you put them inside the quotes.
A is a named command. You give it a value in brackets and it hands back a new one. UPPER(name) gives the name in capitals.
LOWER() gives small letters, and LENGTH() counts the letters. Give the result a name with AS, or the top line shows the whole thing.
SELECT name || ' the ' || species AS pet FROM pets; Functions work inside WHERE too, like WHERE LENGTH(name) > 4.
guess first
Mind the gap. What will this show?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
SELECT name || species AS pet FROM pets WHERE age = 3;
your turn
Your turn. Change the pet names.
Type UPPER, LOWER or LENGTH in the blank, then press run. Try all three and compare the results.
result
Your answer appears here as a table.
fix it
The dogs want treats, but this crashes. Fix it!
result
Your answer appears here as a table.
- Read the error. The database thinks treats is a column. Why might that be?
- Text needs single quotes, even when you glue it on with
||. - Put quotes round treats, so it reads 'treats', then press run.
nailed it
you glued and changed text. :D
||glues values together into one piece of text.- A function takes a value in brackets and hands back a new one.
UPPER,LOWERandLENGTHchange or measure text.
new words in your collection
- ||
- function
This lesson isn’t saved. A free account remembers every lesson you finish.