Oralce 필기 하기 (2)
20642 단어 Oacle
151 user_tables (user_xxx,all_xxx,dba_xxx )
select table_name from user_tables;
152 all_tables (user_xxx,all_xxx,dba_xxx ) ( )
select table_name from all_tables; user_tables
153 dba_tables, , , dba select any table
154 oracle 9i 695 oralce 11 2500
155 oracle
156
select * from dba_users;
157
select * from dba_sys_privs where grantee='SYSTEM';
select * from role_sys_privs where role='SYSTEM';
158
select * from dba_tab_privs where grantee='SYSTEM';
159
select * from dba_col_privs where grantee='SYSTEM';
160
select * from dba_role_privs where grantee='SCOTT';
161
select count(*) from dba_roles; ---51 11.1 --25 9i
162 SCOTT
select * from dba_sys_privs where grantee in (select granted_role from dba_role_privs where grantee='SCOTT');
163 oralce
select * from system_privilege_map; --11.1 [ 206 ] 9i [ 140 ]
164 oracle
select * from dba_tab_privs; -- 11.1 [31520]
165
select tablespace_name from dba_tablespaces;
166
select * from dict where comments like ‘%grant%’
167
select * from global_name;
168 sqlplusw clear screen; PL/SQL ,sqlplus clear
169 : 。
oracle service ;
oracle service , ;
ORACLE v_$ , oracle , V$ 。
v_$datafile v$datafile;
sys, , dba 。
170
: 。
, ;
, , 。
171 oracle
, , , oracle , ,
1.
2.dba , i/0 ,
172 create tablespace , , , dba 。 create tablespace
crate tablesapce data01 datafile 'd:\test\data01.dbf' size 20m uniform size 128k;
: data01 , data.01.dbf , 128k,
create table mydept(deptno number(4),dname varchar2(14),loc varchar2(13)) tablespace data01; ( , SYSTEM );
create table emp(empno,ename) tablespace data01 as select empno,ename from scott.emp;
173
, (online) , , , 。
, 。 dba
1.
alter tablespace offline;
2.
alter tablespace online;
3.
, , update ,delete ,insert ,
alter tablespace read only;
4. ,
alter tablespace tbs001 read write;
174
select * from user_tables where TABLESPACE_NAME='DATA01'; ( )
175 , ( )
select tablespace_name,table_name from user_tables where table_name='EMP';
176 (dba )
drop tablespace DATA01 including contents and datafiles;
: including contents , , datafiles 。
177 oralce 3
1. alter tablespace TBS001 add datafile 'd:\tbs002.dbf' size 20m;
2. alter database datafile 'd:\tbs001.dbf' resize 20m;
3. alter database datafile 'd:\tbs002.dbf' autoextend on next 10m maxsize 500m;
178 ( , )
1.
select tablespace_name from dba_data_files where file_name='D:\TBS001.DBF';
2.
alter tablespacce tbs001 offline;
3. (PL/Sql ,sqlplus )
host move d:\tbs001.dbf c:\tbs001.dbf;
4.
alter tablespace TBS001 rename datafile 'D:\TBS001.DBF' to 'E:\TBS001.DBF';
5.
alter tablespace TBS001 online;
179 (dba_tablespaces);
select * from dba_tablespaces;
180 (dba_data_files)
select file_name,bytes from dba_data_files where tablesapce_name='TBS001';
181
offline,online, read only, read write;
182
undo
183 , oralce
1. (5) not null ,unique ,primary key ,foreign key,check
2.
3. ( , )
184 , unique
185
alter table goods modify goodsName not null;
186
alter table customer add constraint card_unique unique(cardId);
187 check
alter table customer add constraint address_check check(address in(' '),' ',' ');
189
alter table customer add constraint nums_check check(nums between 1 and 30);
190
alter table customer drop constraint 'nums_check';
191 ( )
alter table customer drop primary key 【cascade】;
192 ( user_constraints)
select constraint_name,constraint_type,status,validated from user_constraints where table_name='CUSTOMER';
193 user_constrants
select column_name,position from user_cons_colums where constraint_name=' ';
193 user_cons_columns
select cn.constraint_name,cn.constraint_type,cc.column_name,cc.position,cn.status,cn.validated from user_cons_columns cc,(select constraint_name,constraint_type,status,validated from user_constraints where table_name='CUSTOMER') cn where cc.constraint_name=cn.constraint_name;
select cs.constraint_name,cs.constraint_type,cs.validated,cc.column_name,cc.position from user_cons_columns cc,user_constraints cs where cs.constraint_name=cc.constraint_name and cs.table_name='CUSTOMER';
194 :
create table department4( dept_id number(2) constraint pk_department primary key,
name varchar2(12),
loc varchar2(12));
195 : ,
create table employee2( emp_id number(4),name varchar2(15),dept_id number(2),constraint pk_employee primary key(emp_id),
constraint fk_department foreign key (dept_id) references department4(dept_id));
196 : , I/O , ,
197 , ,
198 :
create index on ( );
199 : , , 。
create index emp_idx1 on emp(ename,job);
create index emp_idx2 on emp(job,ename);
200 sql , sql 。( , )
201
1. ( )
2. where
3. 4
202
1. , 1.2
2. , ,
3. , , 。 , 。
4.
5. , ( ) 。
6. , , DBA
203
1 :B * , ,
2. : ,
3. : ,
4. , , , ...
B* , , 。
204 dba_indexes( ) user_indexes( )
select index_name,index_type from user_indexes where table_name=" ";
205 (user_ind_columns)
select table_name,column_name from user_ind_columns where index_name='IND_ENAME';
206
select ic.table_name,ic.column_name,i.index_name,i.index_type from user_indexes i,user_ind_columns ic where i.index_name=ic.index_name and ic.table_name='CUSTOMER';
207 oracle
208 create table :
create any table :
create session:
create view:
create procedure:
create cluster:
create public synonym:
create trigger:
select * from system_privilege_map; --
209 ( dba )
grant any privilege 【with admin option】--
210
alter
delete select insert upate index references execute
211 (dba_tab_privs)
212
grant update on emp(sal) to luob;
grant select on emp(ename,sal) to luob;
213 alter
grant alter on emp to luob;
214 execute ( 、 , )
grant execute on dbms_transaction to luob; -- dbms_transaction
215 luob scott.emp
grant index on scott.emp to luob with grant option;
216
217 connect ,resource,dba
connect , , connect resource
connect :
alter session
create cluster
create database link
create session
create table
create view
create sequence
resources , , ,resource unlimited tablespace 、
create cluster
create indextype
create table
create type
create proecdure
create trigger
dba with admin option , dba sys system , dba sysdba sysoper ( )
218 dba , create role ( ( , ))
( ): ,
create role not identified;
alter role myrole identified by luobing; --
( )
create role identified by shunping;
grant select on scott.emp from -- system
create update on scott.emp from -- scott
crate delete on scott.emp from
219
grant create session to with admin option;
220
grant to with admin option;
221
revoke from ;
222 dba
drop role :---》 ,
223
select * from dba_roles;
224 PL/SQL procedura language /sql
225
show error;
226 create or replace procedure ss is
begin
insert into myTest values('luob','luob');
end;
/ --- sqlplusw
227
exec ;
call ();
exec ();
228 pl/sql
{ , , , }
: “--“
: /* */
---》 v_
---》 c_
------》 _cursor ---》emp_cursor;
------》 e_ ---->e_error;
229
declare ( )
/*
---> , , , ,
*/
begin
/*
*/
exception ( )
/*
---》
*/
end;
230 set serveroutput on ;
begin
dbms_output.put_line('hello world!');
end;
/
231 declare
v_ename varchar2(30);
v_sal number(7,2);
begin
select ename,sal into v_ename,v_sal from emp where empno=&no;
dbms_output.put_line(' :'||v_name||' '|| v_sal);
end;
/
232 declare
v_enme varchar2(30);
v_sal number(10,2);
begin
select ename,sal into v_ename,v_sal from emp where empno=&no;
dbms_output.put_line(v_ename|| v_sal);
exception
when no_data_found then
dbms_output.put_line(' , ');
end;
/
233 pl/sql
234
create or replace procedure sp_emp3(spName varchar2,newSal number)is
begin
upadte emp set sal=newSal where ename=spName;
end;
/
exec sp_emp3('SCOTT',4687);
235
create or replace function sp_fun1(spName varchar2) return
number is yearSal number(7,2);
begin
select sal*12+nvl(comm,0)*12 into yealSal from emp where ename=spName;
return yearSal;
end;
/
var abc number;
call sp_fun1('SCOTT') into:abc;
236
create package sp_package is
procedure update_sal(name varchar2,newSal number);
function annual_income(name varchar2) return number;
end;
237
create package body sp_package is
proceduare update_sal(name varchar2,newSal number)
is
begin
update emp set sal=newSal where ename=name;
end;
function annual_salary(name varchar2) return numer is yearSal number;
begin
select sal*12+nvl(comm,0)*12 into yearSal from emp where ename =name;
return yealSal;
end;
end;
238 pl/sql
v_sal number(6,2):=5.4;
v_hiredate date;
v_valid boolean not ull default false;
239 (scalar)
declare
c_tax_rate number(3,2):=0.03;
v_ename varchar2(50);
v_sal number(7,2);
v_yearSal number(7,2);
begin
select ename,sal into v_ename,v_sal from emp where empno=&no;
v_yearSal:=v_sal*c_tax_rate;
dbms_output.put_line(' :'||_ename||' :'||v_Sal||' :'||v_yearSal);
end;
/
240 %type
declare
c_tax_rate number(3,2):=0.03;
v_ename emp.ename%type;
v_sal emp.sal%type;
v_tax_sal emp.sal%type;
select ename,sal into v_ename,v_sal from emp where empno=&no;
v_tax_sal:=v_sal*c_tax_rate;
dbms_output.put_line(' :'||_ename||' :'||v_Sal||' :'||v_tax_sal);
end;
/
241 (composite) ,
pl/Sql
pl/Sql
varray ( )
242 pl/sql
declare
//
type emp_record_type is record(name emp.ename%type,sal emp.sal%type,title emp.job%type);
v_emp_record emp_record_type; //
begin //
select ename,sal,job into v_emp_record from emp where empno=&no;
//
dbms_output.put_line(' :'||v_emp_record.name);
end;
/
243 pl/sql ( )( - +);
declare
// pl/sql , sp_table_type emp.ename%type
// index by binary_integer
type sp_table_type is table of emp.ename%type index by binary_integer;
sp_table sp_table_type; //
begin
// ,
select ename into sp_table(0) from emp where empno=7788;
dbms_output.put_line(' :'||sp_table(0));
end;
244 , ,
ref cursor
: select
:(open) select ( select )
ref obj_type
245
declare
//
type sp_emp_cursor is ref cursor;
//
test_cursor sp_emp_cursor;
//
v_ename emp.ename%type;
v_sal emp.sal%type;
begin
//
// test_cursor select
open test_cursor for select ename,sal from emp where deptno=&no;
//
loop
//
fetch test_cursor into v_ename,v_sal;
// 200 +100
if v_sal<200 then
update emp set sal=sal+100 where ename=v_ename;
end if;
// test_cursor ,
exit when test_cursor%notfound;
//
dbms_output.put_line(' '||v_ename||' '||v_sal);
end loop;//
end;
/
246 orale
sys
-- -- --- -- ora_dba
--oralce _PWDorcl.ora
---
conn / as sysdba
-- orapwd
orapwd file=D:\app\Admin\product\11.1.0\database\PWDorcl.ora password=123456 entries=10 force=y
,
247
sql server access
MySql AB mySql
ibm db2
Sybase Sybase
ibm informix
Oracle oralce
248 30 oracle , A-Za-z0-9$#
249 rowid oracle , , , 。
rowid
OOOOOO FFF BBBBBB RRR
data_object_id# rfile# block# row#
32bit 12bit 22bit 16bit
250 ( max min)
1. delete from student a where rowid not in (select max(b.rowid) from student b where a.name=b.name and a.sex=b.sex and a.no=b.no);
2.( "max ")
delete from student a where rowid 1;
select * from empa where rowid not in (select min(rowid) from empa group by empno);
6.
select * from empa a where rowid<>(select max(rowid) from empa where empno=a.empno)
7.
delete empa where empno in(select empno from empa group by empno having count(*)>1) and rowid not in(select min(rowid) from empa group by empno having count(*)>1);
delete empa where rowid not in (select min(rowid) from empa group by empno);
delete empa a where rowid <>(select max(rowid) from empa where empno=a.empno)
delete emp where rowid <>(select max(rowid) from empa group by empno)
--------------------------
user_tables
all_tables;
dba_tables;
dba_user;
dba_sys_privs
role_sys_privs
ROLE_TAB_PRIVS
dbs_tab_privs //
all_tab_privs
user_tab_privs
dba_col_privs
all_col_privs
user_col_privs
dba_roles; //
dba_role_privs //
system_privilege_map //
dba_tablespaces; //
dict
global_name;
dual
v_$
dba_data_files
user_constraints
user_cons_columns
dba_indexes
all_indexes;
user_indexes
user_ind_columns
all_ind_columns;
table_privilege_map;
table_privileges;
select count(*) from dba_roles; 51
select count(*) from system_privilege_map; 206
select count(*) from table_privilege_map; 26
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
자바 작업 은 Clob 또는 NClob 데이터 형식의 저장 프로 세 스 인 스 턴 스 를 포함 합 니 다.텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.