一些oracle的常用語句

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()fromv session where status=’ACTIVE’;
3、查看不同用戶的連接數
select username,count(username) from vsessionwhereusernameisnotnullgroupbyusername;4selectfromallusers;5()selectfromdbasysprivs;selectfromusersysprivs;6()selectfromrolesysprivs;7selectfromdbatabprivs;selectfromalltabprivs;selectfromusertabprivs;8selectfromdbaroles;9selectfromdbaroleprivs;selectfromuserroleprivs;10sysdbasysoper()selectfromV PWFILE_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,v session 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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章