您的位置:首页 > 数据库 > Oracle

数据库-oracle常用SQL语句整理(持续更新中)

2014-07-30 16:50 661 查看
--查询uuid

SELECT sys_guid() FROM dual;

--查询文件长度函数DBMS_LOB.GETLENGTH

SELECT DBMS_LOB.GETLENGTH(F."FILE") FROM T_EXPERT_FILE F WHERE ...

SELECT DBMS_LOB.GETLENGTH(F.filess) FROM T_EXPERT_FILE F WHERE ...

--复制表

create table newtable as select * from oldname where ...

--查询用户

SELECT * FROM all_users;

--查询函数

select * from dba_objects where object_type='FUNCTION';

--给某用户解锁

alter user cpist account unlock;

--查看job

SELECT * FROM Dba_Jobs;

SELECT * FROM dba_jobs WHERE log_user='CPIDBS';

--查看字符集

select userenv('language') from dual; --SIMPLIFIED CHINESE_CHINA.ZHS16GBK;

--查询某个表所有的触发器

select * from all_triggers where table_name =upper( 'chepb') AND owner=upper('cpixs');

--查询所有的存储过程

select * from user_objects where object_type='PROCEDURE';-- 一定要大写

--修改表名

alter table tableName_old rename to tableName_new

--添加列

alter table tableName add colName 字段类型

--修改列名

alter table taleName rename column colName to newColName

--修改列类型

alter table tableName modify colName 字段类型

--替换

从a中找到b,替换成c,若没有c表示从a中删掉b

SELECT REPLACE('a','b','c') FROM dual;

--表连接

select * from tableA cross join tableB;

--闪回

select * from meikxxb

--闪回过程

1,alter table meikxxb enable row movement;

2,flashback table meikxxb to timestamp to_timestamp ('2010-10-13 10:00:00','yyyy-mm-dd hh24:mi:ss');

3,alter table meikxxb disable row movement;

2014年07月31日更新

oracle用户的权限管理

-------------sys Login------------

1. 创建表空间及临时表空间

create tablespace csdn1 datafile 'csdn1' size 30m autoextend on;

create temporary tablespace csdn2 tempfile 'csdn2' size 30m autoextend on;

2. 创建用户指定表空间及临时表空间

create user csdn identified by csdn default tablespace csdn1 temporary tablespace csdn2;

3. 授予用户各种权利

grant create session to csdn;

grant unlimited tablespace to csdn;

grant connect to csdn;grant resource to csdn;

grant create sequence to csdn;

grant create table to csdn;

4. 查询当前用户的权限

select * from user_sys_privs;

5. 撤销用户各种权限

revoke create table from csdn;

revoke create session from csdn;revoke create sequence to csdn;

revoke resource to csdn;revoke connect to csdn;

revoke unlimited tablespace to csdn;

6.通过角色来赋予用户各种权限

create user root identified by root default tablespace csdn1 temporary tablespace csdn2;

create role role1;grant create table to role1;

grant create session to role1;

grant connect to role1;grant resource to role1;

grant create sequence to role1;

(1) 将角色赋予给用户grant role1 to root;

(2) 删除角色drop role role1;

7.创建序列

create sequence xulie

minvalue 1

maxvalue 222222

start with 1

increment by 1

nocache

nocycle

8.数值函数

select ceil(13.2) from tb_stu; --向上取整

select floor(12.9) from tb_stu;--向下取整

select power(9,19) from tb_stu;--9的19次方

select sqrt(8) from tb_stu; --8的平方根

select sign(-2) from tb_stu; --正数返1 负数返-1 0返0

select trunc(12.232323123,5) from tb_stu;--取5位小数

select round(1232.343,2) from tb_stu;--小数位为2 四舍五入

select exp(3) from tb_stu; --求指数

select mod(12,8) from tb_stu; --求余数

select ln(10) from tb_stu;--自然对数

select log(10,100) from tb_stu;--以10为底 100的对数

select vsize(1010) from tb_stu;--返回1010所占空间的大小

9.常用的函数

select initcap(stu_name) from tb_stu;--首字符转换成大写

select stu_name,instr(stu_name,'s') from tb_stu;--查找s在stu_name中的位置 返回相应的值(0 n)

select length(stu_name) from tb_stu;--返回长度

select upper(stu_name) from tb_stu;--换大写

select lower(stu_name) from tb_stu;--换小写

select lpad(stu_name,11,'Hello') from tb_stu;--长度不够则在左边填充Hello 直到够11
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: