oracle教程
- 格式:docx
- 大小:32.51 KB
- 文档页数:12
Oracle数据类型:数据类型含义char 定长的字符型数据,最大长度可达2KBnchar存储Unicode字符集的定长字符型数据,最大长度为2KBVarchar2 可变长的字符型数据,最大长度可达4000个字符Nvarchar2 存储Unicode字符集的变长字符型数据,最大长度为4KBnumber 存储整型或浮点型数据Date 存储日期数据Long 存储最大长度为2GB的变长字符数据Raw 存储非结构化数据的变长字符数据,最长为2KBLong Raw 存储非结构化数据的变长字符数据,最长为2GBRowid存储表中列的物理地址的二进制数据,占用固定的10个字节Blog 二进制大对象,最大长度为4GBClob字符大对象,最大长度为4GBNclob存储多达4GB的Unicode字符数据Bfile把非结构化的二进制数据存储在数据库以外的操作系统文件中Urowid存储表示任何类型列地址的二进制数据float 存储浮点数--------------------------------------------------------------------------------------------char与Varchar2的区别就是,char你给他多少位子他就用多少位子。
Varchar2他用多少位子你就给他多少位子。
---------------------------------------------------------------------------创建表格create table [表名]([字段名字] [类型] ,[字段名字] [类型]);---------------------------------------------------------------------------添加数据insert into [表名]values [添加的数据];--------------------------------------------------------------------------删除表格drop table [表名];---------------------------------------------------------------------------添加字段alter table [表名]add [字段] [类型];add 添加modify 修改---------------------------------------------------------------------------修改表格数据update [表名]set [修改数据的字段] = [修改的数据]where [要修改数据的字段] = [要修改的数据];update employeessetjob_id = (select job_id from employees where empyee_id= 205) whereemployee_id = 114当前时间的添加update aset tame = sysdatewhere name = 1--------------------------------------------------------------------------- 使用序列号create sequence dept_deptid_sepincrement by 10 --- 每次递增10staet with 120 ---从120开始递增maxvalue 99999 ---最大到9999INSERTINTO [表名](字段1, 字段)VALUES (dept_deptid_seq.NEXTVAL, 数据);------- 字段1里面是序列号DROPSEQUENCE dept_deptid_seq; -- 删除序列号--------------------------------------------------------------------------- select * from departments forupdate;直接修改表数据;---------------------------------------------------------------------------创建同义词create synonym [同义词]for [原名];---------------------------------------------------------------------------索引 indexcreateindex [索引名字]on [表名](字段名字);创建了索引以后,以后查找索引过的数据,效率会更快。
视图 viewcreate view [视图名字]asselect * from [要创建的表名];---------------------------------------------------------------------------union 与 union all的区别。
location_id会将每一笔复合条件的资料都列出来,无论资料有无重复!---------------------------------------------------------------------------主键primary key主键的意思就是代表着唯一性。
每个主键在oracle数据都内部索引表里分配一个地址。
查询的时候就根据他的地址查找数据。
这样比一样的查询语句效率快!外键的意思就是,你在外部建立了一个表,如果外部的表里面的字段是更具别的表里面的主键的字段一样,那么就可以当作外键。
---------------------------------------------------------------------------用法例:select length(location_id) ,from departmentsconcut('hello','world') helloworld合并substr('helloworld',1,5) hello 字符截取函数length('helloworld') 10 长度inset ('helloworld','w') 6 指定位数lpad (salary,10,'*') *****24000 用*号补满前面十位rpad用*号补满后面十位trim ('h' from'helloworld') elloworld修剪---------------------------------------------------------------------------like'q%'显示开头的是q的数据like'_q%'显示第二个是q的数据like '%q%显示其中有q的数据where [条件] or [条件] 随便满足哪个条件都可以。
where [条件] no in [条件] 满足前面的,并且不满足后满的。
---------------------------------------------------------------------------avg平均值 max最大值 min最小值 sum总和group by 不可以和where一起使用,所以就用having 代替group by ..... having 当什么什么的时候--------------------------------------------------------------------------- 五、数据库测试有一张表名称为:test_tab,有下列两个字段:id 人员编号, name 姓名, age 年龄表数据如下:请各写一条SQL语句,完成下列各题:求取所有人员的年龄的平均值、最大值。
selectavg(age) from test_tab;select max(age) from test_tab;选出所有存在重名的人员IDselect * from test_bat where name in(select name from test_tab group by name having count(*) > 1)删除姓名重复的记录,每个姓名仅保留年龄最小一条记录,其他删除。
delte from test_bat where name in(select name from test_tab group by name having count(*) > 1)and age <> min(age)select * from test_bat where name in(select name from test_tab group by name having count(*) > 1)delete employees ---删除 employees 表里面job_id字段里为cheng5的那行记录。
where job_id = 'cheng5'--------------------------------update employees ---修改 employees 表里面 salary 字段中的 2524 为 555。
set salary = 555where salary = 2524--------------------------------select substr(salary,1,2) from employees --- 显示employees表里面job_id字段里为cheng5的前面两位。
where job_id = 'cheng5';select CONCAT(salary, job_id) as job_salary from employees -- 在employees表里面aslary和job_id数据合并起来,用job_salary字段显示!select INSTR(job_id, 'e') from employees -- 显示employees表里面job_id字段里记录中e的位子select LENGTH(job_id) from employees --显示employees表里面job_id字段的记录长度!select LPAD(salary,10,'*') from employees -- 显示employees表里面salary字段,如果长度不满足10个前面用*号补满select RPAD(salary, 10, '*') from employees --显示employees表里面salary字段,如果长度不满足10个后面用*号补满selectTRIM(job_id) from employees --去显示出来的空格--------------------------------select ROUND(45.926, 2) from employees 显示小数点后2位,后面的四舍五入。