当前位置: 移动技术网 > IT编程>数据库>Oracle > Oracle入门学习一

Oracle入门学习一

2020年05月02日  | 移动技术网IT编程  | 我要评论

范娜,西安石油大学是几本,诛仙什么时候开新区

oracle的安装,用户授权,表格操作,数据类型,ddl表格,dml数据。

下一篇:oracle入门学习二

学习视频:https://www.bilibili.com/video/bv1tj411r7ec?p=15

安装教程附带百度云安装包:

oracle百度云安装包: https://pan.baidu.com/s/1qvwwcur37j2jxeecybe5hq  提取码:5abz          

上面的oracle服务安装完,去打开sqldeveloper的客户端会报错“sqldeveloper缺少对应的快捷方式”,这时候安装下面的sqldeveloper就可以解决问题。

sqldeveloper附件:

表空间用户授权:

sid唯一标识计算机oracle的数据库名称,一台计算机可能安装多个oracle,此时需要sid区分。sid放在oracle账号名@后面。要运行oracle,必须开启两个服务,一个是主服务“oracleservicesid”,另外一个是主服务监听器。如果客户端无法连接,可以检查一下这两个服务是否都开启了。

sys和system都是系统用户,只是sys会有更大的权限。system只能使用normal方式登录,而sys只能以sysdba或sysoper角色登录。sys的操作是不可逆的,谨慎使用。

创建属于自己的用户:

  • 使用 create tablespace 创建表命名空间
    • create tablespace pratice
      datafile 'e:\pratice.dbf'
      size 10m
  • 使用 create user创建用户
    • create user bibi
      identified by bibi
      default tablespace pratice
  • 使用 grant 给用户授权,这里的授权是指“分配角色”,“分配角色”和“分配权限”是不一样的。“grant create view to bibi”是分配创建视图权限给bibi用户。
    • -- connect临时用户 resouce可靠的正式用户 dba数据库管理员
      grant connect,resource to bibi

到这里总结一下上面过程:安装oracle服务器软件->创建数据库(安装时自动配置)->配置监听器(安装时自动配置)->安装oracle数据库操作客户端sqldeveloper->创建用户的表空间->创建用户并授权

数据类型:

  • number,类似c#的double类型,number(4,3)表示总共最多四个数字,小数位后最多3位。number(3,-1)表示小数位往左移一位139->130。
    • declare
        --最多就五位整数值,有小数位则四舍五入。
        test number(5) := 1234.64;
        --整数最多就两位,小数位最多就三位,小数位多出来的就四舍五入。
        test1 number(5, 3) := 34.9345;
        test2 number(3,-1):=998;
      begin
        dbms_output.put_line(test);
        dbms_output.put_line(test1);
        dbms_output.put_line(test2);
      end;
      
      output:
      1235
      34.935
      1000
  • varchar2,变长字符串类型,最多4000字节。如果是空串则null处理。是oracle独有的。
  • char,固定长度存储,如果内容不满则用空格补上。
  • clob,存储大文本。
  • date:年月日时分秒都有。

创建表:create table

create table person(
 name varchar2(20),
 age number,
 gender char(1),
 phone varchar2(20)
)

删除表:drop table

drop table person

修改表:alter table

-- 表格添加列
alter table person add name1 varchar2(30);
-- 表格删除列
alter table person drop column name1;
-- 表格重命名列
alter table person rename column name1 to name2;
-- 表格名字重命名
alter table person rename to people

修改表结构步骤:数据备份,清空原表数据,修改原表结构,备份数据插入原表。

表格添加数据:三种写法

-- inset into tablename (列1,列2..,最后列) values(值1,值2...)
insert into person
  (name, age, gender, phone)
values
  ('哈士奇大叔', 90, '1', '110');
  
-- inset into tablename (列1,列2..,最后列) values(值1,值2...)
-- 列顺序,列多少都可以,值对得上前面的列就可以了
insert into person
  (name, age)
values
  ('哈士奇大叔', 90);

-- 没有列参数,把所有列值都填上,且必须按顺序
insert into person values ('哈士奇大叔', 90, '1', '111');

表删除数据

-- 删除表的所有数据
delete from person
delete person
-- 按条件删除数据
delete from person where name='哈士奇大叔'

表修改数据

update person set name='柯基大叔',age=88;
update person set name='喵喵' where age=90;

表查询数据

-- *代表所有列
select * from person;
select * from person where ... order by desc

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网