SQL Developer Code Templates Autocomplete

Published by Alvin Liu on

Using the short keyword to fill complex SQL in Oracle SQL Developer to make your work more efficient.

Follow those simple steps to complete this setup in 5 minutes:

  1. How to use Code Template in Oracle SQL Developer
    • Open Oracle SQL Developer.
    • Connect to any database and open SQL Query window.
    • Type “ssf”, you will be suggest to input select table commnad.
    • This is the built-in Code Template. Let us create some more.
  2. Create Code Templates
    • Click Menu -> “Settings”
    • Expand “Code Editor”
    • Select “Code Templates”
    • Click “Add Template”
    • There will be a new empty record at the end, input the keyword in the Id column and your query in the Template column.
    • When inputting the template, click the Pencil button to open a larger edit window.
    • Use [ ] for dynamic content which will be replaced, like the table name. Anyway, you only can use one [ ] in the template.
  3. Code Templates Example
IdUsageTemplate
ssSearch keyword in stored proceduresSELECT * FROM USER_SOURCE WHERE lower(TEXT) LIKE lower(‘%[keyword]%’);
stSearch tables by keywordSELECT table_name
FROM user_tables
WHERE table_name LIKE ‘%[keyword]%’;
scSearch tables by column keywordSELECT table_name, column_name
FROM all_tab_columns
WHERE UPPER(column_name) LIKE UPPER(‘%item_id%’)
order by UPPER(column_name), upper(table_name);
tocharConvert date to charto_char([column], ‘YYYY-MM-DD HH24:MI:SS’)
todateConvert char to dateto_date(‘[2024-01-30]’,’yyyy-mm-dd’)
alterAlter table columnALTER TABLE [table_name] MODIFY (column_name datatype);
analyzeAnalyze tableanalyze table [table name] compute statistics;
datafileList data filesSELECT file_name, tablespace_name, bytes/1024/1024||’M’
FROM dba_data_files;
killKill a dead lock querySELECT ‘ALTER SYSTEM KILL SESSION ”’||sid||’,’||serial#||”’;’, s.username, s.program, s.sql_id, s.sql_child_number, s.status, t.sql_text
FROM v$session s left join v$sql t on s.sql_id=t.sql_id
WHERE s.type != ‘BACKGROUND’ and users_executing>0;
mergeMerge into tableMERGE INTO [target_table] t
USING () f
ON (t.item_id = f.item_id and t.loc_id=f.loc_id)
WHEN MATCHED THEN
UPDATE SET
t. = f.,
t. = f.
WHEN NOT MATCHED THEN
INSERT (item_id,loc_id)
VALUES (f.item_id,f.loc_id);
spaceQuery table space usageSELECT a.tablespace_name,
total,
free,
(total – free) rest,
ROUND((total – free) / total * 100, 2) || ‘%’ used
FROM (SELECT tablespace_name, SUM(bytes) / 1024 / 1024 total
FROM dba_data_files
GROUP BY tablespace_name) a,
(SELECT tablespace_name, SUM(bytes) / 1024 / 1024 free
FROM dba_free_space
GROUP BY tablespace_name) b
WHERE a.tablespace_name = b.tablespace_name
ORDER BY (total – free) DESC;
adddatafileAdd a data file to table spaceALTER TABLESPACE [name]
ADD DATAFILE ‘name and path.DBF’ SIZE 2000M AUTOEXTEND ON;
Categories: Database

Alvin Liu

Software Developer in Toronto

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *