关于oracle数据库的小知识

时间:2021-07-08 00:44:03

--查询语句:select 列名/通配符/列别名/表达式 from 表名 (修饰/限制语句)
select * from tab;
select tname from tab;--指定的列
select tabtype from tab;
select tname "T-M" from tab;--新建列别名
select 3+4 from dual;--虚表(只有一行一列)
select 3+4 as "he" from dual;
--employees:雇员表
desc employees;--desc:显示一个表的结构(列名,烈的约束,列的数据类型)
select * from employees;
--null:1.参与运算,整体为null
--nvl函数:nvl (列名,值)
select (1+commission_pct)*salary*12 as "年薪" from employees;
--有null值则用0来代替null运算
select (1+nvl(commission_pct,0))*salary*12 as "年薪" from employees;
select commission_pct,(1+nvl(commission_pct,0))*salary*12 as "年薪" from EMPLOYEES;
--nvl2函数:nvl2 (列名,值1,值2)为null时,显示值2,不为null时,显示值1
select commission_pct,nvl2(commission_pct,'有提成','没提成') from EMPLOYEES;
--集合内去除重复的行:DISTINCT
SELECT DISTINCT first_name FROM EMPLOYEES;
--双行查询(列1列2不能重复)
--order by(排序,默认从小到大ASC(DESC相反))(排序的列名可以不再语句中出现)
select employee_id,salary from employees;
select employee_id,last_name,salary from employees order by salary;
select employee_id,last_name,salary from employees order by salary desc;
select employee_id,last_name,salary as "sal" from employees order by "sal" desc;
--各列在select语句中的顺序号,从1开始
select employee_id,last_name,salary from employees order by 3 desc;
--条件子句:查找特定id员工的信息
--where 条件
select * from employees where employee_id = 100;
-- 不等于<>
select * from employees where employee_id <> 100;
--between 值1 and 值2:获取两个值之间的数据.
select * from employees where employee_id between 100 and 107;
--in(值1,值2,值3...):获取一组特定的数据/满足任意一个即可
select * from employees where employee_id in( 100,105,200);
--is NULL:判断是否为空(is Null/is not Null)
select * from employees where COMMISSION_PCT is Null;
--not in():特定的值不会选取
select * from employees where employee_id not in (100,200,107);
--逻辑运算符 and(需全部满足) or(满足一个就行) not(选中的不能选取)运算时加括号
select * from employees where employee_id = 100 and employee_id = 200;
select * from employees where employee_id = 100 or employee_id = 200;
select * from employees where employee_id not in (200,100);
--模糊查询:%代替一个或者多个字符(区分大小写)
--是否包含
select last_name from employees where last_name like '%m%';
--排在首位的
select last_name from employees where last_name like 'M%';
--查找排在第二位的
select last_name from employees where last_name like '_m%';
--查找排在倒数第二位的
select last_name from employees where last_name like 'm_%';
--替代变量:&(筛选)代码的重用性
select last_name,salary from employees where salary >='&薪水';
--字符串的连接||
select 'a'||'b' from dual;
select first_name||' '||last_name from EMPLOYEES;
select first_name as "姓",last_name as "名",first_name||' '||last_name as "姓名" from EMPLOYEES;
--脚本运行(.sql):@+文件所在的路径
@e:\\a.sql;
******************************************************
--单行函数:作用于一行记录
--length:求字符长度
select length('就让往事皆随风c')as "长度" from dual;
--统计员工表中,员工的姓名长度,改为名长
--lower upper initcap
--大写转小写
select lower('ADCDEFG二连') from dual;
--小写转大写
select upper('abcdefg二连') from dual;
--initcap:首字母大写,其余小写(汉字忽略不计)
select initcap('喊cajppjPPdsIHOasd') from dual;
--concat('',''):字符连接
select 'a' || 'b' from dual;
select concat('aa','汉字') from dual;
--substr('',start,end):字符串截取('字符串','截取长度','截取长度')(截取长度:正数从左往右,负数则相反)
select SUBSTR('ABCDEFG',2,3) from dual;
--instr('hellowword',''w)(字符串内查找出现的位置)
select instr('就让往事皆随风c','往')from dual;
--R/LPAD(salary,10,'*')(左右填充)
select lpad(salary,10,'*')from employee;
--replace('jack and jue','j','bl')(替代)
select replace ('就让往事皆随风c','往','??')from dual;
--trim('H'from'Helloword')查找给定字符,并截掉(只能截取开头和结尾的字符)
select TRIM('风' from '就让往事皆随风') from dual;
--左截
select LTRIM('xyxyxyxyxyLVxyxyxyxyxy','xy') from dual;
--右截
select RTRIM('xyxyxyxyxyLVxyxyxyxyxy','xy') from dual;
***************************************************************
--数字函数
--舍入和截断,取余
--round:四舍五入(正数,取小数位.负数,取整数位)
--15.2
select round(15.193,1)from dual;
--15
select round(15.193,0)from dual;
--15
select round(15.193)from dual;
--20
--trunc:截取
--15.1
select trunc(15.193,1)from dual;
--15
select trunc(15.193,0)from dual;
--15
select trunc(15.193)from dual;
--10
select trunc(15.193,-1)from dual;
--mod:取余数
--1
select mod(16,3)from dual;
******************************************************************
--日期函数 sysdate
--获取当前时间
select sysdate from dual;
--add_months:在给定的日月数上加上给定数字
select add_months(sysdate,6)from dual;
--next_day:计算下个星期四是几月几号
select next_day(sysdate,'星期四')from dual;
--last_day:当前月的最后一天
select last_day(sysdate)from dual;
--计算日期格式的数据(数字代表天数)
select sysdate+1 from dual;
--字符串表示日期
select add_months('18-6月-12',6)+20 from dual;
--months_between(date1,date2):两个日期之间的月数差(前减后)
select months_between(sysdate,'26-4月-16') from dual;
--round:日期的舍入
--month:看天数 大于15,月数加一
select round(TO_DATE('26-6月-17'),'month')from dual;
--year:看月数 大于6,年数加一
select round(TO_DATE,'year')from dual;
--day:按星期/dd:按小时/hh:看分钟
select round(sysdate,('16-6月-17 12:00:59','dd-Month-yy hh24:mi:ss'),'dd')from dual;
--trunc:日期截取(不考虑天数/月数)
select trunc(sysdate,'month')from dual;
select trunc(sysdate,'year')from dual;
*************************************************************************
--转换函数
--数据类型的隐式转换
--字符串转换为数值类型
select salary from employees where salary >'12000';
--字符串转换为日期类型
select hire_date from employees where hire_date>'01-5月-05';
--to_char:数字类型转换为指定格式的字符串
select salary from employees ;
--0:补位
select to_char(salary,'L00,000') from employees ;
select to_number('2') from dual ;
--to_char:日期类型转换为指定格式的字符串
select last_name,hire_date from employees ;
select last_name,to_char(hire_date,'yyyy-MM-dd hh:mi:ss') from employees ;
--to_date:日期类型转换为指定格式的字符串(hh24:24小时制)(month:6月/MM:06)
select to_date ('2017-6月-29 19:28:28','yyyy-month-dd hh24:mi:ss') from dual;
***************************************************************************************
--多表查询
desc employees;
desc departments;
desc locations;
desc ;
select last_name from employees;
select department_name from departments;
--笛卡尔积
select last_name,department_name from employees cross join departments;
--等价连接(可以用新名去.列名/一旦修改新名后,必须使用新名)
select last_name,department_name from employees,departments where employees.EMPLOYEE_ID = departments.DEPARTMENT_ID;
select e.last_name,d.department_name from employees e,departments d where e.EMPLOYEE_ID = d.DEPARTMENT_ID;
--natural join:自然连接(所有相似的部分)
select e.last_name,d.department_name from employees e natural join departments d;
--创建表
CREATE TABLE "GRADES"
( "LEV" VARCHAR2(10),
"LOW" NUMBER(6,0),
"HIGHT" NUMBER(6,0)
);
INSERT INTO GRADES VALUES('A',1000,2999);
INSERT INTO GRADES VALUES('B',3000,5999);
INSERT INTO GRADES VALUES('C',6000,9999);
INSERT INTO GRADES VALUES('D',10000,14999);
INSERT INTO GRADES VALUES('E',15000,24999);
INSERT INTO GRADES VALUES('F',25000,40000);
commit;
desc grades;
select * from grades;
--不等价连接(数值分区)
select e.last_name,e.salary,f.lev from EMPLOYEES e,GRADES f where e.salary BETWEEN f.low and f.hight;
--表的自连接
--(普通情况)
select manager_id,last_name from EMPLOYEES where LAST_NAME = 'Jones';
select last_name from EMPLOYEES where EMPLOYEE_ID = 123;
--(自连接)
select e1.last_name,e2.last_name from EMPLOYEES e1,EMPLOYEES e2 where e1.MANAGER_ID = e2.EMPLOYEE_ID and e1.LAST_NAME = 'Jones';
--上午↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
--左外链接(+)号的位置在等号右边
select e.last_name,d.DEPARTMENT_ID, d.DEPARTMENT_NAME,e.SALARY from employees e,departments d where e.DEPARTMENT_ID = d.DEPARTMENT_ID(+);
select e.last_name,d.DEPARTMENT_ID, d.DEPARTMENT_NAME,e.SALARY from employees e LEFT OUTER JOIN DEPARTMENTS d ON (d.department_id = e.department_id);
--右外链接
select e.last_name,d.DEPARTMENT_ID, d.DEPARTMENT_NAME,e.SALARY from employees e,departments d where e.DEPARTMENT_ID(+) = d.DEPARTMENT_ID;
select e.last_name,d.DEPARTMENT_ID, d.DEPARTMENT_NAME,e.SALARY from employees e RIGHT OUTER JOIN DEPARTMENTS d ON (d.department_id = e.department_id);
--全连接
select e.department_id,d.department_id,e.last_name,d.department_name from EMPLOYEES e full outer join DEPARTMENTS d on (e.department_id = d.department_id);
--nuion/union all
select e.LAST_NAME,d.department_name from employees e,departments d where e.DEPARTMENT_ID(+) = d.department_id
union all
select e.LAST_NAME,d.department_name from employees e,departments d where e.DEPARTMENT_ID = d.department_id(+);
--minus(第一个查询结果减去第二个查询结果 剩下 第二部分不重复的部分)
select e.LAST_NAME,d.department_name from employees e,departments d where e.DEPARTMENT_ID = d.department_id(+)
minus
select e.LAST_NAME,d.department_name from employees e,departments d where e.DEPARTMENT_ID(+)= d.department_id;
--intersect(联合唯一性)(两个集的交集)
select e.LAST_NAME,d.department_name from employees e,departments d where e.DEPARTMENT_ID = d.department_id(+)
intersect
select e.LAST_NAME,d.department_name from employees e,departments d where e.DEPARTMENT_ID(+)= d.department_id;
--组函数
--count
select count (DEPARTMENT_ID) from EMPLOYEES;
select count (*) from EMPLOYEES where DEPARTMENT_ID = &部门;
select count (commission_pct) from EMPLOYEES where DEPARTMENT_ID = &部门;
--最大(自然顺序)/最小/求和/平均值(限制汉字)
select max(salary),min(salary),sum(salary),round(avg(salary))from EMPLOYEES;
select max(salary),min(salary),sum(salary),round(avg(salary)) from EMPLOYEES where DEPARTMENT_ID = 90;
--group by(分组函数)(having字句对分组函数进行条件筛选)(后面只能跟列名而不是列别名)
--where>分组>组函数>having>order by
select department_id,round(avg(salary)) from EMPLOYEES GROUP BY DEPARTMENT_ID order by 2 desc;
select department_id,round(avg(salary)) from EMPLOYEES GROUP BY DEPARTMENT_ID having round(avg(salary))>9000;
*********************************************************************************************************
--一般查询与子查询
select last_name,salary from employees where salary = 11000;
--单行子查询(多行结果)(可以使用条件连接符)
--1.作为where子句
select last_name,salary,job_id from EMPLOYEES where job_id=(select job_id from EMPLOYEES where last_name='Abel');
select last_name,salary,job_id from EMPLOYEES where
job_id=(select job_id from EMPLOYEES where last_name='Abel')
and
salary>(select salary from EMPLOYEES where last_name='Abel');
--2.作为from子句
select last_name,salary from EMPLOYEES where job_id = 'SA_REP' and salary = 11000;
--后面作为一个表,外部再从内部查询(子查询可以多层嵌套(三层不能再多了))
select last_name,salary from
(select last_name,salary from EMPLOYEES where job_id = (select job_id from EMPLOYEES where last_name='Abel'))
where salary = 11000;
--3.子查询中使用分组函数
select last_name||first_name,salary,job_id from EMPLOYEES where salary=(select max(salary) from employees);
--4.having中使用子查询
select department_id,min(salary) from EMPLOYEES
GROUP by DEPARTMENT_ID having min(salary)>
(select min(salary) from employees where department_id=50);
--最小工资大于100号部门的所有部门的id和最小工资
select department_id,min(salary) from EMPLOYEES
group by DEPARTMENT_ID having min(salary)>
(select min(salary)from EMPLOYEES where DEPARTMENT_ID=100);
--查询与姓氏为**的员工职位相同的员工的姓名,薪资和部门.
--(in/= any)用法相同(<>any是无效操作,等同于没有)
select last_name,job_id,salary from EMPLOYEES where job_id = any
(select job_id from EMPLOYEES where last_name = 'King');
--(>any/<any 大于最小的,小于最大的)
select employee_id,last_name,job_id,salary from EMPLOYEES where salary <> any
(select salary from EMPLOYEES where job_id='IT_PROG');
select last_name,job_id from EMPLOYEES where job_id =
(select job_id from employees where last_name ='Abel');
select last_name,job_id from EMPLOYEES where DEPARTMENT_ID =
(select department_id from EMPLOYEES where last_name = 'Abel');
select last_name||' '||first_name,salary,department_id from employees where salary<
(select avg(salary) from EMPLOYEES where department_id=100)and department_id<>100;
select * from EMPLOYEES;
********************************************************************************************************
--创建表
--create table 表名
--(
--列1 数据类型 约束(可选),
--列2 数据类型 约束
--);
--创建一个表(Test_Oaec) 3列:id name age
create table oaec_test
(
--列级别
--id number(10) CONSTRAINT oaec_test_id_pk PRIMARY key,
--表级别
id number(10) ,
CONSTRAINT oaec_test_id_pk primary key(id),
name varchar2(20) CONSTRAINT oaec_test_name_nn not null,
age number(5)check (age>0 and age<150),
birthday date
);
--birthday date default sysdate;
--描述表
desc oaec_test;
--插入数据
insert into oaec_test (ID,name,age)values(1,'花色',DEFAULT);
--查看
select * from OAEC_TEST;
--删除表
drop table oaec_test;
--查看约束
select * from user_constraints;
--查看oaec_table表的约束(约束名称和约束类型)
select constraint_name,constraint_type from user_constraints where TABLE_NAME='OAEC_TEST';
--约束
--not null(不能为空)(只能写在列级别)
--unique(唯一)
--primary key(非空且唯一)
--foreign key(外键列)(依赖关系.依赖主键.主键有外键不一定有,主键没有外键一定没有)
--check(自定义约束)例如:(age>0 and age<150)
create table friend
(
id NUMBER(10),
phone number(11),
last_name VARCHAR2(25)
CONSTRAINT friend_last_name_nn not null,
gender VARCHAR2(10),
age number(3),
CONSTRAINT friend_id_pk PRIMARY KEY(id),
CONSTRAINT friend_phone_uk UNIQUE(phone),
CONSTRAINT friend_gender_ck check(gender in('男','女')),
CONSTRAINT friend_age_ck check(age>0 and age<150),
--外键列,引用oaec_test的id主键列(列级别)
--test_id number(10) CONSTRAINT friend_test_id_fk REFERENCES oaec_test(id)
--表级别
test_id number(10),
CONSTRAINT friend_id_fk FOREIGN key(test_id) REFERENCES oaec_test(id)
);
drop table oaec_test;
drop table friend;
drop table copy_friend;
select * from OAEC_TEST;
select * from FRIEND;
select * from copy_friend;
INSERT INTO oaec_test (id,name)VALUES(1,'花花');
INSERT INTO oaec_test (id,name)VALUES(2,'花花1');
INSERT INTO oaec_test (id,name)VALUES(3,'花花1');
INSERT INTO oaec_test (id,name)VALUES(4,'花花1');
--INSERT INTO oaec_test VALUES(3,'花花1',21,sysdate);
INSERT INTO FRIEND VALUES(1,16345678910,'花','男',22,null);
INSERT INTO FRIEND VALUES(2,12345678910,'花','男',22,1);
INSERT INTO FRIEND VALUES(3,16346678910,'花','男',22,2);
INSERT INTO FRIEND VALUES(4,16345978910,'花','男',22,2);
--使用子查询创建表
--创建一个只有ID,age的表
create table copy_friend as
select id,age from FRIEND where AGE=22;
--复制整个源表
create table copy_friend as
select * from friend;
--创建表后再添加一列
alter table oaec_test add(salarys number(10) CONSTRAINT oaec_test_salarys_uk unique);
desc oaec_test;
--修改表创建后的列
alter table oaec_test MODIFY(name number(10));
alter table oaec_test MODIFY(birthday date default sysdate);
--创建表后添加约束
alter table oaec_test add(CONSTRAINT oaec_test_birthday_uk unique(birthday));
--创建表后删除约束(根据约束名删除)
Alter table oaec_test DROP CONSTRAINT oaec_test_birthday_uk;
--约束失效(DISABLE)
--删除表中的列(列中即使有数据也能删除)(一次只能删除一个并且必须保留一个列)
alter table oaec_test drop column salarys;
--表的删除(DROP table)(在被引用的时候,可以使用级联删除)
DROP table oaec_test;
--(先删约束,再删表)
DROP table oaec_test CASCADE CONSTRAINTS;
*********************************************************************************************
--1.往表中插入数据
--insert into 表名(表名若不写,表示表的列全部要插入数据)
--values(插入的数据和列一一对应)
select * from tab;
--创建test表
create table tests
(
id number(10) ,
CONSTRAINT oaec_tests_id_pk primary key(id),
name varchar2(20) CONSTRAINT oaec_tests_name_nn not null,
age number(5)check (age>0 and age<150),
birthday date DEFAULT sysdate
);
select * from tests;
insert into tests(id,name,age,birthday)
values(1,'花色',21,sysdate);
insert into tests(id,name,age,birthday)
values(2,'花色',21,TO_DATE('2000-05-01','yyyy-MM-dd'));
insert into tests(id,name,age,birthday)
values(4,'花色',21,TO_DATE('2000-5月-01','yyyy-Mon-dd'));

