首先聲明,我使用的是Informix7.x版本,
1、不等于 :<>
2、判斷是否為空:is null
3、nvl函數(shù)
NVL(expr1,expr2):如果expr1是NULL,則返回expr2,否則返回expr1.返回值與expr1類(lèi)型相同,除非expr1是字符串類(lèi),在這種情況下將返回VARCHAR2類(lèi)型.這個(gè)函數(shù)用于確保查詢記錄集中不包含NULL值。
NVL(expr1,expr2,expr3) :如果expr1是NULL,則返回expr2,否則返回expr3.返回值與expr2類(lèi)型相同,除非expr2是字符類(lèi)型,在這種情況下返回VARCHAR2類(lèi)型;
NULLIF(a,b) :如果a等于b返回NULL,如果不等于返回b。
4、substr()函數(shù)
substr(str,startindex,count);其他數(shù)據(jù)庫(kù)一般用substring(str,startindex,count);
5、string轉(zhuǎn)換成sql的date型:to_date('2006-12-25','%Y-%m-%d');
6、得到昨天的日期:today-1
7、查看sql的執(zhí)行過(guò)程:
1)登錄:su - informix
2)建立SQL文件,里面放要執(zhí)行的sql語(yǔ)句,同時(shí)在前面加一行,set explain on;sql 語(yǔ)句;
3)導(dǎo)入sql文件執(zhí)行:isql -s databasename<filename
4)查看執(zhí)行過(guò)程:cat sqexplain.out
8、使用臨時(shí)表:
into temp tablename with no log ;最好加上with no log;
9、建立存儲(chǔ)過(guò)程:
1)文件命名為zeng.sql
drop procedure zeng;
create procedure zeng(deptstr varchar(20),time1 char(10),time2 char(10))
returning decimal(14,2);
define mysum decimal(14,2);
select a.ownid,a.masterid,c.sendsum from distribute a,order_bankbill b,bankbill c where a.orderid=b.orderid and b.bankbillid=c.id and a.deptno=deptstr and c.sendtime >=time1 and c.sendtime <=time2 into temp mytemp with no log ;
select nvl(sum(sendsum),0) into mysum from mytemp where ownid=masterid;
return mysum WITH RESUME;
end procedure
2)導(dǎo)入到數(shù)據(jù)庫(kù):
dbaccess databasename zengchao.sql
3)進(jìn)入數(shù)據(jù)庫(kù),執(zhí)行
dbaccess databasename
……
execute procedure zeng ('00xm010101','2006-03-01','2006-03-25');
10、update的一種用法
update distribute set (masterid,mastername)=
((select nvl(groupmanager,0),nvl(groupmanagername,'') from department where distribute.deptno=department.departmentno ))
where opertime>='2007-02-11';//注意后面不要漏掉一層括號(hào)
11、unique與distinct的區(qū)別:
unique是distinct的同義詞,功能完全相同。distinct是標(biāo)準(zhǔn)語(yǔ)法,其他數(shù)據(jù)庫(kù) sql server,db2,oracle,sybase,mysql等都支持。unique,informix數(shù)據(jù)庫(kù)認(rèn)識(shí),其他數(shù)據(jù)庫(kù)有的認(rèn)識(shí),有的不認(rèn)識(shí)。
12、Case語(yǔ)句用法:
select name,case when id=9188 then 'ttt' else name end from employee where departmentno ='00xm';
13、使用優(yōu)化器(update statistics):
優(yōu)化使系統(tǒng)表的信息與實(shí)際一致,使搜索樹(shù)的路徑最優(yōu)。同時(shí),整理索引樹(shù)。例:
1. update statistics for table
2. update statistics for procedure
3. update statistics for table rta1(bm_cert)
4. update statistics high for table rta1(bm_cert) resolution 0.5
14、連接字符串(||):
select id ||':'|| name from employee
15、JDBC事務(wù)與游標(biāo)
注意要先關(guān)閉ResultSet然后提交事務(wù);
16、informix備份表數(shù)據(jù)(isql)
1)導(dǎo)出:unload to "zengchao.data" select * from position;
2)導(dǎo)入:load from "zengchao.data" insert into position;
17、關(guān)于like與[]
select count(*) from employee where departmentno like '00xm01%';
select count(*) from employee where departmentno[1,6]='00xm01';
這兩條語(yǔ)句,執(zhí)行差不多,但是估計(jì)成本是第二個(gè)比第一個(gè)好
18、informix下更改表名
update systables set tabname='oldredeploy' where tabname='redeploy';
19、count(name)與count(*)區(qū)別
如果name列有null值,那么如下兩條語(yǔ)句得到的返回值不等
select count(*) from tablename
select count(name) from tablename
20、鎖表的解決方法(轉(zhuǎn))
1、找到被鎖表的partnum:select hex(partnum) from systables where tabname = ”tabalname”;
2、onstat -k|grep partnum 找到該鎖的owner;
3、onstat -u | grep owner 找到用戶會(huì)話session號(hào);
4、onmode -z sesid 殺掉該session;
5、如果第4步失敗,則進(jìn)一步onstat -g ses | grep sesid 找到該發(fā)起該會(huì)話的pid;
6、kill pid 或 kill -9 pid;
7、特殊情況:在第2步中,如果發(fā)現(xiàn)鎖的owner為0,則檢查:
onstat -x
onstat -G
看是否存在全局事務(wù),若有全局事務(wù),則繼續(xù)以下步驟:select hex(tx_addr) trans_addr,hex(tx_lklist) lock_addr from systrans where hex(tx_addr) like '%c000000007674c58%';需要說(shuō)明的是,c000000007674c58是使用onstat -x 或 onstat -G得到的全局事務(wù)的地址。上面SQL語(yǔ)句提供出該全局事務(wù)對(duì)應(yīng)的鎖地址,這時(shí)如果得到的鎖地址與鎖表的鎖地址相同的話,你就必需從應(yīng)用端(通常是三層結(jié)構(gòu)的中間件)發(fā)命令讓該全局事務(wù)回滾或提交,否則該鎖會(huì)被一直持有,直到你執(zhí)行oninit -i。
21、從數(shù)據(jù)庫(kù)的數(shù)據(jù)導(dǎo)成Excel格式
方法一:
1)導(dǎo)成csv文件:isql -s databasename unload to data.csv select * from tablename;
2)轉(zhuǎn)換成Excel:用Excel中的“數(shù)據(jù)”->“導(dǎo)入外部數(shù)據(jù)”->“導(dǎo)入文本文件”,選擇分隔符為'|';
方法二:
用Excel中的“數(shù)據(jù)”->“導(dǎo)入外部數(shù)據(jù)”->“新建數(shù)據(jù)庫(kù)查詢”,然后配置數(shù)據(jù)源
22、配置Informix-CLI
1、配置Informix-Setnet32

