搜尋此網誌

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 部份畫面)