Thursday, April 16, 2015

Repeating another SQLCL EA release

    It's been a month and a lot of bugs have been fixed in that time and new features added. That adds up to time for another EA for our new sqlcl.  The third sqlcl EA is out now and can be found here on the SQL Developer 4.1 download page.  

  Not sure what this sqlcl thing is ? Check here.


LOAD:  Making CSV loading to the db very easy

Here's a very quick example of the possibilities.  Here 

-- drop it to be sure
drop table emp2;

-- create an empty table
create table emp2 as select * from emp where rownum=0;

-- don't need to see it
set term off
-- set the format to CSV
set sqlformat csv
-- spool
spool emp.csv
-- spooling....
select * from emp;
-- spooled
spool off

-- need to see again
set term on
-- load into the new table
load EMP2 emp.csv



The output from running the script makes it very easy to see what happened.



REPEAT : Build your own monitor

This is another very simple yet useful command.  The idea is to basically build your own sql that your may want to run to see what's going on.  This example is a simple select against v$session with a decode on the command to see what the sessions are doing.  Running this is easy, running it again and again mean hitting / and return a lot.

Enter the repeat.  Just specify how many times and what the sleep interval is and sqlcl takes care of running it.



In the header, there's a status to who what iteration it is what the time is ( and yes I know a bug in the number format ) and what the delay is to running it again.




The Report being used

The SQL I'm using here is the same sql in the SQL Developer Sessions report.  It can be found off the Tools->Sessions menu.  Additionally in the Reports section under DBA reports.



select vs.sid ,serial# serial, vs.sql_id,
       vs.username "Username",
       case when vs.status = 'ACTIVE' then last_call_et else null end "Seconds in Wait",
       decode(vs.command,  
                         0,null, 
                         1,'CRE TAB', 
                         2,'INSERT', 
                         3,'SELECT', 
                         4,'CRE CLUSTER', 
                         5,'ALT CLUSTER', 
                         6,'UPDATE', 
                         7,'DELETE', 
                         8,'DRP CLUSTER', 
                         9,'CRE INDEX', 
                         10,'DROP INDEX', 
                         11,'ALT INDEX', 
                         12,'DROP TABLE', 
                         13,'CRE SEQ', 
                         14,'ALT SEQ', 
                         15,'ALT TABLE', 
                         16,'DROP SEQ', 
                         17,'GRANT', 
                         18,'REVOKE', 
                         19,'CRE SYN', 
                         20,'DROP SYN', 
                         21,'CRE VIEW', 
                         22,'DROP VIEW', 
                         23,'VAL INDEX', 
                         24,'CRE PROC', 
                         25,'ALT PROC', 
                         26,'LOCK TABLE', 
                         28,'RENAME', 
                         29,'COMMENT', 
                         30,'AUDIT', 
                         31,'NOAUDIT', 
                         32,'CRE DBLINK', 
                         33,'DROP DBLINK', 
                         34,'CRE DB', 
                         35,'ALTER DB', 
                         36,'CRE RBS', 
                         37,'ALT RBS', 
                         38,'DROP RBS', 
                         39,'CRE TBLSPC', 
                         40,'ALT TBLSPC', 
                         41,'DROP TBLSPC', 
                         42,'ALT SESSION', 
                         43,'ALT USER', 
                         44,'COMMIT', 
                         45,'ROLLBACK', 
                         46,'SAVEPOINT', 
                         47,'PL/SQL EXEC', 
                         48,'SET XACTN', 
                         49,'SWITCH LOG', 
                         50,'EXPLAIN', 
                         51,'CRE USER', 
                         52,'CRE ROLE', 
                         53,'DROP USER', 
                         54,'DROP ROLE', 
                         55,'SET ROLE', 
                         56,'CRE SCHEMA', 
                         57,'CRE CTLFILE', 
                         58,'ALTER TRACING', 
                         59,'CRE TRIGGER', 
                         60,'ALT TRIGGER', 
                         61,'DRP TRIGGER', 
                         62,'ANALYZE TAB', 
                         63,'ANALYZE IX', 
                         64,'ANALYZE CLUS', 
                         65,'CRE PROFILE', 
                         66,'DRP PROFILE', 
                         67,'ALT PROFILE', 
                         68,'DRP PROC', 
                         69,'DRP PROC', 
                         70,'ALT RESOURCE', 
                         71,'CRE SNPLOG', 
                         72,'ALT SNPLOG', 
                         73,'DROP SNPLOG', 
                         74,'CREATE SNAP', 
                         75,'ALT SNAP', 
                         76,'DROP SNAP', 
                         79,'ALTER ROLE', 
                         79,'ALTER ROLE', 
                         85,'TRUNC TAB', 
                         86,'TRUNC CLUST', 
                         88,'ALT VIEW', 
                         91,'CRE FUNC', 
                         92,'ALT FUNC', 
                         93,'DROP FUNC', 
                         94,'CRE PKG', 
                         95,'ALT PKG', 
                         96,'DROP PKG', 
                         97,'CRE PKG BODY', 
                         98,'ALT PKG BODY', 
                         99,'DRP PKG BODY', 
                         to_char(vs.command)) "Command",
    vs.machine "Machine",
    vs.osuser "OS User", 
    lower(vs.status) "Status",
    vs.program "Program",
    vs.module "Module",
    vs.action "Action",
    vs.resource_consumer_group,
    vs.client_info,
    vs.client_identifier
from gv$session vs 
where vs.USERNAME is not null
and nvl(vs.osuser,'x') <> 'SYSTEM'
and vs.type <> 'BACKGROUND'
order by 1;

Disqus for Kris' Blog