上面的czzymis修改為online_web

2)配置Odbc-Administrator
a)新建一用戶DNS

b)配置DNS

c)高級(jí)屬性
23、系統(tǒng)表(syscolumns)中字段類(lèi)型(coltype)字段的含義
coltype定義在informix/incl/esql/sqltypes.h文件中,如下圖

注意:如果,某字段要求非空,則在原類(lèi)型上加256。例如,SERIAL對(duì)應(yīng)的是6,SERIAL not NULL類(lèi)型對(duì)應(yīng)的是(6+256)=262。
24、常用函數(shù)(來(lái)自網(wǎng)絡(luò))
聚集函數(shù):
avg,求平均值
count,統(tǒng)計(jì)記錄的條數(shù)
max,求最大值
min,求最小值
range,計(jì)算所選行的最大值與最小值的差
stdev,計(jì)算所選行的標(biāo)準(zhǔn)偏差
sum,求和函數(shù)
variance,函數(shù)返回值樣本的方差做為所有選擇行的方差的無(wú)偏估計(jì)。公式,(sum(xi**2)-sum(xi)**2)/N)/(N-1),其中xi是列中的每個(gè)值,N是列中值的總和。

時(shí)間函數(shù):
day,mdy,month,weekday,year 這些函數(shù)返回與用來(lái)調(diào)用函數(shù)的表達(dá)式或自身變量的值。Current返回當(dāng)前的日期和時(shí)間值,可以用extend函數(shù)來(lái)調(diào)整date或datetime值的精度。使用day和current 函數(shù)來(lái)將列值與當(dāng)前日期進(jìn)行比較。
date函數(shù)將字符串函數(shù)轉(zhuǎn)換為DATE值。例date(‘12/7/04’)
to_char函數(shù)將datetime和date值轉(zhuǎn)化為字符值。
to_date函數(shù)將字符值轉(zhuǎn)化為datetime類(lèi)型的值。例to_date(“1978-10-07 10:00” ,”%Y-%m-%d %H:%M)

