Brightlane's catalog validation rule checks that product codes do not exceed 12 characters.
Write a query to return the character count of the product code 'SKU-4821-B-XL'.
Output:
- A single row with one column,
code_length, containing the count as a number.
Schema · ecommerce 5 tables
Run previews · Check grades
Write a query, then run it to see results here.
Worked solution Try it yourself first
SELECT
LENGTH('SKU-4821-B-XL') AS code_length The shape
LENGTH('SKU-4821-B-XL') returns the integer 13, the character count of the product code. The validation rule caps codes at 12, so this value being one over the cap is the signal the catalog check is built around.
Clause by clause
SELECT LENGTH('SKU-4821-B-XL') AS code_lengthmeasures the literal and returns the count as a single integer column.LENGTHcounts characters, not bytes: every letter, digit, and hyphen in the code contributes one to the total, which adds up to13.- There is no
FROMbecause the input is a literal embedded in the query. The function takes one string and returns one number; nothing else needs to be in scope.
Why this and not measuring against the cap inline
The output spec asks for the count itself, not a pass-or-fail flag. Returning the raw 13 lets the validation layer decide what counts as over the cap and lets a human reading the result see exactly how far over it is. LENGTH is the right tool here because the question is how long the string is; turning the answer into a boolean is a separate downstream decision.
You practiced LENGTH(...) — return the character count of a string as a number, the basic measurement for validating against a length cap.