Sunday, 17 February 2019

DB2 - Catalog to remote server


Catalog the server node and the database.

a. In the command window, run the following command:

db2 catalog tcpip node name remote DB Server {<host name> or <IP Address server Port number used>}

b. In the command window, run the following command:

db2 catalog db database name at node name authentication SERVER

DB2 - VIP instance list and Primary Node

Run the following command to get the Database name.






db2 get db cfg for DB2|grep HADR

output would something like

 HADR database role                                      = PRIMARY
 HADR local host name                  (HADR_LOCAL_HOST) = NameOfPrimaryNode
 HADR local service name                (HADR_LOCAL_SVC) = hadr01
 HADR remote host name                (HADR_REMOTE_HOST) = NameOfSecondyNode
 HADR remote service name              (HADR_REMOTE_SVC) = hadr01


Saturday, 16 February 2019

DB2 - List the alias Name


Run the following command  to get the alias Name:

 db2 list database directory


Output

 System Database Directory

 Number of entries in the directory = 1

Database 1 entry:

 Database alias                       = DB2ALIAS
 Database name                        = DB2
 Node name                            = DB2NODE
 Database release level               = 10.00
 Comment                              =
 Directory entry type                 = Remote
 Catalog database partition number    = -1
 Alternate server hostname            =
 Alternate server port number         =

Oracle - Date- Truncate - EXTRACT - To_Char

Truncate a date.


The TRUNC (date) function returns date with the time portion of the day truncated to the unit specified by the format model fmt. The value returned is always of datatype DATE, even if you specify a different datetime datatype for date. If you omit fmt, then date is truncated to the nearest day. Please refer to "ROUND and TRUNC Date Functions" for the permitted format models to use in fmt.



Below will truncate timestamp part from a dateTimeStamp Field

select trunc(dateTimeStamp),count(*) from myTable


SELECT TRUNC(TO_DATE('27-OCT-92','DD-MON-YY'), 'YEAR')
  "New Year" FROM DUAL;
 
New Year
---------
01-JAN-92 

EXTRACT (datetime)
extract_datetime::=
Description of extract_datetime.gif follows
e.g
select extract( month from sysdate) from dual
select extract( year from sysdate) from dual

TO_CHAR
select to_char( sysdate, 'mm' ) from dual ; -- returns 01..12
select to_char( sysdate, 'MON' ) from dual ;-- returns JAN, FEB, ... DEC 
select to_char( sysdate, 'Month' ) from dual ;-- returns January, ... December