版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Oracle常用命令Oracle数据类型:Create table test1(name char(10,sex char(1;Insert into test1 values(tomcatt北京,f;Create table test2(name nchar(10,sex nchar(1;Insert into test2 values(to mcatt北京,男;删除表 drop table 表名;Create table test3(name varchar2(10,sex varchar2(2;Insert into test3 values(tomcatt北京,f;/插入值过大Inse
2、rt into test3 values(tomcat北京,f;Create table test4(name varchar2(10,age number(3,salary number(8,2;Create table test5(name varchar2(10,birth date;Insert into test5 values(Tom,28-2月-08;Insert into test5 values(Allen,sysdate;DDL:创建表create table scott.test6(eid number(10,name varchar2(20,hiredate date
3、default sysdate,salary number(8,2 default 0插入数据时若没有指定hiredate,salary的话则会取默认值数据字典:Dba-所有方案包含的对象信息All-用户可以访问的对象信息User-用户方案的对象信息Select * from user_tables;Select * from all_tables;约束:域完整性约束:not null check实体完整性约束:unique primary key参照完整性约束:foreign key视图:Create or replace view v1(eid,name,salary as select
4、empno,ename,sal from emp where deptno = 30;序列:sequenceCreate sequence mysequence1 increment by 1 start with 1 nomaxvalue nocycle;Insert into test values(mysequence1.nextval,tom;Create sequence student_sequence start with 1 increment by 1;Insert into student values(student_sequence.nextval,john;表间数据拷
5、贝:Insert into dept1(id,name select deptno,dname from dept;实例(创建表 ID字段自增:-create table test2(id char(10 primary key not null, name char(10;-create sequence test2_sequence increment by 1 start with 1 nomaxvalue nocycle;-insert into test2 values(test2_sequence.nextval,'john'-insert into test2 v
6、alues(test2_sequence.nextval,'allen'-insert into test2 values(test2_sequence.nextval,'candy'-insert into test2 values(test2_sequence.nextval,'aaaa'-insert into test2 values(test2_sequence.nextval,'bbbbb'-insert into test2 values(test2_sequence.nextval,'cccccc'
7、-insert into test2 values(test2_sequence.nextval,'ddddd'-insert into test2 values(test2_sequence.nextval,'eeeee'-insert into test2 values(test2_sequence.nextval,'ggggg'-insert into test2 values(test2_sequence.nextval,'jowwwwhn'-insert into test2 values(test2_sequence.
8、nextval,'aaaadd'-insert into test2 values(test2_sequence.nextval,'ggghhh'-insert into test2 values(test2_sequence.nextval,'eeettt'-insert into test2 values(test2_sequence.nextval,'wwwttt'select * from test2;查看表结构EDITDATA 表名;修改表字段:Alter table 表名 modify(字段名类型约束;alter ta
9、ble test modify (addd varchar2(10 null;alter table 表名 add(字段名类型约束;alter table test add(age varchar2(5;%51.登陆系统用户sqlplus 然后输入系统用户名和密码登陆别的用户conn 用户名/密码;2.创建表空间create tablespace 空间名datafile 'c:空间名' size 15M -表空间的存放路径,初始值为15MautoExtend on next 10M -空间的自动增长的值是10Mpermanent online; -永久使用3.创建用户creat
10、e user shi -创建用户名为shiidentified by scj -创建密码为scjdefault tablespace 表空间名 -默认表空间名temporary tablespace temp -临时表空间为tempprofile default -受profile文件的限制quota unlimited on 表空间名; -在表空间下面建表不受限制4.创建角色create role 角色名 identified by 密码;5.给角色授权grant create session to 角色名;-给角色授予创建会话的权限grant 角色名 to 用户名; -把角色授予用户6.给
11、用户授予权限grant connect,resource to shi;-给shi用户授予所有权限Grant dba to shi;-给shi 用户授予DBA权限grant create table to shi; -给shi用户授予创建表的权限7.select table_name from user_tables; 察看当前用户下的所有表8.select tablespace_name from user_tablespaces; 察看当前用户下的表空间9.select username from dba_users;察看所有用户名称命令必须用sys as sysdba登陆10.创建表cr
12、eate table 表名(id int not null,name varchar2(20 not nulltablespace 表空间名 -所属的表空间storage(initial 64K -表的初始值minextents 1 -最小扩展值maxextents unlimited -最大扩展值;11.-为usrs表添加主键和索引alter table usersadd constraint pk primary key (ID;12.为已经创建users表添加外键alter table usersadd constraint fk_roleid foreign key (roleidre
13、ferences role(role_id on delete cascad; -下边写主表的列on delete cascad是创建级联13.把两个列连接起来select concat(name,id from 表名; -把name和id连接起来14.截取字符串select column(name,'李' from 表名; -把name中的李去掉15.运行事务之前必须写set serveroutput on; -打开输入输出(不写的话,打印不出信息16.while的应用declare -声明部分ccc number:=1; -复职a number:=0;begin -事务的开
14、始while ccc<=100 loop -循环if(ccc mod 3=0 then -条件dbms_output.put_line(ccc|',' -打印显示a:=a+ccc;end if; -结束ifccc:=ccc+1;end loop; -结束循环dbms_output.put_line(a;end; -结束事务/17.select into 的用法 -只能处理一行结果集declarename varchar(30;beginselect username into namefrom userswhere id=2;dbms_output.put_line(
15、39;姓名为:'|name;end;%18.利用%rowtype属性可以在运行时方便的声明记录变量和其他结构Set serveroutput on;Declareutype users%rowtype;BeginSelect * into utype from users where id=20;Dbms_output.put_line('姓名'| utype.username;Dbms_output.put_line('生日'| utype.brithday;end;/ -%rowtype想当于复制一个表19.游标的定义和使用DeclareCursor
16、 ucur is select * from users; -声明游标Us users%rowtype;-定义与游标想匹配的变量BeginOpen ucur;-打开游标Fetch ucur into us;While ucur %found loop -使用循环遍历游标的查询结果Dbms_output.put_line('姓名:'|us.username|'生日'|us.brithday;Fetch ucur into us;End loop;Close ucur; -关闭游标End;=%found在前一条的fetch语句至少对应数据库的一行时,%found属性
17、值为true,否则为false;% notfound 在前一条fetch语句没有对应的数据库行时,%notfound属性值为true,否则为false;%isopen 在游标打开时%isopen属性值为true;否则为false;%rowcount显示迄今为止从显示游标中取出的行数20.删除drop tablespace 空间名 including contents; -删除表空间和里面的内容drop table 表名 -删除表drop user 用户名 -删除用户查看有哪些表空间:Select tablespace_name from dba_tablespaces;查看某个表属于哪个表空间
18、:Select tablespace_name from tabs where table_name=表名;在指定的表空间创建表:create table(. tablespace users;查询前N条数据:select * from 表名 where rownum<=N;Oracle中创建一个数据库:打开Database Configuration Assistant,可以通过视图创建数据库。创建成功后,系统服务里面会多一个OracleServer 数据库名的服务项。查看所有表空间大小:select * from dba_free_space;问题:user lacks create session privilege logon deniedgrant create session to the_user;删除用户:Drop user 用户名 cascade;导入数据库对象:IMP
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 安徽亳州刘桥中学2026届初三下学期中考适应性月考(八)数学试题含解析
- 袋鼠式护理:不仅仅是保暖
- 医院门诊部绩效考核制度
- 中小学校审计制度
- 审计局走访制度
- 审计人员管理制度
- 大众绩效考核制度
- 审计局控烟监督管理制度
- 保安部绩效考核制度
- 健全医院内部审计制度
- 江苏省交通设施代建合同范本
- 2026年及未来5年中国耐火粘土行业发展运行现状及投资战略规划报告
- T∕CIECCPA 125-2026 温室气体 产品碳足迹量化方法与要求 燃气-蒸汽联合循环发电产品
- 2024版2026春新教科版科学三年级下册教学课件:第一单元 辨别方向 单元小结复习
- 物业管理公司员工招聘条件及流程
- 2025年上海大专自主招生免笔试及答案
- 汽车制造焊接工艺技术规范
- 2025年黑龙江生态工程职业学院单招职业倾向性测试模拟测试卷附答案解析
- 融媒体应聘考试题及答案
- (新版)上海安全员C3考试(重点)题库300题(含答案)
- 老年2型糖尿病合并认知障碍照护方案
评论
0/150
提交评论