Determining the length of strings
Determining the number of characters in a string is something that you will use frequently when working with data in a SQL database. Many situations will require you to find the length of a string stored in your database. For example, you may need to limit the number of characters that are displayed in an application or you may need to ensure that a column in your dataset contains values that are all the same length. In this example, we are going to determine the length of the description column in the film table of the DVD Rental database.
Latihan ini adalah bagian dari kursus
Functions for Manipulating Data in PostgreSQL
Petunjuk latihan
- Select the
titleanddescriptioncolumns from thefilmtable. - Find the number of characters in the
descriptioncolumn with the aliasdesc_len.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
SELECT
-- Select the title and description columns
___,
___,
-- Determine the length of the description column
___(___) AS ___
FROM film;