Current date
Describe
Explain plans
Get type of expression
Run scripts
Show all tables
Show parameters
Truncate table
Run AWRs for Oracle
SELECT CURDATE();
SELECT NOW();
SELECT CURRENT_DATE;
SELECT CURRENT_TIMESTAMP;
SELECT SYSDATE FROM DUAL;
SELECT SYSTIMESTAMP FROM DUAL;
SELECT SYSDATETIME();
SELECT CURRENT_TIMESTAMP;
VALUES(CURRENT DATE);
VALUES(CURRENT TIMESTAMP);
SELECT CURRENT DATE FROM sysibm.sysdummy1;
SELECT CURRENT TIMESTAMP FROM sysibm.sysdummy1;
DESCRIBE <table_name>;
\d <table_name>;
sp_help <table_name>;
DESCRIBE TABLE <table_name>;
DESCRIBE SELECT * FROM <table_name>;
EXPLAIN [FORMAT = [TRADITIONAL | TREE | JSON]] <SQL>;
EXPLAIN ANALYZE <SQL>;
EXPLAIN [ ANALYZE ] [ VERBOSE ] <SQL>;
EXPLAIN PLAN FOR <SQL>;
SELECT *
FROM TABLE(DBMS_XPLAN.DISPLAY (FORMAT=>'ALL +OUTLINE'));
SET SHOWPLAN_TEXT ON;
<SQL>
<SQL>
<SQL>
SET SHOWPLAN_TEXT OFF;
CALL SYSPROC.SYSINSTALLOBJECTS('EXPLAIN', 'C',
CAST (NULL AS VARCHAR(128)), CAST (NULL AS VARCHAR(128)))
EXPLAIN PLAN FOR <SQL>;
db2exfmt -d <DB> -o explain.txt
EXPLAIN USING TABULAR <SQL>;
SELECT pg_typeof(<expression>);
SELECT dump(<expression>) FROM DUAL;
source <script path/file>
\i <script path/file>
@<script path/file>
:r <script path/file>
db2 -tvmf <script path/file>
SHOW TABLES;
\dt
SELECT * FROM pg_catalog.pg_tables;
SELECT * FROM DBA_TABLES;
SHOW VARIABLES [LIKE '<string>'];
SHOW [<parameter> | ALL];
SHOW PARAMETER <string>
TRUNCATE TABLE <table_name>;
TRUNCATE TABLE <table_name> IMMEDIATE;
# Little script to take an AWR snapshot and return the snap id
take_snapshot() {
sql -s / as sysdba <<EOF
set pagesize 0 feedback off verify off heading off echo off;
select DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT('ALL') AS a from dual;
exit;
EOF
}
# Little script to get the dbid
get_dbid() {
sql -s / as sysdba <<EOF
set pagesize 0 feedback off verify off heading off echo off;
select dbid from v\$database;
exit;
EOF
}
# Generate AWR report (dbid, snap_id_begin, snap_id_end, log_file)
generate_snapshot() {
sql -s / as sysdba > $4 <<EOF
set pagesize 0 feedback off termout off;
SELECT * FROM TABLE(DBMS_WORKLOAD_REPOSITORY.AWR_REPORT_HTML($1, 1, $2, $3));
exit;
EOF
}
# Take snapshot ids
snap_id_begin=$(take_snapshot)
snap_id_end=$(take_snapshot)
dbid=$(get_dbid)
generate_snapshot($dbid, $snap_id_begin, $snap_id_end, "awr.html")