Oracle数据库基本概念理解(1)
生活随笔
收集整理的這篇文章主要介紹了
Oracle数据库基本概念理解(1)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
--函數(shù) 數(shù)字轉(zhuǎn)換為字符
--0 強(qiáng)制位數(shù),9位數(shù)不夠不顯示 $美元
SELECT TO_CHAR(124.3456,'0000.00') FROM dual ;
SELECT TO_CHAR(124.3456,'9999.99') FROM dual ;
SELECT TO_CHAR(124.3456,'$9999.99') FROM dual ;
--日期 日期轉(zhuǎn)換為字符
SELECT TO_CHAR(SYSDATE,'YYYY-MM-DD HH:MI:SS') FROM dual ;
SELECT TO_CHAR(SYSDATE,'YYYY"年"MM"月"DD"日" HH:MI:SS') FROM dual;
--字符轉(zhuǎn)換為日期
SELECT TO_DATE('2005-12-06','yyyy-mm-dd') FROM dual;
--常用的偽列 rowid rownum
select rowid,emp.* from scott.emp;
select rownum,emp.* from scott.emp;
--查詢 第三行數(shù)據(jù)
select * from (select rownum rnum,s.* from scott.emp s ) where rnum=3;
--轉(zhuǎn)換空值的函數(shù) NVL(EXP1, EXP2)select emp.* from scott.emp;
select nvl(comm,0) from scott.emp;
--去除重復(fù)行
select distinct job from scott.emp;
--根據(jù)現(xiàn)有表創(chuàng)建表
create table emp
as
select * from scott.emp;--當(dāng)前用戶表行數(shù)大于10行的表
select table_name from user_all_tables a
where a.num_rows>10 ;
--
select * from sun.tuser;
--事務(wù)控制
insert into sun.tuser(userid,username,pwd)
values(18,'1777','1777');
savepoint aa; --保存事物點(diǎn)
insert into sun.tuser(userid,username,pwd)
values(19,'1777','1777');
rollback to aa; --回滾到保存的事物點(diǎn)
select * from sun.tuser;
commit--提交事務(wù)
--集合操作符
--1.union 聯(lián)合
select * from scott.emp;
select count(*) from scott.emp
select * from scott.emp
union
select * from scott.emp
where job='CLERK'
--UNIONALL 聯(lián)合所有
select * from scott.emp
union ALL
select * from scott.emp
where job='CLERK'
--INTERSECT 交集
select * from scott.emp
INTERSECT
select * from scott.emp
where job='CLERK'
--MINUS 減集
select * from scott.emp
MINUS
select * from scott.emp
where job='CLERK'
--\\ 連接符號(hào),類似 +;
--分析函數(shù)
--row_number 排名有相同數(shù)據(jù)時(shí)排名遞增
--dense_rank 排名有相同數(shù)據(jù)時(shí)排名一樣
--rank 排名有相同數(shù)據(jù)時(shí)排名一樣,但在下一個(gè)不同數(shù)據(jù)空出排名
select ename, job,sal,row_number()over(partition by job order by sal desc ) "number",dense_rank()over(partition by job order by sal desc ) "dense_rank",rank()over(partition by job order by sal desc ) "rank"from emp;
--
select ename, job,sal,row_number()over( order by sal desc ) "number",dense_rank()over(order by sal desc ) "dense_rank",rank()over( order by sal desc ) "rank"from emp;
總結(jié)
以上是生活随笔為你收集整理的Oracle数据库基本概念理解(1)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: java通过commons-fileup
- 下一篇: Oracle数据库基本概念理解(2)