mercoledì 29 maggio 2013

Oracle: duplicare una tabella

Per poter duplicare una tabella in Oracle, basta eseguire la seguente istruzione:


create table nuova_tabella as 
select * 
from vecchia_tabella;

ORA-00054

Può capitare durante l'utilizzo di un database, alcune attività blocchino una tabella. 

In questo caso Oracle restituisce l'errore

ORA-0054: resource busy and acquire with NOWAIT specified. 

Tramite SQLPLUS oppure TOAD, inserire la seguente query: 

select object_name, s.sid, s.serial#, p.spid
from v$locked_object l, dba_objects o, v$session s, v$process p 
where l.object_id = o.object_id 
  and l.session_id = s.sid 
  and s.paddr = p.addr; 


La quale fornirà il seguente risultato: 

OBJECT_NAME   SID  SERIAL#  SPID
TABLE1        159    16191  2240 
TABLE1        150    11583  2608 

 L'elenco delle tabelle che lo bloccano. 

 Per sbloccarlo basta la seguente istruzione: 

ALTER SYSTEM DISCONNECT SESSION '159,16191' IMMEDIATE; 
ALTER SYSTEM DISCONNECT SESSION '150,11583' IMMEDIATE;

giovedì 2 maggio 2013

Visual Basic .NET: Differenza tra due date

Di seguito un esempio pratico in vb.net

        Dim data As New DateTime(2013, 5, 2, 13, 17, 5)
        Dim data2 As DateTime = Date.Now
        'ottengo la differenza tra due date
        Dim diff As TimeSpan = data2.Subtract(data)

        TextBox1.Text = "Giorni: " & diff.Days & vbNewLine
        TextBox1.Text &= "Ore: " & diff.Hours & vbNewLine
        TextBox1.Text &= "Minuti: " & diff.Minutes & vbNewLine
        TextBox1.Text &= "Secondi: " & diff.Seconds & vbNewLine