Oracle基本操作

2022-08-27 15:09:13 字數 2340 閱讀 8549

檢視資料庫字符集編碼

select userevn('language') from dual;

oracle常用函式:

lower('aaaaa'),將字元全部轉換成小寫

upper('aaaaasss'),將字元全部轉換成大寫

initcap('atsichuan chengdu'),每個字元首字母大寫

concat('hello', 'world'),連線2個字元

substr('atsichuan', 1, 5),從第一位開始擷取5位

instr('helloworld','o'),字元第一次出現『o』的位置

length('helloworld'),字元長度

trim(' hellow world '),去掉字元首尾空格 trim('h' from 'hellohworldh') 去掉字元首尾的h--(ellohworld),說明trim只能去掉字元首尾,中間的不能去掉

lpad('sss', 5, '&'),左對齊(&&sss)

rpad('ccc', 5, '*'),右對齊(ccc**)

replace('ancasa', 'a', 'd')將字元中的a替換成d

轉換成金額型 to_char(salary,'$99999999.99')

round四捨五入 round(157.9321)---158 round(157.9321,2)--157.93 round(157.9321,-2)--100

trunc截斷 trunc(69.9923, 2)---69.99 trunc(69.9923)---69 trunc(69.9923, -1)---60

mod求餘 mod(1600, 300)---100

日期函式

months_between(sysdate,hire_date) 2個日期之間相差的月份數

add_months 新增月份 add_months(sysdate,2)---- 2017/12/12 10:52:34 add_months(sysdate,-3)---2017/7/12 10:52:34 (sysdate是20171012)

next_day(sysdate,'星期四') 下乙個星期的某一天的日期(sysdate是20171012)

last_day 指本月最後一天 last_day(sytsdate)---31 (sysdate是20171012)

round(sysdate,'mm') ---20171001 round(sysdate,'month')---20171001

trunc(sysdate,'year')---2017/1/1 trunc(sysdate,'mm')--2017/10/1 trunc(sysdate,'dd') --2017/10/12 trunc(sysdate,'hh')---2017/10/12 11:00:00

wm_concat 該函式可將查詢結果放在乙個單元格中;

decode(欄位或字段的運算,值1,值2,值3)

這個函式的執行的結果是,當字段或字段的運算的值等於值1時,該函式返回值2,否則返回值3.

decode(條件,值1,返回值1,值2,返回值2,值3,返回值3……值n,返回值n,預設值)

該函式的含義如下:

if 條件=值1 then

return 返回值1

if 條件=值2 then

return 返回值2

if 條件=值3 then

return 返回值3

....

else if 條件=值n then

return 返回值n

else

return 預設值

end if

merge into 的用法

merge 的基本語法:

merge into table[alias]

using table or sql query[alias]

on condition

when matched then

update set.....

when not matched then

insert values....

truncate table 命令將快速刪除資料表中所有的記錄,但保留資料表結構。其刪除的資料是不可以恢復的。(刪除速度非常快)

delete from table 命令刪除的資料儲存在系統回滾段中,即資料是可以恢復的。

drop table將刪除表的結構被依賴的約束(constrain)、觸發器(trigger)、索引(index);依賴於該錶的儲存過程/函式將保留,但是變為invalid狀態。

exits

between and 在兩個值之間 (包含邊界)

Oracle基本操作

1.建立表空間 create tablespacetestdatafile c test.dbf size 10m 名字不要為數字 2.建立使用者 create user username identified by password 不要為數字 3.給使用者授權 grant dba to user...

Oracle 基本操作

在這裡詳述 oracle 基本操作。新增使用者 隨著使用者的建立,自動產生與使用者同名的schema create user tester profile default identified by tester default tablespace testdata temporary table...

oracle 基本操作

1 使用者登入 sqlplus 帳號 密碼 2 檢視當前登入使用者 show user 3 檢視所有的使用者 select username from all users 4 建立臨時表空間 create temporary tablespace test temp tempfile d oracl...