Thursday, November 22, 2012

Oracle Relation Query - DBA_CONSTRAINTS

Ref. http://www.shutdownabort.com/dbaqueries/Structure_Constraints.php
Ref. http://docs.oracle.com/cd/B19306_01/server.102/b14237/statviews_1037.htm




-- View The Relation of The Specific Table

col type format a10
col cons_name format a30
select decode(constraint_type,
  'C', 'Check',
  'O', 'R/O View',
  'P', 'Primary',
  'R', 'Foreign',
  'U', 'Unique',
  'V', 'Check view') type
, constraint_name cons_name
, status
, last_change
, R_CONSTRAINT_NAME
, RELY
from dba_constraints
where owner like '&owner'
and table_name like '&table_name'
order by 1
/

-- View The PK column of The Specific Table
SELECT cols.table_name, cols.column_name, cols.position, cons.status, cons.owner
FROM all_constraints cons, all_cons_columns cols
WHERE cols.table_name = '&table_name'
AND cons.constraint_type = 'P'
AND cons.constraint_name = cols.constraint_name
AND cons.owner = cols.owner
AND cons.owner ='&owner'
ORDER BY cols.table_name, cols.position;

Tuesday, November 20, 2012

Linux change atime,mtime using touch

Ref. http://www.csie.cyut.edu.tw/~dywang/linuxSystem/node37.html



  1. 檔案變動時間
    1. atime (Access time):檔案內容上次被讀取的時間;
    2. ctime (Change status time):檔案狀態最近被更動的時間(不論是屬性、權限等);
    3. mtime (Modification time):檔案內容最近被修改的時間。
  2. 查詢檔案 /etc/man.conf 變動時間

    [root@dywHome2 ~]# ll /etc/man.config <==預設為 mtime
    -rw-r--r-- 1 root root 4831 Feb  3  2008 /etc/man.config
    [root@dywHome2 ~]# ll --time=atime /etc/man.config
    -rw-r--r-- 1 root root 4831 Sep  5 09:30 /etc/man.config
    [root@dywHome2 ~]# ll --time=ctime /etc/man.config
    -rw-r--r-- 1 root root 4831 Feb  3  2008 /etc/man.config
    [root@dywHome2 ~]# ll --time=mtime /etc/man.config
    

  3. touch:修改檔案時間,若檔案不存在,則產生新檔案。

    [root@linux ~]# touch [-acdmt] 檔案
    參數:
    -a  :僅修訂 access time;
    -c  :僅修改時間,而不建立檔案;
    -d  :後面可以接日期,也可以使用 --date="日期或時間"
    -m  :僅修改 mtime ;
    -t  :後面可以接時間,格式為[YYMMDDhhmm]
    範例:
    
    範例一:新建一個空的檔案
    [root@linux ~]# cd /tmp
    [root@linux tmp]# touch testtouch
    [root@linux tmp]# ls -l testtouch
    -rw-r--r--  1 root root    0 Jul 19 20:49 testtouch
    
    範例二:將 ~/.bashrc 複製成為 bashrc,假設複製完全的屬性,檢查其日期
    [root@linux tmp]# cp ~/.bashrc bashrc
    [root@linux tmp]# ll bashrc; ll --time=atime bashrc; ll --time=ctime bashrc
    -rwxr-xr-x  1 root root 395 Jul  4 11:45 bashrc  <==這是 mtime
    -rwxr-xr-x  1 root root 395 Jul 19 20:44 bashrc  <==這是 atime
    -rwxr-xr-x  1 root root 395 Jul 19 20:53 bashrc  <==這是 ctime
    
    範例三:修改案例二的 bashrc 檔案,將日期調整為兩天前
    [root@linux tmp]# touch -d "2 days ago" bashrc
    [root@linux tmp]# ll bashrc; ll --time=atime bashrc; ll --time=ctime bashrc
    -rwxr-xr-x  1 root root 395 Jul 17 21:02 bashrc
    -rwxr-xr-x  1 root root 395 Jul 17 21:02 bashrc
    -rwxr-xr-x  1 root root 395 Jul 19 21:02 bashrc
    # 日期在 atime 與 mtime 都改變了,但是 ctime 則是記錄目前的時間!
    
    範例四:將上個範例的 bashrc 日期改為 2005/07/15 2:02
    [root@linux tmp]# touch -t 0507150202 bashrc
    [root@linux tmp]# ll bashrc; ll --time=atime bashrc; ll --time=ctime bashrc
    -rwxr-xr-x  1 root root 395 Jul 15 02:02 bashrc
    -rwxr-xr-x  1 root root 395 Jul 15 02:02 bashrc
    -rwxr-xr-x  1 root root 395 Jul 19 21:05 bashrc

Tuesday, November 06, 2012

MySQL Loop Usage --- select whole year status



-- Create Procedure
DELIMITER $$
CREATE PROCEDURE TIMELOOP()

   BEGIN
      DECLARE a INT Default 0 ;
      simple_loop: LOOP
         select DATE_ADD('20120101',interval a day) "Date", week(DATE_ADD('20120101',interval a day)) "Week", date_format(DATE_ADD('20120101',interval a day),"%m") "Month",quarter(DATE_ADD('20120101',interval a day)) "Season", date_format(DATE_ADD('20120101',interval a day),"%Y") "Year";
         SET a=a+1;
         IF a=366 THEN
            LEAVE simple_loop;
         END IF;
   END LOOP simple_loop;
END $$

-- Run Procedure
call TIMELOOP();

-- Delete Procedure
DROP PROCEDURE IF EXISTS `TIMELOOP`;

-- Check If exists procedures
show PROCEDURE status;

Saturday, November 03, 2012

換一個方式生活 !


不是只有一種生活~
除了朝九晚五的拼命賺錢~
還有其他的生活方式~
重點是了解自己要的是什麼~ 了解自我~!
人一生的時間不多~ 快 "準備好" 去追你的夢~!!
~~~ Share with 有夢,追夢,逐夢,的你 ~~~