Wednesday, September 26, 2012

move putty sessions between computers.

ISSUE:
when a new compute was prepared, you want old putty session info loaded.

SOLUTION:
a. create a putty registry file from old computer
regedit /e putty.reg “HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions”

b. copy putty.reg to new computer

c. double click putty.reg to merge.

reference:
http://downloadsquad.switched.com/2007/02/01/howto-transfer-your-putty-settings-between-computers/

single value comparsion from three tables: Oracle SQL

ISSUE:
NEED alert for tablespace difference between 3 databases.

SOLUTION:

select a.tablespace_name,
NVL(prod.tablespace_name, '**MISSING**') DB1,
NVL(uat.tablespace_name,'**MISSING**') DB2,
NVL(upg.tablespace_name, '**MISSING**') DB3
from
(
(
select tablespace_name from dba_tablespaces@DB1
union
select tablespace_name from dba_tablespaces@DB2
union
select tablespace_name from dba_tablespaces@DB3
)
minus
(
 select tablespace_name from dba_tablespaces@DB1
 where tablespace_name in  (select tablespace_name from dba_tablespaces@DB2)
 and tablespace_name in (select tablespace_name from dba_tablespaces@DB3)
 )
) a ,
dba_tablespaces@DB1 db1,
dba_tablespaces@DB2 db2,
dba_tablespaces@DB3 db3
where a.tablespace_name=db1.tablespace_name(+)
and a.tablespace_name=db2.tablespace_name(+)
and  a.tablespace_name=db3.tablespace_name(+)
and a.tablespace_name not in ('EXAMPLE','UNDOTBS')
order by a.tablespace_name


OUTPUT:

TABLESPACE_NAME |DB1            |DB2          |DB3                                                                                     
----------------|---------------|-------------|---------------                                                                         
AAAAAA          |**MISSING**    |**MISSING**  |AAAAAA                                                                                  
AAAAAAAAAB      |AAAAAAAAAB     |**MISSING**  |AAAAAAAAAB                                                                              
AAAAAAAAATBS    |AAAAAAAAATBS   |**MISSING**  |AAAAAAAAATBS                                                                            
AAAAAAAAAAATBS  |**MISSING**    |**MISSING**  |AAAAAAAAAAATBS                                                                          
AAAAAAAABTBS    |**MISSING**    |AAAAAAAABTBS |AAAAAAAABTBS                                                                            
AAAAAAAABTB     |AAAAAAAABTB    |AAAAAAAABTB  |**MISSING**                                                                             
AAAAAAAABTC     |**MISSING**    |AAAAAAAABTC  |**MISSING**                                                                             
AAAAAAAACTC     |**MISSING**    |AAAAAAAACTC  |**MISSING**                                                                             
AAAAAAACCTC     |**MISSING**    |AAAAAAACCTC  |**MISSING**                                                                             
AAADAAACCTC     |AAADAAACCTC    |**MISSING**  |AAADAAACCTC                                                                             
AAAAACCTC       |AAAAACCTC      |**MISSING**  |AAAAACCTC                                                                               
AAAACCTC        |**MISSING**    |AAAACCTC     |**MISSING**                                                                             
AABBCCTC        |AABBCCTC       |**MISSING**  |**MISSING**                                                                             
AADDCCTC        |**MISSING**    |AADDCCTC     |**MISSING**                                                                             
AADDEETC        |**MISSING**    |AADDEETC     |**MISSING**                  


Comment:
this sql can be expended to compare multiple tables.

Reference:

http://www.techonthenet.com/sql/union.php

Remove lines in one file from another file: UNIX

ISSUE:
some config file need be updated to remove no-need lines. the no-need lines were provided without any sort.

SOLUTION:
a. put the no-need lines to a file - noneedfile
b. make a backup file of original one-  originfile.bkp
c. run
grep -v -x -f noneedfile originfile.bkp > originfile

CHECK:
cat noneedfile | wc -l
+
cat originfile | wc -l
=
cat originalfile.bkp | wc -l

Reference:

http://stackoverflow.com/questions/4780203/deleting-lines-from-one-file-which-are-in-another-file
http://www.unix.com/shell-programming-scripting/89798-compare-two-files-remove-all-contents-one-file-another.html


Friday, September 21, 2012

oracle clusterware command

as grid infrastructure user

#start high availability infrastructure
crsctl start has 

#stop high avialability infrastructure
crsctl stop has

#check crs status
crs_stat -t

#check crs status
crsctl status resource

as  grid infrastructure user or database owner
#make a one node database start and stop automatic
# -a is required if you use ASM otherwise db startup will failed
srvctl add database -d <database name> [-a "diskgroup,diskgroup"]

#check database restart config
srvctl config database -d <database name>


reference:
http://docs.oracle.com/cd/E11882_01/server.112/e25494/restart005.htm

Wednesday, September 5, 2012

PL SQL: PLS-00382: expression is of wrong type

Cause:
 one of the cause is that implicit cursor is used as a variable

e.g:

-- wrong syntex
FOR x in ( select username from all_users)
LOOP
   dbms_output.put_line ( x);
END LOOP;

-- correct syntex
FOR x in ( select username from all_users)
LOOP
   dbms_output.put_line ( x.username);
END LOOP;

reference:
http://www.orafaq.com/forum/t/50755/2

PL SQL: read comma-separated input string

 select regexp_substr('SMITH,ALLEN,WARD,JONES','[^,]+', 1, level) from dual
   connect by regexp_substr('SMITH,ALLEN,WARD,JONES', '[^,]+', 1, level) is not null;


reference:
https://blogs.oracle.com/aramamoo/entry/how_to_split_comma_separated_string_and_pass_to_in_clause_of_select_statement

Tuesday, September 4, 2012