CodeBlanks Logo Icon CodeBlanks

Calling a function

Call a function inside SELECT.

Calling a function

You call a function inside a SELECT. It returns a value instead of a table.

SELECT get_tax(100);

This query returns the tax for 100.

The expression get_tax(100) is evaluated and returned.

Calling a function — details

A function can be used anywhere in a query: WHERE, SELECT and HAVING.

For example, WHERE get_tax(price) > 10 filters products whose tax is above 10; but wrapping a column in a function can prevent an index from being used.

Practice Calling a function

Call get_tax(100) inside a SELECT.

Starter code

query.sql
-- call function
SELECT

Sample solution

query.sql
SELECT get_tax(100);

Expected output

get_tax
18

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Where is a function called?

  • Inside SELECT Correct answer
  • Inside ALTER
  • Inside DROP
  • Inside CREATE

Explanation: A function is called inside SELECT.

2 Add SELECT

Question
____ get_tax(100);
Answer
SELECT get_tax(100);

Explanation: A function that returns a value is called inside SELECT, e.g. SELECT get_tax(100).

3 Calling a function: match the terms

Term Meaning
SELECT query
function function
parameter input
value result

All lessons in Advanced