Select with inline function fails in SQL and Command Window

In Oracle 12c we can write inline functions within a select statement. When running such a select in SQL or Command Window, the statement is broken into several pieces. A simple example:

with function IC (a_ in varchar2) return varchar2 is
begin
return initcap(a_);
end;
select IC(username) from all_users;

This is broken into three pieces beacuse of the ;s, and each part of course fails.
This works in SQL*Plus if I define the SQLTERMINATOR to something different from ;. Oracle SQL Developer executed the statement without problems.

Is there a way to make PL/SQL Developer run such a command?
 
I suspect that if you uncheck the "AutoSelect statement" preference under the SQL Window preferences, it would work. You might have to manually select the whole statement. The AutoSelect statement preference assumes that the semi-colon is the end of a select statement.

It's not ideal, but it would get you by.
 
Last edited:
Was having the same problem as OP.

with function IC (a_ in varchar2) return varchar2 is
begin
return initcap(a_);
end;
select IC(username) from all_users;
 
To have autoselect work you must put a / on the line after the statement:

SQL:
with function IC (a_ in varchar2) return varchar2 is
begin
return initcap(a_);
end;
select IC(username) from all_users
/

This currently works for me.
 
Back
Top