Search notes:

Oracle SQL: Verbs and nouns

Most of Oracle's SQL statements (as well as probably of other vendors' too) consist of a combination of verbs and nouns. Because Oracle exposes the available SQL statements in v$sqlcommand, it is possible to parse the statements and extract their verbs and statements.

Create a view

In order to implement the command parsing only once, I create a view that I can then use multiple times.
create or replace view sqlcommand_verb_noun as
select
                       lower(command_name)                     sql_statement,
         regexp_substr(lower(command_name),   '[^ ]+' , 1, 1 ) verb,
   ltrim(regexp_substr(lower(command_name), ' ([^ ])+', 1, 1)) ||
         regexp_substr(lower(command_name), ' ([^ ])+', 1, 2)  noun
from
   v$sqlcommand
where
   command_name is not null and
   command_name    not like 'Do not use%' and
   command_name    not in ('NO-OP', 'PL/SQL EXECUTE')
;

select
   substrb(sql_statement, 1, 28) sql_statement,
   substrb(verb         , 1, 12) verb,
   substrb(noun         , 1, 20) noun
from
   sqlcommand_verb_noun fetch first 5 rows only;
--
-- SQL_STATEMENT                VERB         NOUN                
-- ---------------------------- ------------ --------------------
-- create table                 create       table               
-- insert                       insert                           
-- select                       select                           
-- create cluster               create       cluster             
-- alter cluster                alter        cluster   
Github repository Oracle-Patterns, path: /Installed/dynamic-performance-views/sql/command/verb_noun_view.sql
The view has three columns: sql_statement, verb and noun. Selecting from the view, it can be seen how it splits create table (value of sql_statement) into the verb create and the noun table.
In order to be able to create the view, a user must be granted select on the underlying v_$sqlcommand view:
connect sys as sysdba
grant select on sys.v_$sqlcommand to rene;

Verb only statements

Some statements consist only of a verb. They don't have a noun:
select
   verb
from
   sqlcommand_verb_noun
where
   noun is null
order by
   verb;
Github repository Oracle-Patterns, path: /Installed/dynamic-performance-views/sql/command/only-verb-statements.sql
This returns the following verbs:

Count of verbs

Of course, it's also interesting to see how many verbs there are:
select
   count(*),
   verb
from
   sqlcommand_verb_noun
where
   verb is not null
group by
   verb
order by
   verb
;
Github repository Oracle-Patterns, path: /Installed/dynamic-performance-views/sql/command/count-verbs.sql
The query returns (18c):
1 administer
48 alter
3 analyze
1 associate
1 audit
1 call
1 change
1 comment
1 commit
51 create
1 declare
1 delete
1 disassociate
48 drop
1 explain
2 flashback
1 grant
1 insert
1 lock
1 noaudit
5 purge
1 rename
1 revoke
1 rollback
1 savepoint
1 select
3 set
2 truncate
1 undrop
3 update
1 upsert
1 validate
Unsurprisingly, the most used verbs are alter, create and drop.

Count of nouns

Similarly, we can also count the nouns:
select
   count(*),
   noun
from
   sqlcommand_verb_noun
where
   noun is not null
group by
   noun
order by
   noun
;
Github repository Oracle-Patterns, path: /Installed/dynamic-performance-views/sql/command/count-nouns.sql
3 analytic view
3 assembly
3 attribute dimension
3 audit policy
2 bitmapfile
3 blockchain new in 21c or 23c
5 cluster
1 constraints
2 context
1 control file
4 database
1 database dictionary
3 database link
1 dba recyclebin
3 dimension
2 directory
3 disk group
3 domain 21c or 23c
3 Oracle SQL noun: EDITION
3 flashback archive
3 function
3 hierarchy
6 index
1 indexes
3 indextype
3 inmemory join
3 java
1 join index
1 key management
2 language 21c or 23c
3 library
3 lockdown profile
3 logical partition tracking 21c or 23c
6 materialized view
3 materialized zonemap
1 method
3 mining model
3 mle env 21c or 23c
3 mle module 21c or 23c
5 object (This one is a bit special as it pertains to grant object, revoke object etc.)
3 operator
3 outline
3 package
3 package body
1 password
1 pfile
3 pluggable database
3 pmem filestore 21c or 23c
3 procedure
3 profile
3 property graph 23c
1 recyclebin
1 resource cost
2 restore point
3 rewrite equivalence
4 role
3 rollback segment
1 schema
2 schema synonym
3 sequence
1 session
1 spfile
2 statistics
1 storagepool 21c or 23c
3 summary
3 synonym
1 system (alter system)
8 table
4 tablespace
1 tracing
1 transaction
3 trigger
1 true cache
3 type
3 type body
3 user
3 view

Links

DB: SQL clauses

Index