I’m always looking for things. I love the ALT+G trick in SQL Developer.
But what about the command-line?
One of the really nice things about SQLcl is that if you can’t do what you want with the available commands, you can just build your own. That’s especially true now that we have JavaScript support.
But this is just plain, straight up SQL.
To build your own command, use ‘ALIAS’.
SQL> alias fuzzy=SELECT owner, object_name, object_type FROM dba_objects WHERE object_name LIKE :name ORDER BY 1,2,3 fetch FIRST 10 ROWS ONLY;
You can probably guess what this does.
Clik here to view.

You pass the binds in in the same order they appear in your query.
So, pretty easy, yeah?
And if you forget what your ALIAS is, just do, ALIAS LIST ALIAS_NAME.
Or do ALIAS LIST to see them all.
SQL> alias list fuzzy locks SEARCH sessions TABLES tables2
Or do HELP ALIAS to get a refresher.
SQL> help alias ALIAS ------ alias [<name>=<SQL statement>;| LOAD [<filename>]|SAVE [<filename>] | LIST [NAME] | DROP ] Alias IS a command which allows you TO save a SQL, plsql OR sqlplus script AND assign it a shortcut command. "alias" - print a list OF aliases "alias list <aliasName>" - list the contents OF the alias "alias <aliasName>=select :one from dual;" - Simple alias command Define an alias simply BY USING the alias keyword followed BY a single identifier name followed BY an '='. Anything after the '=' will be used AS the alias contents. FOR example, IF it IS SQL, it will be TERMINATED BY a ';'. IF it IS PLSQL, it will be TERMINATED BY a '/' Examples: -------- 1. SQL Example WITH Binds SQL> alias fred=SELECT :one FROM dual; IN this example, a bind variable can be SET up IN the alias. Running the alias IS done LIKE this below WITH any parameters TO the alias being bound TO a bind variable BY SQLcl SQL> fred 1 Command=fred :ONE ---- > 2. PL/SQL example SQL> alias db= BEGIN dbms_output.put_line('hi'); END; > / Here the block OF PLSQL IS TERMINATED BY the '/' ON a separate line at which point it IS accepted AS a NEW alias. SQL> db Command=db PL/SQL PROCEDURE successfully completed. hi Summary ------- alias ..=.. IS TERMINATED BY ';' alias ..=BEGIN OR ..=DECLARE IS TERMINATED BY a / ON a newline alias ON its own gives a list OF existing aliases. SQL>
We ship with a very few simple ones out of the box, but I’m hoping the clever folks out there will come up with some real humdingers.
And about SQL Developer…
Our script engine in SQLcl and SQL Developer are essentially the same. And actually, they are exactly the same. It’s the same code. Now, while it might not make sense to do things in SQL Developer that you do in SQLcl, you theoretically CAN.
Clik here to view.

an alternative to sql code templates perhaps
While the alias command works, they’re not stored in SQLDev for use in the next application startup…