搜尋此網誌

2013年6月30日 星期日

ORACLE 12C 12項強化功能之一 建TABLE 時可以直接用Sequence

oracle 12c database new features Oracle 12項 資料庫新特性 
Default value of column can use a sequence.nextval
在以往ORACLE 9i ,10g,11g  建sequence 都要建一個Trigger 將Seqence  作改變 


參考Create table with default sequence
 Creating a Table with a DEFAULT ON NULL Column Value: Example 
The following statement creates a table myemp, which can be used to store employee data. The department_id column is defined with a DEFAULT ON NULLcolumn value of 50. Therefore, if a subsequent INSERT statement attempts to assign a NULL value to department_id, then the value of 50 will be assigned instead.

CREATE TABLE myemp (employee_id number, last_name varchar2(25),
                    department_id NUMBER DEFAULT ON NULL 50 NOT NULL);

以上官網的範例 
以下我作個實際範例 

create table example (
production varchar2(100),
productioserial number default on null 1 not null);



insert into example(production) values('item2');
commit;
insert into example(production) values('item2'); commit;


select * from example;
Results :  看樣子是會帶DEFAULT 值出 ,可是這不是我要的自動增加 
PRODUCTION  PRODUCTIOSERIAL
----------------------------------------------------------------
item1     1 
item2     1

CREATE TABLE example2 (productname varchar2(100),serial NUMBER GENERATED BY DEFAULT AS IDENTITY (START WITH 1 INCREMENT BY 1));

insert into example2(productname) values ('itema');
 insert into example2(productname) values ('itemb');

PRODUCTNAME               SERIAL
--------------------------------
itema                          1 
itemb                          2 




 

可以exclude 特定目錄的copy 程式

因為之前有同事說Linux  下的cp 無法排除特定目錄,所以我就用python2.7 寫了隻  ohCP
給他用

#!/usr/bin/python2.7
import os,time,shutil,argparse,sys
def exculde_cp(source,dest,exclude):
print(source)
if os.path.isdir(source) == True or os.path.isfile(source)==False:
print(source)
dirnames=os.listdir(source)
for dirname in dirnames:
print(dirname)
srcname=os.path.join(source,dirname)
dstname=os.path.join(dest,dirname)
try:
if srcname == exclude:
pass
elif os.path.islink(srcname):
print('detect dirs has some links')
linkto = os.readlink(srcname)
os.symlink(linkto, dstname)
else:
print('begin copy dir',dirname)
shutil.copytree(srcname,dstname)

except (IOError, os.error) as why:
print('some errors',why)
elif os.path.isdir(source) == False or os.pathisfile(source):
try:
shutil.copy2(source,dest)
except (IOError, os.error) as why:
print('some errors',why)
###
def cop(source,dest):
if os.path.isdir(source) == True or os.path.isfile(source)==False:
print(source)
dirnames=os.listdir(source)
for dirname in dirnames:
print(dirname)
srcname=os.path.join(source,dirname)
dstname=os.path.join(dest,dirname)
try:
if os.path.islink(srcname):
print('detect dirs has some links')
linkto = os.readlink(srcname)
os.symlink(linkto, dstname)
else:
print('begin copy dir',dirname)
shutil.copytree(srcname,dstname)
except (IOError, os.error) as why:
print('some errors',why)
elif os.path.isdir(source) == False or os.pathisfile(source):
try:
print('copy file from:',source,'to dest:',dest )
shutil.copy2(source,dest)
except (IOError, os.error) as why:
print('some errors',why)
parser = argparse.ArgumentParser()
parser.add_argument('-src:', dest='src',help='ohCP.py -src: /home/usera/ -dst: /home/userb',nargs='*')
parser.add_argument('-dst:', dest='dst',help='ohCP.py -src: /home/usera/ -dst: /home/userb',nargs='*')
parser.add_argument('-exclude:',dest='exclude',help='ohCP.py -src: /home/usera/ -dst: /home/userb -exclude: /home/usera/userc',nargs='*')
try:
parameter=parser.parse_args()
source=parameter.src
dest=parameter.dst
exclude=parameter.exclude
print(parameter)
except TypeError:
print('Input ohCP.py -help')

if source is not None and dest is not None and exclude  is not None:
exculde_cp(source[0],dest[0],exclude[0])
elif exclude is not None and source is not None and dest is not None:
cop(source[0],dest[0])
else:
print('type ohCP.py -help')

Install ORACLE 12C (安裝12C 部份畫面)







2013年3月22日 星期五

How to USE python to find out /etc/hosts ip

import os,re tt2=open('/etc/hosts','r')
for s in tt2: #ip hostname pattern as \d+.\d+.\d+.\d \d means number
     matchObj = re.match( r'\d+.\d+.\d+.\d+\t\w+',s)
        if matchObj:
           print "matchObj.group() : "matchObj.group().split('\t')

2013年3月20日 星期三

PARAMETER PARSE

import platform,sys,os,fileinput,re global dstconfig,org_pattern,chg_pattern,srcconfig,org_pattern srcconfig='' org_pattern='' dstconfig='' org_pattern='' patternfs="/Users/Hermes/Downloads/srt.txt" def get_ip(): bond1_dst='/etc/sysconfig/network-scripts/ifcfg-bond1' eth1_dst='/etc/sysconfig/network-scripts/ifcfg-eth1' if os.path.isfile(bond0_dst) == True: temp=open(bond1_dst,'r') text=temp.read() ip_tmp=str(re.findall('IPADDR=\d+.\d+.\d+.\d+',text)) ip=ip_tmp.rsplit('IPADDR=') elif os.path.isfile(bond1_dst) == False and os.path.isfile()==True: temp=open(eth01_dst,'r') text=temp.read() ip_tmp=str(re.findall('IPADDR=\d+.\d+.\d+.\d+',text)) ip=ip_tmp.rsplit('IPADDR=') else: print('some wrong') def change_file(srcconfig,org_pattern,chg_pattern): changing_file_dst='/Users/Hermes/Downloads/srt.txt' changefile=fileinput.input(srcconfig, inplace=1) #results=re.sub(stringa,replace,changefile) result=st.replace(pattern,replace_str) changefile.close() def paramter_parse(patternfs): ofs=open(patternfs) for s in ofs: parameter=tuple(s.split('::')) print(parameter) print(range(len(parameter))) if len(parameter)

2013年3月17日 星期日

How to use python replace a word as sed does

import os,fileinput 
changing_file_dst='/Users/Hermes/Downloads/srt.txt' changefile=fileinput.input(changing_file_dst, inplace=1)
 # <==this is part very import if you just fileinput.input(change_file_dst) data will not modified , so you need set inplace=1 to modify current file 
for st in changefile:
 replace_str='cluster.enabled=true'
 pattern='cluster.enabled=false'
 result=st.replace(pattern,replace_str)
 print(result) changefile.close()

 original I just want use open , but when I write all file will be truncate and write . so I use fileinput.
原本是用open 將檔案 打開修改可是用 W mode 會因為先作truncated , 再寫入所以檔案會被清空 ,所以改用 fileinput 直接作修改

2010年12月22日 星期三

BULLYING

BULLYING is a operation when strong man ask weaker money and do something bad .
It is a Normal status in high school . why kind of emotions let bullying more common on Taiwan Education. it is a shame thing. especially some one don't interrupter up that kind of things.