--same function different database: find the first 5 rows
?
select top 5 * from some_table???????????????????????????????????????? -- sql server
select * from some_table rownum >=1 and rownum<=5?? -- oracle (begin at 1)
?
select * from some_table limit 0, 5??????????????????????????????????? -- mysql (begin at 0)
?
select * from some_table limit 5 offset 0??????????????????????????? -- postgreSQL (begin at 0)
--however, if you want to implement between 10 to 20 in SQL SERVER, you have to use following trick
select top 10 * from
(select top 20 * from some_table) t
order by t.primary_key desc
posted @
2006-12-13 14:34 Jcat 閱讀(185) |
評論 (0) |
編輯 收藏
Most INSERT statements are the single-table variety, but Oracle also supports a multiple-table INSERT statement. With a multitable insert, you can make a single pass through the source data and load the data into more than one table.
[
ALL |
FIRST ]
WHEN condition THEN insert_into_clause [values_clause]
[insert_into_clause [values_clause]]...
[WHEN condition THEN insert_into_clause [values_clause]
[insert_into_clause [values_clause]]...
]...
[ELSE insert_into_clause [values_clause]
[insert_into_clause [values_clause]]...
]
If a WHEN condition evaluates to TRUE, the corresponding INTO clause is executed. If no WHEN condition evaluates to TRUE, the ELSE clause is executed.
The keyword ALL tells the database to check each WHEN condition. On the other hand, the keyword FIRST tells the database to stop checking WHEN conditions after finding the first TRUE condition.
--test?case
create?table?insert_test_case
(
id?number(1)
)

create?table?insert_test01
(
id?number(1)
)

create?table?insert_test02
(
id?number(1)
)

create?table?insert_test03
(
id?number(1)
)

insert?into?insert_test_case?values(1)
insert?into?insert_test_case?values(2)
insert?into?insert_test_case?values(3)
insert?into?insert_test_case?values(4)
insert?into?insert_test_case?values(5)
--3 rows inserted
insert?first?
??when?id=1?then?into?insert_test01?values(id)
??when?id=2?then?into?insert_test02?values(id)
??when?id=3?then?into?insert_test03?values(id)
select?id?from?insert_test_case

--3 rows inserted
insert?all
??when?id=1?then?into?insert_test01?values(id)
??when?id=2?then?into?insert_test02?values(id)
??when?id=3?then?into?insert_test03?values(id)
select?id?from?insert_test_case
--1 rows inserted
insert?first
??when?id=1?then?into?insert_test01?values(id)
??when?id=1?then?into?insert_test02?values(id)
??when?id=1?then?into?insert_test03?values(id)
select?id?from?insert_test_case

--3 rows inserted
insert?all
??when?id=1?then?into?insert_test01?values(id)
??when?id=1?then?into?insert_test02?values(id)
??when?id=1?then?into?insert_test03?values(id)
select?id?from?insert_test_case
posted @
2006-12-13 13:32 Jcat 閱讀(273) |
評論 (0) |
編輯 收藏
--
Test?Case
create
?
table
?sale(
sale_id?
char
(
1
)
,sale_type?
char
(
1
)
)
--
insert
?
into
?sale?
values
?(
'
a
'
,
'
Y
'
);
insert
?
into
?sale?
values
?(
'
b
'
,
'
N
'
);
insert
?
into
?sale?
values
?(
'
b
'
,
'
Y
'
);
insert
?
into
?sale?
values
?(
'
b
'
,
'
Y
'
);
insert
?
into
?sale?
values
?(
'
c
'
,
'
Y
'
);
insert
?
into
?sale?
values
?(
'
c
'
,
'
N
'
);
insert
?
into
?sale?
values
?(
'
d
'
,
'
N
'
);
insert
?
into
?sale?
values
?(
'
d
'
,
'
N
'
);
Count the number of 'Y' and the number of? 'N' separately
--
full?join
select
?
*
?
from
?
(
select
?sale_id,?
count
(
*
)?
as
?num_y?
from
?sale
where
?sale_type
=
'
Y
'
group
?
by
?sale_id
)?sale_y
full
?
join
(
select
?sale_id,?
count
(
*
)?
as
?num_n?
from
?sale
where
?sale_type
=
'
N
'
group
?
by
?sale_id
)?sale_n
using?(sale_id)
order
?
by
?sale_id
--
decode
select
?sale_id
?,
sum
(decode(sale_type,
'
Y
'
,
1
,
0
))?
as
?num_y??
--
note?using?sum?to?implement?count
,
sum
(decode(sale_type,
'
N
'
,
1
,
0
))?
as
?num_n
from
?sale
group
?
by
?sale_id
order
?
by
?sale_id
--
case
select
?sale_id
?,
sum
(
case
?
when
?sale_type
=
'
Y
'
?
then
?
1
?
else
?
0
?
end
)?
as
?num_y??
--
note?using?sum?to?implement?count
,
sum
(
case
?
when
?sale_type
=
'
N
'
?
then
?
1
?
else
?
0
?
end
)?
as
?num_n
from
?sale
group
?
by
?sale_id
order
?
by
?sale_id
Separate sale_type column
--
union?all
select
?sale_id,?sale_type?
as
?type_y,?
null
from
?sale
where
?sale_type
=
'
Y
'
union
?
all
select
?sale_id,?
null
,?sale_type?
as
?type_n
from
?sale
where
?sale_type
=
'
N
'
order
?
by
?sale_id
--
decode
select
?sale_id
,decode(sale_type,
'
Y
'
,
'
Y
'
,
null
) as type_y
,decode(sale_type,
'
N
'
,
'
N
'
,
null
) as type_n
from
?sale
?
--
case
select
?sale_id
,(
case
?
when
?sale_type
=
'
Y
'
?
then
?
'
Y
'
?
else
?
null
?
end
)?
as
?type_y
,(
case
?
when
?sale_type
=
'
N
'
?
then
?
'
N
'
?
else
?
null
?
end
)?
as
?type_n
from
?sale
posted @
2006-12-05 13:11 Jcat 閱讀(253) |
評論 (0) |
編輯 收藏
功能:5秒后,自動跳轉(zhuǎn)到同目錄下的02view.html文件
?
1)html的實現(xiàn)
<head>
<meta?http-equiv="refresh"?content="5;url=02view.html">
</head>優(yōu)點:簡單
缺點:Struts Tiles中無法使用
?
2)javascript的實現(xiàn)
<script?language="javascript"?type="text/javascript">
?? setTimeout("javascript:location.href='02view.html'",?5000);?
</script>
優(yōu)點:靈活,可以結(jié)合更多的其他功能
缺點:受到不同瀏覽器的影響
?
3)結(jié)合了倒數(shù)的javascript實現(xiàn)(IE)
<span?id="totalSecond">5</span>
<script?language="javascript"?type="text/javascript">
var?second?=?totalSecond.innerText;
setInterval("redirect()",?1000);
function?redirect(){?
totalSecond.innerText=--second;?
if(second<0)?location.href='02view.html';
}
</script>
優(yōu)點:更人性化
缺點:firefox不支持(firefox不支持span、div等的innerText屬性)
?
3')結(jié)合了倒數(shù)的javascript實現(xiàn)(firefox)
<script?language="javascript"?type="text/javascript">
????var?second?=?document.getElementById('totalSecond').textContent;
????setInterval("redirect()",?1000);
????function?redirect()
????{
????????document.getElementById('totalSecond').textContent?=?--second;
????????if?(second?<?0)?location.href?=?'02view.html';
????}
</script>
4)解決Firefox不支持innerText的問題
<span?id="totalSecond">5</span>
<script?language="javascript"?type="text/javascript">
if(navigator.appName.indexOf("Explorer")?>?-1){
????document.getElementById('totalSecond').innerText?=?"my?text?innerText";
}?else{
????document.getElementById('totalSecond').textContent?=?"my?text?textContent";
}
</script>
5)整合3)和3')
<span?id="totalSecond">5</span>
<script?language="javascript"?type="text/javascript">
????var?second?=?document.getElementById('totalSecond').textContent;
????if?(navigator.appName.indexOf("Explorer")?>?-1)
????{
????????second?=?document.getElementById('totalSecond').innerText;
????}?else
????{
????????second?=?document.getElementById('totalSecond').textContent;
????}
????setInterval("redirect()",?1000);
????function?redirect()
????{
????????if?(second?<?0)
????????{
????????????location.href?=?'02view.html';
????????}?else
????????{
????????????if?(navigator.appName.indexOf("Explorer")?>?-1)
????????????{
????????????????document.getElementById('totalSecond').innerText?=?second--;
????????????}?else
????????????{
????????????????document.getElementById('totalSecond').textContent?=?second--;
????????????}
????????}
????}
</script>
posted @
2006-11-22 17:20 Jcat 閱讀(16871) |
評論 (2) |
編輯 收藏
我們都知道SQL查詢過程中,單引號“'”是特殊字符,所以在查詢的時候要轉(zhuǎn)換成雙單引號“''”。
但這只是特殊字符的一個,在實際項目中,發(fā)現(xiàn)對于like操作還有以下特殊字符:下劃線“_”,百分號“%”,方括號“[]”以及尖號“^”。
其用途如下:
下劃線:用于代替一個任意字符(相當于正則表達式中的 ? )
百分號:用于代替任意數(shù)目的任意字符(相當于正則表達式中的 * )
方括號:用于轉(zhuǎn)義(事實上只有左方括號用于轉(zhuǎn)義,右方括號使用最近優(yōu)先原則匹配最近的左方括號)
尖號:用于排除一些字符進行匹配(這個與正則表達式中的一樣)
以下是一些匹配的舉例,需要說明的是,只有l(wèi)ike操作才有這些特殊字符,=操作是沒有的。
a_b...??????? a[_]b%
a%b...?????? a[%]b%
a[b...?????? a[[]b%
a]b...?????? a]b%
a[]b...????? a[[]]b%
a[^]b...???? a[[][^]]b%
a[^^]b...??? a[[][^][^]]b%
?
在實際進行處理的時候,對于=操作,我們一般只需要如此替換:
' -> ''
對于like操作,需要進行以下替換(注意順序也很重要)
[ -> [[]???? (這個必須是第一個替換的!!)
% -> [%]??? (這里%是指希望匹配的字符本身包括的%而不是專門用于匹配的通配符)
_ -> [_]
^ -> [^]
?
posted @
2006-11-16 18:31 Jcat 閱讀(2621) |
評論 (0) |
編輯 收藏
--查詢short_name有重的記錄
select short_name, count(*) from sys_catalog
group by short_name
having count(*)>1
?
--給short_name加上unique約束
alter table sys_catalog add unique (short_name)
--給column01加上check in約束
alter table son add constraint ck1 check (column01 in (1,2,3));
--查詢與當前系統(tǒng)時間最近的那個時間
select some_dt, sysdate-some_dt as gap from test_date
where sysdate-some_dt = (select min(abs(sysdate-some_dt)) from test_date)
--加字段
alter table?some_table add?some_column varchar2(20)
--找出所有包含_(下劃線)的字段;網(wǎng)上說用[_],但沒成功
select * from test_date where email like '%/_%' escape '/'
--啟動用戶
alter user scott account unlock;
--更改密碼
alter user scott indentified by tiger;
posted @
2006-11-15 13:50 Jcat 閱讀(227) |
評論 (0) |
編輯 收藏
In my opinion, SYSDBA and SYSOPER are system privileges.
You can find them by
select * from system_privilege_map where name like 'SYS%'As I know
1. schema: SYS, SYSTEM, SYSMAN
2. privilege: SYSDBA, SYSOPER
3. role: DBA
Note: The DBA role does not include the SYSDBA or SYSOPER system privileges.
-------------
sysdba、sysoper是一種很特殊的權(quán)限,可以啟動與關(guān)閉、創(chuàng)建與刪除數(shù)據(jù)庫等,不包含在dba權(quán)限之內(nèi)的。
兩個權(quán)限是超越數(shù)據(jù)庫的權(quán)限(新建,啟動,關(guān)閉數(shù)據(jù)庫),在數(shù)據(jù)庫之上,所以dba_roles中沒有(??)。
只要用internal用戶將此權(quán)限授給其它的用戶就可以用此用戶加 as sysdba 登錄,可以關(guān)閉和啟動數(shù)據(jù)庫了。并可以進行oracle DBA所不能做的操作。
授權(quán):
SQL> grant sysdba,sysoper to jcat
收回權(quán)限:
SQL> revoke sysdba from jcat
查看這兩個權(quán)限的擁有情況(需一定的權(quán)限,sys就可以看):
SQL> select * from v$pwfile_users
-------------
?
sysdba 擁有最高的系統(tǒng)權(quán)限 (sysdba的權(quán)限包含所有sysoper的權(quán)限)
sysoper主要用來啟動、關(guān)閉數(shù)據(jù)庫
相比之下,SYSDBA比SYSOPER多了兩個權(quán)限:
?1)change character set,改變字符集設(shè)置;
?2)CREATE DATABASE,創(chuàng)建數(shù)據(jù)庫。
?
sysoper登陸后用戶是 public
sysdba 登陸后是 sys
可以通過以下方式進行驗證:
SQL> conn test/test as sysoper;
SQL> show user
USER 為"PUBLIC"
?
SQL> conn test/test as sysdba
SQL> show user
USER 為"SYS"
posted @
2006-10-25 15:12 Jcat 閱讀(562) |
評論 (0) |
編輯 收藏
After a new database built, confirm following tools is working.
?
1. sqlplus
./sqlplus
connect system/******
?
2. isqlplus
http://localhost:5560/isqlplus
username=system
password=******
?
3. TNS
./lsnrctl
start
?
4. em
http://localhost:5500/em
username=system
password=******
posted @
2006-10-23 16:01 Jcat 閱讀(238) |
評論 (0) |
編輯 收藏
Linux下常用壓縮格式的壓縮與解壓方法
|
???? 大致總結(jié)了一下linux下各種格式的壓縮包的壓縮、解壓方法。但是部分方法我沒有用到,也就不全,希望大家?guī)臀已a充,我將隨時修改完善,謝謝! 作者:Linux愛好者 來自:www.LinuxByte.net 最后更新時間:2003-12-1
.tar 解壓:tar xvf FileName.tar 壓縮:tar cvf FileName.tar DirName (注:tar是打包,不是壓縮!) --------------------------------------------- .gz 解壓1:gunzip FileName.gz 解壓2:gzip -d FileName.gz 壓縮:gzip FileName .tar.gz 解壓:tar zxvf FileName.tar.gz 壓縮:tar zcvf FileName.tar.gz DirName --------------------------------------------- .bz2 解壓1:bzip2 -d FileName.bz2 解壓2:bunzip2 FileName.bz2 壓縮: bzip2 -z FileName .tar.bz2 解壓:tar jxvf FileName.tar.bz2 壓縮:tar jcvf FileName.tar.bz2 DirName --------------------------------------------- .bz 解壓1:bzip2 -d FileName.bz 解壓2:bunzip2 FileName.bz 壓縮:未知 .tar.bz 解壓:tar jxvf FileName.tar.bz 壓縮:未知 --------------------------------------------- .Z 解壓:uncompress FileName.Z 壓縮:compress FileName .tar.Z 解壓:tar Zxvf FileName.tar.Z 壓縮:tar Zcvf FileName.tar.Z DirName --------------------------------------------- .tgz 解壓:tar zxvf FileName.tgz 壓縮:未知 .tar.tgz 解壓:tar zxvf FileName.tar.tgz 壓縮:tar zcvf FileName.tar.tgz FileName ---------------------------------------------
.a
解壓:#tar xv file.a
---------------------------------------------
.cpio.gz/.cgz
解壓:gzip -dc file.cgz | cpio -div
---------------------------------------------
.cpio/cpio
解壓:cpio -div file.cpio 或cpio -divc file.cpio
---------------------------------------------
.rpm
安裝: rpm -i file.rpm 解壓:rpm2cpio file.rpm | cpio -div
---------------------------------------------
.deb
安裝:?dpkg -i file.deb
解壓:dpkg-deb --fsys-tarfile file.deb | tar xvf - ar p file.deb data.tar.gz | tar xvzf - ---------------------------------------------
.zip
解壓:unzip FileName.zip 壓縮:zip FileName.zip DirName --------------------------------------------- .rar 解壓:rar a FileName.rar 壓縮:rar e FileName.rar
rar請到:http://www.rarsoft.com/download.htm 下載! 解壓后請將rar_static拷貝到/usr/bin目錄(其他由$PATH環(huán)境變量指定的目錄也可以): [root@www2 tmp]# cp rar_static /usr/bin/rar --------------------------------------------- .lha 解壓:lha -e FileName.lha 壓縮:lha -a FileName.lha FileName
lha請到:http://www.infor.kanazawa-it.ac.jp/~ishii/lhaunix/下載! 解壓后請將lha拷貝到/usr/bin目錄(其他由$PATH環(huán)境變量指定的目錄也可以): [root@www2 tmp]# cp lha /usr/bin/ --------------------------------------------- .tar .tgz .tar.gz .tar.Z .tar.bz .tar.bz2 .zip .cpio .rpm .deb .slp .arj .rar .ace .lha .lzh .lzx .lzs .arc .sda .sfx .lnx .zoo .cab .kar .cpt .pit .sit .sea 解壓:sEx x FileName.* 壓縮:sEx a FileName.* FileName
sEx只是調(diào)用相關(guān)程序,本身并無壓縮、解壓功能,請注意! sEx請到:http://sourceforge.net/projects/sex下載! 解壓后請將sEx拷貝到/usr/bin目錄(其他由$PATH環(huán)境變量指定的目錄也可以): [root@www2 tmp]# cp sEx /usr/bin/
參考文獻:Linux 文件壓縮工具指南 (其實看幫助是最好的方法,一般各個命令都可以用“--help”參數(shù)得到常用使用方法!)
|
posted @
2006-10-19 00:33 Jcat 閱讀(478) |
評論 (0) |
編輯 收藏
select * from user_objects
查看當前數(shù)據(jù)庫的所有對象(表、視圖、過程……)
describe AA顯示表AA的信息(字段名、類型……)
select * from AA where rownum=1返回結(jié)果集中的第一行
show parameter para_name???
不等同于?? select para_name from v$instance查看初始化參數(shù) (省略para_name可以查看所有的初始化參數(shù))
alter system set para_name = some_value scope = both修改初始化參數(shù)
select * from v$database
查看物理數(shù)據(jù)庫的信息
alter database xxxx對數(shù)據(jù)庫進行結(jié)構(gòu)性修改
sql>archive log list查看redo log的信息
posted @
2006-10-10 16:41 Jcat 閱讀(221) |
評論 (0) |
編輯 收藏