一些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 v
3、查看不同用户的连接数
select username,count(username) from v
修改数据库允许的最大连接数:
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 v
连接函数 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
- oracle一些常用的语句
- 一些oracle的常用语句
- 关于oracle常用语句的一些整理
- oracle的一些常用的查询的sql语句
- oracle中SQL语句的一些有效常用用法
- oracle logical standby 日常管理常用的一些语句
- SqlServer和Oracle中一些常用的sql语句1
- SqlServer和Oracle中一些常用的sql语句2
- 一些Oracle的语句
- 常用的oracle语句
- oracle 常用的语句
- oracle常用SQL语句和一些技巧
- SqlServer和Oracle中一些常用的sql语句5 流程控制语句
- 一些常用的SQL语句
- 一些常用的SQL语句
- 一些常用的SQL语句
- 一些常用的SQL语句
- 一些常用的MDX语句
- linux下mysql 5.7+版本 忘记密码和支持远程访问
- maven多模块Springmvc+mybatis读取配置文件和注入bean
- 将博客搬至CSDN
- kindeditor富文本编辑器前端+后端实现
- mysql多个时间戳字段默认值问题
- 一些oracle的常用语句
- js 日期格式化
- 【Unity资源】(动作/双足)
- HeadFirstC笔记_13 十大遗漏知识点
- maven阿里仓库
- AndroidSQLite简单使用
- matlab中文函数手册.chm
- 基于springMVC 将log日志写入到数据库中
- opencv之cvScalar函数