一些oracle的常用语句

来源:互联网 发布:最强密码破解软件 编辑:程序博客网 时间:2024/06/05 03:49

1.查看用户所有表: select * from user_tables;
2. 查询所有的列内容(不重复):Select distinct 列 from 表名;
3.改表名:Alter table 表名 rename to 表名;
4.更改字段内容:Update 表名 set 列名 =replace(列名,被替换的内容,要替换的内容)
5.查询及删除重复记录:Select * from 表 where 列 in(select 列 from 表 group by 列 having count(列) >1)
6.修改密码:Alter user newjw(用户) identified by 新密码
7.解锁scott用户:alter user scott account unlock;
8.锁定用户的方法:alter user test account lock;
9.多表查询:
Left join: Select * from a表 left join b表 on a.id=b.id
Inner join: select * from a表,b表 where a.id=b.id
oracle如何查看当前有哪些用户连接到数据库

可以执行以下语句:
select username,serial#, sid from v$session; —查询用户会话
alter system kill session ‘serial#, sid ‘;—删除相关用户会话

建议以后台登陆删除用户会话
1、查询oracle的连接数
select count(*) from vsession;2oracleselectcount()fromvsession where status=’ACTIVE’;
3、查看不同用户的连接数
select username,count(username) from vsessionwhereusernameisnotnullgroupbyusername;4selectfromallusers;5()selectfromdbasysprivs;selectfromusersysprivs;6()selectfromrolesysprivs;7selectfromdbatabprivs;selectfromalltabprivs;selectfromusertabprivs;8selectfromdbaroles;9selectfromdbaroleprivs;selectfromuserroleprivs;10sysdbasysoper()selectfromVPWFILE_USERS;

修改数据库允许的最大连接数:
alter system set processes = 300 scope = spfile;

查看游标数量
Select * from v$open_cursor Where user_name=”

查询数据库允许的最大连接数:
select value from v$parameter where name = ‘processes’;
或者:show parameter processes;

查询数据库允许的最大游标数:
select value from v$parameter where name = ‘open_cursors’

查看oracle版本
select banner from sys.v_$version;

按降序显示用户”SYSTEM”为每个会话打开的游标数
select o.sid, osuser, machine, count(*) num_curs from vopencursoro,vsession s where user_name = ‘SYSTEM’ and o.sid=s.sid group by o.sid, osuser, machine order by num_curs desc;

连接函数 concat 或者 ||
字符串截取:substr()
字符串长度:length()
内容替换:replace()
Select substr(截取内容,位数)
改表的列名:
Alter table 表名 rename column 列 to 列 ;
改字段类型:
Alter table 表 modify 列 类型;
备份表数据: create table emp as select * from scott.emp
还原表数据:insert into emp select * from scott.emp
按某列的序号排列
Select * from 表名 order by 列名;
向表中加入列:
Alter table 表名 add 列名 类型 (约束)
表连接:
Select * from 表1,表2 where 表1.字段=表2.字段;
将个表的数据导入另一个表
insert into B select * from A;

可以使用 CREATE TABLE 语句创建表,CREATE TABLE 语句的简化语法如下:
CREATE [GLOBAL TEMPORARY] TABLE table_name
(
column_name type [CONSTRAINT constraint_def DEFAULT default_exp]
[, column_name type [CONSTRAINT constraint_def DEFAULT default_exp] … ]
)
[ON COMMIT [DELETE | PRESERVE] ROWS]
[TABLESPACE tab_space];
创建表的同时创建约束
• 主键 PRIMARY KEY
这个字段是非空的 并且是唯一的
一个表的主键只能有一个
• 唯一 UNIQUE
这个字段的值 是不能重复的
• 非空 NOT NULL
这个字段的值 不能是NULL值
• 检查 CHECK
这个字段的值 必须符合检查条件
• 外键 REFERENCES
on delete cascade
on delete set null
添加列
范例:向 order_status2 表中添加名为 modified_by 的列,数据类型是 INTEGER
ALTER TABLE order_status2 ADD modified_by INTEGER;
范例:向 order_status2 表中添加名为 initially_created 列
ALTER TABLE order_status2 ADD initially_created DATE DEFAULT SYSDATE NOT NULL;
–曾不及格(现在及不及格不清楚)
select kc.kch 课程号,kc.kcm 课程名,A.cj 成绩 ,xj.xh 学号,xj.xm 姓名,zy.zym 专业名, xs.xsm 学院名, xj.sfyxj 是否有学籍 from (
select xh,kch,min(kccj)as cj from (
select x.zxjxjhh,x.xh,x.kccj,x.kch from xs_kccjb x union all select y.zxjxjhh,y.xh,y.kccj,y.kch from cj_lrcjb y )
group by xh, kch having min(kccj) < 60 ) A, code_kcb kc ,xs_xjb xj ,code_zyb zy ,code_xsb xs
where A.Xh = xj.xh and A.Kch = kc.kch and zy.zyh = xj.zyh and xj.xsh = xs.xsh

–曾不及格(现在已及格)
select kc.kch 课程号,kc.kcm 课程名,A.cj 成绩 ,xj.xh 学号,xj.xm 姓名,zy.zym 专业名, xs.xsm 学院名, xj.sfyxj 是否有学籍 from (
select xh,kch,min(kccj)as cj from (
select x.zxjxjhh,x.xh,x.kccj,x.kch from xs_kccjb x union all select y.zxjxjhh,y.xh,y.kccj,y.kch from cj_lrcjb y )
group by xh, kch having min(kccj) < 60 and max(kccj)>=60 ) A, code_kcb kc ,xs_xjb xj ,code_zyb zy ,code_xsb xs
where A.Xh = xj.xh and A.Kch = kc.kch and zy.zyh = xj.zyh and xj.xsh = xs.xsh

–尚不及格
select kc.kch 课程号,kc.kcm 课程名,A.cj 成绩 ,xj.xh 学号,xj.xm 姓名,zy.zym 专业名, xs.xsm 学院名, xj.sfyxj 是否有学籍 from (
select xh,kch,min(kccj)as cj from (
select x.zxjxjhh,x.xh,x.kccj,x.kch from xs_kccjb x union all select y.zxjxjhh,y.xh,y.kccj,y.kch from cj_lrcjb y )
group by xh, kch having max(kccj) < 60 ) A, code_kcb kc ,xs_xjb xj ,code_zyb zy ,code_xsb xs
where A.Xh = xj.xh and A.Kch = kc.kch and zy.zyh = xj.zyh and xj.xsh = xs.xsh

0 0
原创粉丝点击