本文主要用于记录常用的Oracle基本命令,由于多使用图形工具进行查询,命令使用较少,便于个人在以后使用时参考,其中有不正确的地方请指正。
本文主要用于记录常用的Oracle基本命令,由于多使用图形工具进行查询,命令使用较少,便于个人在以后使用时参考,其中有不正确的地方请指正。
1.查看Oracle版本
select * from product_component_version;
2.表管理命令
创建table:
1 | CREATE TABLE AAA(AA VARCHAR (5),BB VARCHAR (10), CC VARCHAR (90)); |
删除table:
1 | DROP TABLE AAA; |
增加column:
1 | ALTER TABLE AA ADD FNAME NUMBER NOT NULL; |
增加value
1 | INSERT INTO AA (A, B) VALUES ('12345', '9099889'); |
更新value
1 | UPDATE AA SET A = '000' WHERE AA.B = '9'; |
删除value
1 | DELETE FROM IPOUSER.AA WHERE AA.A = '00000'; |
3.表查询命令
基础查询:
1 | SELECT A.B.FCODINGS AS 代码,A.B.FNAME AS 名称 FROM A.B; |
BETWEEN用法:
1 | SELECT A.B.C,A.B.D FROM A.B WHERE A.B.C BETWEEN '210882' AND '250883'; |
AND和OR用法:
1 | SELECT * FROM A.B WHERE A.B.FKINDNAME = 'ABC' AND (A.B.FNAME = '威克岛' OR A.B.FNAME = '津巴布韦'); |
ORDER BY用法:
1 | SELECT * FROM A.B ORDER BY A.B.FID ASC; |
ROWNUM用法:
1 | SELECT * FROM A.B WHERE ROWNUM <= 10; |
LIKE用法:
1 | SELECT * FROM A.B WHERE A.B.FNAME LIKE '_南省%'; |
IN用法:
1 | SELECT * FROM A.B WHERE FNAME IN ('河南省郑州市', '河南省洛阳市'); |
4.数据去重
1 | SELECT DISTINCT NAME FROM USER.NAME; |
5.数据去重并统计数量
1 | SELECT COUNT(*) AS NUM FROM (SELECT DISTINCT NAME FROM USER.NAME); |
6.用户赋权限
1 | GRANT SELECT ON USER.NAME TO ADMIN; |
7.多表联合查询
1 | SELECT A.FNAME, A.FCODE, B.NAME FROM USERA.NAME A, USERB.NAME B WHERE A.CODE = B.CODE; |
8.创建视图
1 | SELECT * FROM ( SELECT DBMS_LOB.GETLENGTH(PHOTO) AS FPHOTO FROM USER.NAME )WHERE FPSIZE > 10000 AND FPSIZE IS NOT NULL ; |
9. 查询字段长度
1 | SELECT * FROM USER.NAME WHERE LENGTH(USER.NAME)>3; |
10.创建视图
1 | CREATE OR REPLACE FORCE VIEW ADMIN."企业和用户" |
11. MINUS函数
1 | SELECT T1.* FROM (SELECT * FROM ADMIN.TCELECT MINUS SELECT * FROM ADMIN.TALLHOTELS)T1; |
12. INSTR函数
1 | SELECT INSTR ('ABBCC','C',1,1) FROM DUAL; |
13. REPLACE函数
1 | REPLACE (CONTENT,'aoe','000') |
14. HAVING函数
1 | SELECT CODE, COUNT (*) AS NUM FROM ABCTABLE GROUP BY CODE HAVING COUNT (*) > 1; |
15.复制数据的三种方法
1 | INSERT INTO A.TABLE1 SELECT * FROM A.TABLE2; |
16. INNER JOIN函数
1 | SELECT A.FCODE,A.FNAME FROM A INNER JOIN B ON A.FCODE = B.FCODE; |
17.UNION ALL函数
1 | SELECT CODE,NAME FROM A.TABLE1 UNION ALL SELECT CODE,NAME FROM A.TABLE2; |
18.CONCAT函数
1 | SELECT CONCAT ('abc', 'aoe') AS rzsj FROM A.TABLE1; |