create table oaec_tests_copy as select * from oaec_test;
select * from OAEC_TESTS_COPY;
--删除表中的数据
delete OAEC_TESTS_COPY;
--2.插入数据//用子查询插入数据(查询出的数据全部插入到指定的表/列要一一对)(普通插入只能插入一列)
insert into OAEC_TESTS_COPY select * from OAEC_TEST;
insert into OAEC_TESTS_COPY(id,name) select id,name from OAEC_TEST;
insert into OAEC_TESTS_COPY(id,name) select id,name from OAEC_TEST where id in(1,4);
--更新表中的数据(UPDATE 表名
--select 列名 = 新值
--where 条件 (确定数据的位置/不写则更行所有的)
select * from OAEC_TEST;
update OAEC_TEST
set id = 5 where id = 3;
update OAEC_TEST set name = 'faker' where NAME = '比克大魔王faker';
--3.删除数据
--delete from 表名
--where 条件(确定要删除数据的位置);
delete from OAEC_TEST;
rollback;
delete from OAEC_TEST
where id = 0;
delete from OAEC_TEST
where NAME like '%花花1%';
--注意:插入/删除/更新 不要违反约束!尤其是外键约束!
commit;--提交
ROLLBACK;--回滚
SAVEPOINT update_p;--设置回滚点
ROLLBACK to update_p;--回滚到指定的回滚点

***********************************************************************************************
--序列的创建
--查找相关的表
select * from tab;
desc OAEC_TEST;
select count(*) from OAEC_TEST;
select * from OAEC_TEST;
--创建序列
--create sequence 表名_序列名
create sequence oaec_test_seq
--每次的增加量
INCREMENT by 1
--起始值
START with 1
--最大值
MAXVALUE 100
--循环(nocycle--不循环)
cycle
--循环次数
CACHE 10;
--描述序列表
desc user_sequences;
--查看序列表的内容
select sequence_name,max_value,increment_by,cache_size,last_number from user_sequences;
--1.序列产生主键值(如何使用)
--2.使用:
--(1). 序列名.nextval--获取下一个序列值
select oaec_test_seq.nextval
from dual;
--(2). 序列名.currval--查看当前序列值
select oaec_test_seq.currval
from dual;
--插入数据时,使用序列
select * from OAEC_TEST;
--手动添加id
insert into OAEC_TEST
VALUES(5,'价格',12,TO_DATE('2000-02-10','yyyy-mm-dd'));
--使用序列使id自增
insert into OAEC_TEST
values(oaec_test_seq.nextval,'价格',12,TO_DATE('2000-02-10','yyyy-mm-dd'));
--序列的修改(起始值不能修改)
alter sequence oaec_test_seq
increment by 2
MAXVALUE 121
NOCYCLE
NOCACHE;
--确认修改
select sequence_name,max_value,increment_by
from user_sequences;
--使用效果
select oaec_test_seq.nextval
from dual;
select oaec_test_seq.currval
from dual;
--序列的删除:drop sequence 序列名;
drop SEQUENCE oaec_test_seq;
************************************************************************************
--视图的创建:view
--create view 视图名
--[(列名)]
--as (查询语句);
--可选操作
--部门号为90的员工名字,工资,入职日期
select last_name,salary,hire_date from HR.EMPLOYEES where DEPARTMENT_ID = 90;

create view emp_dept_id_90
(e_name,sal,h_date)
as
(select last_name,salary,hire_date from HR.EMPLOYEES where DEPARTMENT_ID = 90);
--查看视图
select * from emp_dept_id_90;
--删除视图
drop view emp_dept_id_90;
--视图的替换:create (or replace) view emp_dept_id_90
create or replace view emp_dept_id_90
(e_name,sala,h_date)
as
(select last_name,salary,hire_date from HR.EMPLOYEES where DEPARTMENT_ID = 90);
--force/noforce(默认)-->强制创建视图
--with check option(插入/更新/删除的数据,必须满足子句的条件)
create or REPLACE view emp_dept_id_100
as
select * from emp where DEPARTMENT_ID = 100 with check option;
--with read only(拒绝一切DML操作,只允许进行select操作)
create or REPLACE view emp_dept_id_100
as
select * from emp where DEPARTMENT_ID = 100 with read only;
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
--1.对源表插入数据(符合视图的数据),视图会改变吗??
--复制一张表
create table emp as select * from employees;
--查看
select * from emp;
--创建视图
create view emp_dept_id_90
(e_name,sal,h_date)
as
(select last_name,salary,hire_date from HR.EMPLOYEES where DEPARTMENT_ID = 90);
--描述emp表
desc emp;
--源表数据插入
insert into emp
values(208,'a','a','a','a',sysdate,'AD_VP',10000,null,100,90);
insert into emp
values(208,'aa','aa','aa','aa',sysdate+1,'AD_VP',10000,null,100,100);
--提交
commit;
--删除插入的数据
delete from emp where last_name in ('a','aa');
--查看emp表
select * from emp;
--查看视图
select * from emp_dept_id_90;
--结论:会发生改变
--2.对视图插入数据,源表会改变吗??
--创建视图
create or REPLACE view emp_dept_id_100
as
select * from emp where DEPARTMENT_ID = 100 with read only;
--查看视图
select * from emp_dept_id_100;
--视图中插入数据
insert into emp_dept_id_100
values(209,'a1','a1','a1','a1',sysdate,'AD_VP',10000,null,100,90);
insert into emp_dept_id_100
values(210,'aa1','aa1','aa1','aa1',sysdate+1,'AD_VP',10000,null,100,100);
--查看源表
select * from emp;
--查看视图
select * from emp_dept_id_100;
--结论:会改变.(插入视图的过程就是插入源表的过程)
--视图分类:
--简单视图(来源于一个表,没有一些分组函数,可以进行DML操作)
--复杂的视图(来源于多个表,具有一些分组函数,拒绝DML操作)
select e.DEPARTMENT_ID,min(e.salary),max(e.salary),round(avg(e.salary),2)
from employees e,DEPARTMENTS d
where e.DEPARTMENT_ID = d.DEPARTMENT_ID group by e.DEPARTMENT_ID;
create view dept_sal
as select ;
sqlplus sys/123456 as syadba;
create tablespace garyspace datafile 'd:\\garyspacea.dbf' size 100m;
--创建用户
--create user 用户名(gary) identified by 密码(gary) 是否锁定(account unlock);
create user gary identified by gary account unlock;
--管理登陆
conn sys/123456 as sysdba;
--用户授权
grant resource to gary;
--基本包括所有操作
grant connect,resource to gary;
grant create session to gary;状态: 失败 -测试失败: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
grant create table to gary;
grant create view to gary;
--连接用户
conn gary/gary
--删除用户
drop user anan;
--收回权限
invoke create session from gary;
--修改密码
alter user gary identified by 123456;