建表空间
create tablespace NK_DATA
datafile 'D:/oracle/product/10.2.0/oradata/orcl/NK_DATA1.def' size 1000M
autoextend on next 1000M maxsize unlimited logging
extent management local autoallocate
segment space management auto;
建用户
create user UNIREPORT
identified by "UNIREPORT"
default tablespace NK_DATA
temporary tablespace FINTEMP
profile DEFAULT;
授权
grant connect to UNIREPORT;
grant dba to UNIREPORT;
grant resource to UNIREPORT;
grant unlimited tablespace to UNIREPORT;导出
exp SZ/SZ@fin file=d:\SZ.dmp log=d:\SZ.log grants=y
导入
imp FIN/FIN@ORCL file=F:\FIN.dmp log=F:\FIN.dmp.log fromuser=FIN touser=FIN buffer=4096000 feedback=100000 新建表
create table aaa (
jl_hh NUMBER(20) default -1 not null,
name VARCHAR2(20),
lsh VARCHAR2(100)
)
新增表字段
alter table aaa add KK_BBB varchar(100);
修改表名
alter table old_table_name rename to new_table_name;
建立索引
create index IDX_BB_ZZ_SJZZ_HH on BB_ZZ (SJZZ_HH)
tablespace FIN_TABLE
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 64K
minextents 1
maxextents unlimited
);查询语句
select * from tablename;
通过等值联接
select z.name , y.position , y.score from TableX x inner join TableY y on x.id = y.id
inner join TableZ z on x.department = z.id
外联接
select x.Name,y.Posistion,y.Scored from TableX x left join TableY y ON x.ID =y.ID
基础函数
sum,distinct ,Decode,nvl,case,with,intersect,minus,substr,having
DECODE(value, if1, then1, if2,then2, if3,then3, . . . else )
sum,求和
distinct,去重
nvl,如nvl(字段,‘x’)字段值等于null
case, case when t=1 then '男' else ‘女’end
with 在两个值之间的意思
Intersect 返回两个输入集合的交集,可以选择保留重复项。语法 Intersect(«Set1», «Set2»[, ALL])
minus, 取差集
substr, SUBSTR(str,pos,len);
这种表示的意思是,就是从pos开始的位置,截取len个字符(空白也算字符) 。
having HAVING对由sum或其它集合函数运算结果的输出进行限制
等号=与in
能用=尽量不要用in,数据量大时,in速度比较慢,举例(a=5 or a=6) 和 a in (5,6)
sqlldr:
大批量数据导入时使用sqlldr速度很快,需要连个文件,一个转换文件
for /r C:\sqlldr %%a in (*.csv) do type "%%a" >>%%~dpanewcsv.txt
一个控制文件
LOAD DATA
INFILE 'c:\sqlldr\newcsv.txt'
APPEND INTO TABLE aaa
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
(TJR,TJSJ,JL_HH)
注意转换后的newcsv.txt文件列,必须大于等于控制文件的列。建立视图
create or replace view v_aaa as
select a.JL_HH, a.name from aaa a;
建立计数器
create sequence SEQ_aaa
minvalue 0
maxvalue 99999999
start with 1970540
increment by 1
cache 20
cycle;建立同义词
create or replace synonym aaa_1 for FIN.aaa;同一实例下连个用户可以直接建立,但是需要授权;
不通实例需要首先建立dblink;
create tablespace NK_DATA
datafile 'D:/oracle/product/10.2.0/oradata/orcl/NK_DATA1.def' size 1000M
autoextend on next 1000M maxsize unlimited logging
extent management local autoallocate
segment space management auto;
建用户
create user UNIREPORT
identified by "UNIREPORT"
default tablespace NK_DATA
temporary tablespace FINTEMP
profile DEFAULT;
授权
grant connect to UNIREPORT;
grant dba to UNIREPORT;
grant resource to UNIREPORT;
grant unlimited tablespace to UNIREPORT;导出
exp SZ/SZ@fin file=d:\SZ.dmp log=d:\SZ.log grants=y
导入
imp FIN/FIN@ORCL file=F:\FIN.dmp log=F:\FIN.dmp.log fromuser=FIN touser=FIN buffer=4096000 feedback=100000 新建表
create table aaa (
jl_hh NUMBER(20) default -1 not null,
name VARCHAR2(20),
lsh VARCHAR2(100)
)
新增表字段
alter table aaa add KK_BBB varchar(100);
修改表名
alter table old_table_name rename to new_table_name;
建立索引
create index IDX_BB_ZZ_SJZZ_HH on BB_ZZ (SJZZ_HH)
tablespace FIN_TABLE
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 64K
minextents 1
maxextents unlimited
);查询语句
select * from tablename;
通过等值联接
select z.name , y.position , y.score from TableX x inner join TableY y on x.id = y.id
inner join TableZ z on x.department = z.id
外联接
select x.Name,y.Posistion,y.Scored from TableX x left join TableY y ON x.ID =y.ID
基础函数
sum,distinct ,Decode,nvl,case,with,intersect,minus,substr,having
DECODE(value, if1, then1, if2,then2, if3,then3, . . . else )
sum,求和
distinct,去重
nvl,如nvl(字段,‘x’)字段值等于null
case, case when t=1 then '男' else ‘女’end
with 在两个值之间的意思
Intersect 返回两个输入集合的交集,可以选择保留重复项。语法 Intersect(«Set1», «Set2»[, ALL])
minus, 取差集
substr, SUBSTR(str,pos,len);
这种表示的意思是,就是从pos开始的位置,截取len个字符(空白也算字符) 。
having HAVING对由sum或其它集合函数运算结果的输出进行限制
等号=与in
能用=尽量不要用in,数据量大时,in速度比较慢,举例(a=5 or a=6) 和 a in (5,6)
sqlldr:
大批量数据导入时使用sqlldr速度很快,需要连个文件,一个转换文件
for /r C:\sqlldr %%a in (*.csv) do type "%%a" >>%%~dpanewcsv.txt
一个控制文件
LOAD DATA
INFILE 'c:\sqlldr\newcsv.txt'
APPEND INTO TABLE aaa
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
(TJR,TJSJ,JL_HH)
注意转换后的newcsv.txt文件列,必须大于等于控制文件的列。建立视图
create or replace view v_aaa as
select a.JL_HH, a.name from aaa a;
建立计数器
create sequence SEQ_aaa
minvalue 0
maxvalue 99999999
start with 1970540
increment by 1
cache 20
cycle;建立同义词
create or replace synonym aaa_1 for FIN.aaa;同一实例下连个用户可以直接建立,但是需要授权;
不通实例需要首先建立dblink;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货