Join Bill Weinman for an in-depth discussion in this video Finding the type of a value, part of SQL Essential Training (2014).
Most database systems allow expressions on values of different types. When they do the type of the result will depend on the rules the system uses for converting the values used in the expression. In some cases, you may need to know that type of the result. For this lesson, we're going to use the in memory database. And I'm going to start by adding an expression. So, this expression simply adds two numbers together and gives you the result. In this case both of the numbers in the expression are integer values.
If I instead make one of these a real number by putting a .0 after it. It still has the same value, but now it's represented as a real number, instead of an integer. And when we get the result, you'll notice that the result now has a .0 at the end, which indicates that this is also a real number. And if I use the TYPEOF function, And we'll go back to just the integers here. We'll see that the type of this expression is an integer. And it says integer there.
The type of function is specific to SQL lite, but most database management systems have a way of finding the type of an expression. And should you ever need to do that you'll need to look it up in your documentation for your data base management system. What's interesting here is that when I add a .0 to this second operand you'll notice that the type of the entire expression is now real instead of integer. If I replace all this with a string, you notice that the type now says text.
And if I add one string to another, you notice that the type is now again integer, because the operator, the plus sign, in SQL light is simply numeric addition. It can be used for integers or or And so these have each been. Converted to an integer with a value of 0. And, now the type of the expression is integer. Well, that's good to know. Some systems use the plus sign to concatenate strings, and others like this one will simply convert the strings to integer 0's, and try and add them together.
It can be very important to understand how your system performs type conversions. And if your system has a simple type of function, you can use it for that purpose. Not all systems support the type of function. Some systems have a similar function by a different name, or some other method of finding the type of an expression. You'll need to consult the documentation for your system to find the equivalent functionality.
- Understanding SQL terminology and syntax
- Creating new tables and records
- Inserting and updating data
- Writing basic SQL queries
- Sorting and filtering
- Accessing related tables with JOIN
- Working with strings
- Finding the numeric type of a value
- Using aggregate functions and transactions
- Updating a table with triggers
- Creating views
Skill Level Beginner
Q: For Mac OS X: When I try to start the Apache Web Server from the XAMPP control panel, it doesn't start, and when I open "localhost" in my web browser, I see a white screen that says "It Works!" instead of the XAMPP page.
sudo apachectl stop
Q: I'm on a Mac, and I get an error in SID that says "attempt to write a read only database." How can I fix this?
A: This usually means that the database folder does not have sufficient permissions for writing by the web user. This can happen if you create the SQL folder new, rather than copying it from the Exercise Files. Here's how to fix this:
- Open a Finder window and Navigate to /Applications/XAMPP/htdocs/SQL
- Control-click on the SQL folder and select "Get Info" from the context menu.
- Under "Sharing and Permissions" (you may need to open the disclosure triangle), in the "everyone" row, select "Read & Write."Then you can close the Info window.
- Now repeat the process for the three *.db files inside the folder.