1

I would like to create a function which returns with a table, but I would like to add default values to the values, like this:

CREATE OR REPLACE FUNCTION cleanDatabase()
RETURNS TABLE 
(
error TEXT,
createConnection TEXT,
dropDatabases TEXT DEFAULT 'OK',
dropTableSpaces TEXT,
closeConnection TEXT
)
AS $$
...

But I get the following error: ERROR: syntax error at or near "DEFAULT"

I use default keyword often when I create new tables and it is working fine. Is it just not a use case what I am doing here, and I should just create a temporary table with defaults and return with that one?

1
  • 2
    you can add coalesce in the select statement where you are returning the data Commented Nov 29, 2018 at 10:53

1 Answer 1

2

It doesn’t make sense to have a default for the return type’s columns, because you’re returning every column.

The default value for a table only kicks in when a row is inserted without providing values (as distinct from specifying a null) for columns with default values. There’s no way in PL/SQL to not return all values.

Use coalesce() or similar to provide a value when one can’t be determined from your SP logic.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.