# SQLcl has built-in code snippets (ALIAS command). Because you can't remember everything, right?

How many times a day do you re-type the exact same SQL queries?

Whether it is checking system time, finding out which employees earn way too much, or running a complex query to check active database sessions, typing those long SQL statements repeatedly is a waste of time.

Sure, you could keep a scratchpad open with your standard scripts. But what if your favorite command-line tool (SQLcl) could remember them for you?

That’s exactly what the`ALIAS` command in SQLcl is for. And it’s been there since… well, let’s just say it’s not exactly new.

## What's an alias?

In SQLcl, it is simply a shortcut name mapped to a SQL statement or PL/SQL script. Instead of executing a full query, you just type your custom shortcut name.

## How do you create one?

Let’s say you keep querying `SYSDATE` just to check the current database time.

![](https://cdn.hashnode.com/uploads/covers/636caea92e3b6701485c17b5/603bd6e0-f340-470d-8f91-7b7d8593db1b.png align="center")

Define an alias called "time":

```sql
alias time = select sysdate from dual;
```

And just type "time"

![](https://cdn.hashnode.com/uploads/covers/636caea92e3b6701485c17b5/93f8b6f5-8476-4510-b714-68a1cd3f1e9c.png align="center")

OK, but aliases are not limited to static queries. You can also pass parameters into them.

Suppose you want to query your top highest-paid employees.

![](https://cdn.hashnode.com/uploads/covers/636caea92e3b6701485c17b5/31870f9c-0950-42a4-951f-63ddc57ad49b.png align="center")

What about just typing "top"?

Yes, please! Just define an alias.

![](https://cdn.hashnode.com/uploads/covers/636caea92e3b6701485c17b5/fa9793f1-4ccc-48f7-8a73-74d8bf2e1c74.png align="center")

```sql
alias -nulldefaults -group employees -desc "My top X employees" top = select * from (select last_name, first_name, salary from employees order by salary desc) where rownum <= nvl(:count,10);
```

Quick explanation:

"-nulldefaults" - optional param, auto-assigns null values if you don't specify a variable while running "top"

"-group" - optional, adds alias to group

"-desc" - optional alias description

Now, just type "top" or "top X"

![](https://cdn.hashnode.com/uploads/covers/636caea92e3b6701485c17b5/bb46ee8c-320b-47a9-aaa3-0537d7565146.png align="center")

## Manage aliases/snippets

I don't want you to get lost in 1000 aliases you will create after reading this blog :)

That's why SQLcl provides built-in subcommands to manage, view, and organize all your saved shortcuts.

`alias list` - show user-defined aliases

![](https://cdn.hashnode.com/uploads/covers/636caea92e3b6701485c17b5/5e54eddb-fd01-43b0-80be-149f576a2b32.png align="center")

`alias list all` - show all aliases

![](https://cdn.hashnode.com/uploads/covers/636caea92e3b6701485c17b5/b654b2f7-c523-4e75-9f48-bf3e82f67a14.gif align="center")

`alias list <group>` - shows user-defined aliases from group

![](https://cdn.hashnode.com/uploads/covers/636caea92e3b6701485c17b5/df46585b-2c24-4ca4-b381-fc77a521d6e8.png align="center")

`alias details <alias_name>` - shows alias details

![](https://cdn.hashnode.com/uploads/covers/636caea92e3b6701485c17b5/e49ffbad-6b7e-4734-9847-b9080782478b.png align="center")

`alias search *text*` - search through aliases, \* is an optional wildcard

![](https://cdn.hashnode.com/uploads/covers/636caea92e3b6701485c17b5/d0a9e0d4-c366-474d-91f6-f5c2ffec3dca.png align="center")

`alias save` - save aliases you defined

`alias load` - load aliases from file shared by friend

If you use SQLcl Projects, you can start by loading the aliases created by Alexander Kluev (link [here](https://alexonapex.com/blog/2026/08/13/sqlcl-project-aliases/)).

## Useful aliases already built into SQLcl.

No need to do anything. Just run SQLcl, and you already have all those aliases. Nice, isn't it?

`alias list default`

![](https://cdn.hashnode.com/uploads/covers/636caea92e3b6701485c17b5/0a86356d-4ded-438e-9852-febbb166ff91.png align="center")

![](https://cdn.hashnode.com/uploads/covers/636caea92e3b6701485c17b5/167c0792-2166-43a0-89c5-40f771647241.gif align="center")

If you want to learn more about the `ALIAS` command, open SQLcl and run the HELP command.

```sql
sql /nolog
help alias
```

![](https://cdn.hashnode.com/uploads/covers/636caea92e3b6701485c17b5/7e480ac7-2d7b-4654-bf93-9040f89f5b22.gif align="center")

And for more articles about SQLcl, try my all things SQLcl hub here -> [https://rafal.hashnode.dev/oracle-sqlcl-what-every-apex-pl-sql-dev-should-know-dbas-you-re-invited-too](https://rafal.hashnode.dev/oracle-sqlcl-what-every-apex-pl-sql-dev-should-know-dbas-you-re-invited-too)

Enjoy creating your next 1,000 aliases or code snippets if you prefer!

P.S. What's the cover photo? It's a view from my video calls in a co-working office during my stay in Riga, Latvia.

P.P.S.

*   The gorilla is not real.
    
*   No animals were hurt.
    
*   Yes, it was motivating to work harder :)