基數(shù)函數(shù):
cardinality(僅適用IDS)函數(shù)對(duì)集合包含的元素?cái)?shù)目計(jì)數(shù)。

智能大對(duì)象函數(shù)(僅適用與IDS):
filetoblob( ),將文件復(fù)制到BLOB列中
filetoclob( ),將文件復(fù)制到CLOB列中
locopy( ),將BLOB或CLOB類(lèi)型的數(shù)據(jù)復(fù)制到另一個(gè)BLOB或CLOB列中
lotofile( ),將BLOB或CLOB復(fù)制到文件中

字符串處理函數(shù):
lower,將字符串中每個(gè)大寫(xiě)字母轉(zhuǎn)換為小寫(xiě)字母
upper,將字符串中每個(gè)小寫(xiě)字母轉(zhuǎn)換為大寫(xiě)字母
initcap,將字符串中每個(gè)詞的首寫(xiě)字母轉(zhuǎn)換成大寫(xiě)
replace,將字符串中的某一組字符轉(zhuǎn)換成其他字符,例replace(col,'abc','')
substr,返回字符串中的某一部分,例substr(col,1,2)
substring,返回字符串中的某一部分,例substring(col,from 1 to 4)

其他函數(shù):
hex,返回表達(dá)式的十六進(jìn)制數(shù)
round,返回表達(dá)式的四舍五入值
trunc,返回表達(dá)式的截?cái)嘀?br />
length,計(jì)算表達(dá)式的長(zhǎng)度
user,返回執(zhí)行查詢的用戶的用戶名(登陸帳戶名)
today,返回當(dāng)前系統(tǒng)日期
dbservername,返回?cái)?shù)據(jù)庫(kù)服務(wù)器的名稱,同sitename
dbinfo,返回?cái)?shù)據(jù)庫(kù)的相關(guān)信息
decode,函數(shù)來(lái)將一個(gè)具有一個(gè)值的表達(dá)式轉(zhuǎn)換為另一個(gè)值
decode(test,a,a_value,b,b_value,c,c_value……),decode函數(shù)不支持TEXT和BYTE類(lèi)型。
nvl,來(lái)將求值為空的表達(dá)式轉(zhuǎn)化為另一個(gè)想要指定的值。
25、修改/添加表的列的屬性
例如:alter table student modify studentno integer not null;
alter table student add sex char(1) not null;
26、導(dǎo)出數(shù)據(jù)庫(kù)的表結(jié)構(gòu)
導(dǎo)出特定的某個(gè)表:dbschema -t tabname -d databasename tarfilename
導(dǎo)出整個(gè)數(shù)據(jù)的所以表:dbschema -d databasename tarfilename
posted on 2007-09-05 15:29
破繭而出 閱讀(1773)
評(píng)論(0) 編輯 收藏 所屬分類(lèi):
數(shù)據(jù)庫(kù)