Oracle 50 commonly used grammar

Copyright: chengf https://blog.csdn.net/qq_34156628/article/details/90741743

1. Database connection and disconnection database

连接数据库
connect scott/123456;
断开数据库
disconn;

2. View the table structure

describe scott.emp;

3. View Data Sheet

select empno.job.mgr.sal;

4. Save the buffer to the file sql statement

save scott_emp_query.sql

The contents of the file is read into the buffer

get scott_emp_query.sql list

6. Use the start command to read and run the sql file

start scott_emp_query.sql

7. Save the output to the specified file

spool scott_emp_outcome.txt append

8. The statement with variables

select empno.ename.mgr.sal.deptno
from scott.emp
where empno >=&temp;

9. statement with two variables (two entries)

select &column_name.deptno
from scott.emp
where &column_name>=7850;

10. The two variables with a statement (last input)

select &&column_name .deptno
from scott.emp
where &&column_name>=7850;

11. Non-display "at cost" and "new value" information

set veryify off;(on是显示)

New tactics: slash "/" Run again above query

12. Variables defined character set

set define '@'(设置以后定义变量的字符就变为@.&无效)

13. execute sql file statements

@ D:\Chengf\temp.sql (此处应当注意,路径是区分大小写的)

14. Use define constant view

define;

15. Constant grammar

设置常量
define temp=7850
查看常量
define temp
删除常量
undefine temp

16. The use of column format the output

column empno heading '员工编号' format 9999
column ename heading '员工姓名' format a10
column mgr heading   '上级编号' format 9999
column hiredate heading '受雇日期' justfify center
column sal heading '员工工资' format $999.999.99

17. The row number is provided a data display

set pagesize 20

18. Set row shows how many characters

set linesize 20

19. Set the header and footer

ttitle页眉.btitle页脚

20.break command packet, compute command to calculate and

break on deptno;
compute sum of sal on deptno;

select empno.ename.mgr.sal.deptno
from scott.emp order by deptno;

21. Clear column format

clear columns

22. Create a permanent table space

create tablespace myspace 
datafile '文件路径'
size 文件大小
autoextend on next 自动增加大小
maxsize 文件最大值

23. Check the table space properties

select * from dba_tablespace wheretablespace_name='表空间名';

Table 24. Change the state space

alter tablespace 表空间名 表空间状态;

25. Modify the table space name

alter tablespace 表空间名1 rename to 表空间名2;

26. The use of free space in the data dictionary to see information

select * from dba_free_space where tablespace_name='表空间名称';

27. The use of the data dictionary view the table space data file information

select * from dba_data_files wheretablespace_name='表空间名称';

28. The modified table space corresponding to the size of the data file

alter database
datafile '表空间文件路径名称'
resize 大小

29. Add a new data file for the table space

alter tablespace myspace
add datafile '数据文件路径名称'
size 大小
autoextend on next 自增大小 maxsize 最大值;

30. Delete myspace table space data file

alter tablespace myspace
drop datafile '数据文件名称';

31. The modified automatic scalability myspace tablespace data files

alter database
datafile '表空间文件路径名称'
autoextend off;

32. Set the file status table space is offline drop

alter database
datafile '表空间路径名称'
offline drop;

33. Mobile data file tablespace

(1)alter tablespace 表空间名称 offline;先设置表空间状态为offline
(2)手动操作.将磁盘中的表空间数据文件移动到新的路径
(3)使用alter tablespace语句修改表空间文件路径名称
alter tablespace myspace 
rename datafile '表空间路径名称'
to
'新的表空间路径名称';
(4)修改myspace表空间状态
alter tablespace 表空间名称 online;

34. Delete table space

drop tablespace 表空间名称
including contents and datafiles;

35. Create a temporary table space

create temporary tablespace 表空间名称
tempfile '表空间路径名称'
size 大小
autoextend on next 自增大小 maxsize 最大大小;

36. Create a temporary table space where the group will be designated as group1

create temporary tablespace 表空间名称
tempfile '表空间路径名称'
size 大小
tablespace group group1;

37. modify the temporary table space group

alter tablespace 临时表空间名称 tablespace group group2;

38. Create a large table space

create bigfile tabliespace mybigspace
datafile '表空间路径名称'
size 大小;

39. Modify the default table space

alter database default tablespace 表空间名称;

40. Create a temporary table level things

create global temporary table temp_student(
)on commit delete rows(事物级别的意思);

41. The use of a temporary table level things

select * from temp_student;
commit;提交事物。
提交后表还在.但数据被清除

42. Create a temporary table session

create global temporary table temp_book(
)on commit preserve rows(会话级别的意思);
commit;
断开该用户连接才会清除数据

43. The external file is read
first documented in the corresponding path
and then
create directory external_card as'E:\external';
creates a corresponding path

The next step is to create an external table

create table e_card(
对应的数据
)organization external(
//里边这一团是什么东西噢
type oracle_loader//指定访问外部数据文件的驱动程序.oracle默认为oracle_loader
default directory external_card //对应上一步路径

access parameters(
fields terminated by '.')
location ('蓝胖子没有耳朵.txt')
);

Use 44.reject limit of the sentence

External table error-prone. With this allows numerous errors

create table e_card(
对应的数据
)organization external(
type oracle_loader
default directory external_card
access parameters(
fields terminated by '.')
location ('card.txt')
)reject limit unlimited;

45. The store error data to a specified file

create table e_card(

对应的数据
)organization external(
type oracle_loader
default directory external_card
access parameters(

records delimited by newline
badfile 'card_bad.txt'

fields terminated by '.')
location ('card.txt')
);

46. ​​The error log file

create table e_card(
对应的数据
)organization external(
type oracle_loader
default directory external_card
access parameters(

records delimited by newline
badfile 'card_bad.txt'
logfile 'card_log.txt'

fields terminated by '.')
location ('card.txt')
);

47. Create a range partitioned table

create table part_book(
数据库内容
)partition by range(booktime)(
partition part1 values less than ('01-1月-2008')tablespacemytemp1.
partition part2 values less than ('01-1月-2009')tablespacemytemp2.
partition part1 values less than (maxvalue)tablespacemytemp3
)

48. Create a hash-partitioned tables

create table part_book(
数据库内容
)partition by hash(bid)(
partition part1 tablespace mytemp1.
partition part2 tablespace mytemp2.
)

49. Create a list partition tables

create table part_book(
数据库内容
)partition by list(bookpress)(
partition part1 values ('chengf') tablespace mytemp1.
partition part1 values ('blog') tablespace mytemp2
)

50. Create Composite range-hash partitioned table

create table part_book(
数据库内容
)partition by range(booktime)
subpartition by hash(bid)
subpartitions 2 store in(mytemp1.mytemp2)
(
partition part1 values less than ('01-1月-2008').
partition part1 values less than ('01-1月-2009').
partition part1 values less than (maxvalue)
);

Guess you like

Origin blog.csdn.net/qq_34156628/article/details/90741743