Skip to content
Advertisement

Return multiple values in varchar2

I want to return the values of several columns (With a function) in a varchar2 but I get an error when I choose several columns in select.

Error:

Error(17,6): PL/SQL: SQL Statement ignored

Error(18,6): PL/SQL: ORA-00947: there are not enough values

Advertisement

Answer

Two relatively simple options – if they suit your needs. You didn’t really explain what you expect to get as a result so – this might, or might not be applicable to your situation.

Anyway, here you go:

First option uses listagg function which returns a concatenated string (as you wanted to return varchar2). Drawback is that it won’t work for the result longer than 4000 characters, but – in that case – you can use XMLAGG.


Another one concatenates different columns into a string; you might need to use e.g. to_char or to_date functions in certain cases, but – generally – it works as follows:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement