写给还在上班的人(转)

–朋友推荐

HP老总孙振耀  写在退休时

如果这篇文章没有分享给你,那是我的错。

如果这篇文章分享给你了,你却没有读,继续走弯路的你不要怪我。

如果你看了这篇文章,只读了一半你就说没时间了,说明你已经是个“茫”人了。

如果你看完了,你觉得这篇文章只是讲讲大道理,说明你的人生阅历还不够,需要你把这篇文章珍藏,走出去碰几年壁,头破血流后再回来,再读,你就会感叹自己的年少无知。

如果你看完了,觉得很有道理,然后束之高阁,继续走进拥挤的地铁,依然用着自己昨日的观念来思考自己的未来,你的人生也将继续重复着昨日的状况。

如果你看完了,觉得那是一个过来人,对你的人生忠告,并你也愿意用他告诉你的思想去指导自己今后的生活,对你来讲成功不是很难,难的是你是否可以用这篇文章里的思想一直鞭策自己。

如果你看完了,觉得那是一个长辈用他的一生的时间来写的一篇对你忠告的文章,说明你已经有了和他相似的人生阅历,只要你继续努力,成就伟业并不难,难的是你是否可以把自己的人生经验和他人分享呢? Continue reading

python-oracle9i单表访问SQL统计信息

#!/usr/bin/env python
# -*- encoding: utf8 -*-
# Author: tracylling@gmail.cn
# Created: 2011-8-16

import cx_Oracle
import os
import sys
import re
os.environ['NLS_LANG'] ='AMERICAN_AMERICA.ZHS16GBK'

#input format : python oracle9i_liling.py -t table_name -o owner >> file_path/file_name.txt
OWNER = sys.argv[4]
TABLE_NAME = sys.argv[2]

TABLE_NAME1 = TABLE_NAME.upper()
OWNER1 = OWNER.upper()

print("------------Welcome To Oracle 9i Statistics Tools----------------")
print("")

#--login--#
def db_connect():
    try:
        conn = cx_Oracle.connect('tp/tp@ocn_test')
        return conn
    except cx_Oracle.DatabaseError,exc:
        error,=exc.args
        print "db_connect error"
        print >> sys.stderr, "Oracle-Error-Code:", error.code
        print >> sys.stderr, "Oracle-Error-Message:", error.message


#--table information--#
def table_info(cursor):
    try:
        cursor.execute("""
           select owner,segment_name,bytes / 1024 / 1024
             From dba_segments
            where segment_name = :table_name
              and segment_type = 'TABLE'
              and owner = :owner
           """,table_name = TABLE_NAME1,owner = OWNER1)
        for column_1,column_2,column_3 in cursor.fetchall():
            print "*********************Table Info*********************"
            print "Version      Table Name      Owner Name      Size(MB)"
            print "-"*52
            print "%s %12s %16s %12d" %(conn.version,TABLE_NAME1,OWNER1,column_3)
        
    except cx_Oracle.DatabaseError, exc:
        error, = exc.args
        print "table_info error"
        print >> sys.stderr, "Oracle-Error-Code:", error.code
        print >> sys.stderr, "Oracle-Error-Message:", error.message

#--index infomation--#
def index_info(cursor):
    try:
        print ""
        print "***********Index Info***********"
        print "INDEX_NAME             SIZE(MB)"
        print "-"*30
        cursor.execute("""
            select owner,segment_name, bytes / 1024 /1024
                From dba_segments
            where segment_name IN
                (SELECT INDEX_NAME FROM DBA_INDEXES 
                WHERE TABLE_NAME = :table_name)
                and segment_type = 'INDEX'
                and owner = :owner
            """,table_name = TABLE_NAME1,owner = OWNER1)
        for column_1,column_2,column_3 in cursor.fetchall():
                print "%-25s %d" % (column_2,column_3)
    except cx_Oracle.DatabaseError, exc:
            error, = exc.args
            print "index_info error"
            print >> sys.stderr, "Oracle-Error-Code:", error.code
            print >> sys.stderr, "Oracle-Error-Message:", error.message

#--SQL--#
def sql_join(cursor):
    dict = {}        #存放SQL连接并归一化后结果
    dict_table = {}  #存放全词匹配表名的SQL语句
    count = {}       #存放归一化语句条数,做除数
    match_join='(\s*:[A-Za-z0-9]+\s*,?\s*)+'
    match_table = '[^A-Za-z0-9_]' + TABLE_NAME + '[^A-Za-z0-9_]'
    rx = re.compile(match_table,re.IGNORECASE)
    
    print ""
    print "***********SQL EXECUTIONS Info***********"
    
    try:
        #print "start"
        cursor.execute("""
            select distinct hash_value
                From stats$sqltext
                """)
        hash_val = cursor.fetchall()          
        
        for i in hash_val:
            cursor.execute("""
                select sql_text
                from  stats$sqltext
                where hash_value = :hash_value
                order by piece
            """,i)
            sql_piece = cursor.fetchall()
            sql_text = ''
            for j in sql_piece :
                sql_text = sql_text + "%s" %(j)
            sql_text = sql_text.replace('\n\r',' ')
            sql_text = " ".join(sql_text.split())  #SQL语句拼接并去除多余的空格
            if rx.search(sql_text) is not None:    #匹配表名,存储进映射KV关系  k是hash_val,v是对应完整的SQLTEXT
                dict[i] = sql_text.upper()
                
        for key in dict.keys():
            dict[key] = re.sub(match_join,' :1 ',dict[key])  #归一化
            #print dict[key]
            cursor.execute("""SELECT hash_value,case
            when max_exec > min_exec and min_exec > 0 then
            trunc((max_exec - min_exec) / decode(trunc(max_time)-trunc(min_time),0,1,trunc(max_time)-trunc(min_time)))
            when max_exec = min_exec and min_exec > 0 then max_exec
            else
            0
            end as exec_daily,
            trunc(max_time)-trunc(min_time) diff_days,
            to_char(min_time, 'yyyy-mm-dd') as begin_snap,
            to_char(max_time, 'yyyy-mm-dd') as end_snap fROM 
            (select A.*,
            row_number() OVER(partition by hash_value order by max_time desc) rn
            from (select s.hash_value,
               min(t.snap_time) over(partition by hash_value order by s.snap_id) as min_time,
               max(t.snap_time) over(partition by hash_value order by s.snap_id) as max_time,
               min(s.executions) over(partition by hash_value order by s.snap_id) as min_exec,
               max(s.executions) over(partition by hash_value order by s.snap_id) as max_exec
            from stats$sql_summary s, stats$snapshot t
            where s.snap_id = t.snap_id and s.Hash_value = :arg) a)B WHERE B.RN =1
            """,key)
            executions = cursor.fetchall()            
            #print executions
            for line in executions:
                sql_hash_val = line[0]
                exec_daily = line[1]
                snap_time = line[4]
                if exec_daily is not None:                    
                    if dict_table.has_key(dict[key]):
                        dict_table[dict[key]] = dict_table[dict[key]] + exec_daily
                        count[dict[key]] = count[dict[key]] + 1
                    else :
                        dict_table[dict[key]] = exec_daily
                        count[dict[key]] = 1
                #else:
                    #exec_daily = 0
        print ""
        
        for keys in dict_table:
            dict_table[keys] = dict_table[keys]/count[keys]
            #print count[keys]
            #print dict_table[keys]
        
        for i in  sorted(dict_table.items(),key=lambda e:e[1],reverse=True):
            print "** SQL EXECUTIONS: %d **" %i[1] 
            print "%s" %i[0] 
            print "" 

    except cx_Oracle.DatabaseError, exc:
            error, = exc.args
            print "sql_join error"
            print >> sys.stderr, "Oracle-Error-Code:", error.code
            print >> sys.stderr, "Oracle-Error-Message:", error.message

#--main--#
def main(cursor):
        db_table_info = table_info(cursor)
        db_index_info = index_info(cursor)
        db_sql_join = sql_join(cursor)

if __name__ == '__main__':
    conn = db_connect()
    cursor = conn.cursor()
    main(cursor)

Python&&cx_Oracle

Python版本:python2.7.2
Instantclient版本:Version 10.2.0.4
cx_Oracle版本:cx_Oracle-5.0.1
下载软件及工程目录:/home/oracle/LL/python/software(/workstation)

1. 查看系统版本选择合适版本
uname -a
Linux inc-dba-ccbu-36-18 2.6.9-67.ELsmp #1 SMP Wed Nov 7 13:56:44 EST 2007 x86_64 x86_64 x86_64 GNU/Linux

2. 下载安装python2.7.2 – 稳定版
# wget http://www.python.org/ftp/python/2.7.1/Python-2.7.1.tar.bz2
# tar -jxvf Python-2.7.1.tar.bz2
# cd Python-2.7.1
# ./configure (默认安装在/usr/local/lib/python2.7,–prefix可指定)
# make && make install

Continue reading

吉他

开始学吉他,作为一项爱好,决定全身心的投入进去,好让生活变得丰富起来。
谢谢@高阳同学的吉他,嘿嘿,弹起来感觉不错。
阿里十派乒乓球掌门人做偶的吉他老师,荣幸啊~
计划每天练习一小时的吉他,每周上一次课。
今天上完第二节课回来,和弦太疼了,手指疼,红红的,不能放弃噢~加油加油~
mark一下,下次来更新吉他笔记好了。

lesson1

1.吉他分类:根据不同的结构和发声原理可以大致分为木吉他(如古典吉他,钢弦吉他)和电吉他(如标准电吉他和低音电吉他)。根据演奏风格可以分为古典吉他、民谣吉他、弗拉门哥吉他、爵士吉他、夏威夷吉他及电吉他几个大类。
民谣吉他可细分为Acoustic guitar和Cutting down(缺角琴),前者适合演奏和弦,后者适合演奏高把位Solo。
我玩的吉他是民谣吉他,缺角琴。
2.乐理知识:
十二平均律–将一个八度平均分成十二个均等的音,其中每个音作为音高的最小单位,称作半音。
音–两个半音构成全音。(在键盘乐器上相邻的两个琴键(含黑键)互为半音。在吉他上相邻的两个品格互为半音,相隔一个品格为全音。在七个基本音中,Mi和Fa、Si和Do之间为半音,其余相邻的两音都是全音。

简谱  1      2    3     4    5    6    7
音名  C     D    E     F    G    A    B
唱名  Do Re Mi Fa  Sol  La  Si

度数–音程的单位称为度。音阶中同音之间的距离为一度。度数相同的两个音程所包含的全音和半音有时会有所不同。
音数–音程中全音和半音的数目。

音数       度数      性质      举例
0              一       纯一度     1-1,2-2,3-3,4-4,5-5,6-6,7-7
1/2          二       小二度     3-4,7-1
1               二       大二度     1-2,2-3,4-5,5-6,6-7
1 1/2       三       小三度     2-4,3-5,6-
1,7-2
2               三       大三度     1-3,4-6,5-7
2 1/2       四       纯四度     1-4,2-5,3-6,5-1,6-2,7-3
3               四       增四度      4-7
3 1/2       五       纯五度      1-5,2-6,3-7,4-1,5-2,6-3
3               五       减五度      7-4

品格–

 

Learning–shell(1)

shell执行一个程序时,会要求UNIX内核启动一个新的进程,以便在该进程里执行所指定的程序。
1.位于第一行的#!–内核会扫描该行其余部分,看是否存在可用来执行程序的解释权的完整路径
shell脚本通常一开始都是#! /bin/sh

2.变量:变量名=新值(可以为空值) 注:若所赋值内含有空格,加上引号  eg.fullname=”I am learning python”
需要使用变量时变量名称前面加上$字符,也可作为第二个变量的新值   eg.oldname=$fullname
连接不同的变量也需要引号  eg. fullname=”$first $middle $last”
Continue reading

where 1=1&&where 1=0

以下示例为ibatis文件。
–简介:iBatis 是一个开源的对象关系映射程序,着重于 POJO 与 SQL 之间的映射关系。使用时,开发者提供一个被称为 SQL 映射的 XML 文件,定义程序对象与 SQL 语句间的映射关系, iBatis 会根据 SQL 映射文件的定义,运行时自动完成 SQL 调用参数的绑定以及 JDBC ResultSet 到 Java POJO 之间的转换。
参考:扩展 iBatis 以透明支持多种数据库
Continue reading

Settle Down

终于安定下来,好让我有这闲情逸致在这码字,大清早的房东就过来装空调,迷迷糊糊的被折腾了一番也就不想再睡了。
到杭州有十天了,开始慢慢适应这里的环境,却还总是会找不着北。
公司里同事都很好相处,氛围也很好,但是自己又不善于交流,困扰困扰,也算明白什么叫学生气,就该是像我这样子了。很多东西需要学习的,作为女生的优势也是存在的,但是需要好好把握和使用。
谢谢那些关心我为我操心的盆友们,我已经安定下来啦,哈哈~
Continue reading