返回顶部
首页 > 资讯 > 数据库 >ORACLE 12C基础
  • 725
分享到

ORACLE 12C基础

2024-04-02 19:04:59 725人浏览 安东尼
摘要

1.CON_ID,0为cdb,1为cdb$root, 2为pdb seed,3以上为pdb2.自增长列在12c之前,oracle只能通过sequence来实现这个功能sys@newtestCDB> c

1.CON_ID,0为cdb,1为cdb$root, 2为pdb seed,3以上为pdb
2.自增长列
ORACLE 12C基础
在12c之前,oracle只能通过sequence来实现这个功能
sys@newtestCDB> create table test(id number generated always as identity , name varchar2(20));

Table created.

Elapsed: 00:00:00.04
sys@newtestCDB> insert into test(name) values('smith');

1 row created.

Elapsed: 00:00:00.01
sys@newtestCDB> insert into test(name) values('smith3');

1 row created.

Elapsed: 00:00:00.01
sys@newtestCDB> insert into test(name) values('smith4');

1 row created.

Elapsed: 00:00:00.01
sys@newtestCDB> select * from test;

    ID NAME

     1 smith
     2 smith3
     3 smith4

Elapsed: 00:00:00.02
sys@newtestCDB> update test set id=1 where id=2;
update test set id=1 where id=2
*
ERROR at line 1:
ORA-32796: cannot update a generated always identity column

Elapsed: 00:00:00.03
sys@newtestCDB> insert into test(id,name) values(null,'smith4');
insert into test(id,name) values(null,'smith4')
*
ERROR at line 1:
ORA-32795: cannot insert into a generated always identity column

Elapsed: 00:00:00.01
sys@newtestCDB> insert into test(id,name) values(2,'smith4');
insert into test(id,name) values(2,'smith4')
*
ERROR at line 1:
ORA-32795: cannot insert into a generated always identity column
sys@newtestCDB> delete from test where id=3;

1 row deleted.

Elapsed: 00:00:00.03
sys@newtestCDB> insert into test(name) values('smith5');

1 row created.

Elapsed: 00:00:00.01
sys@newtestCDB> select * from test;

    ID NAME

     2 smith3
     4 smith5

Elapsed: 00:00:00.01
结论:
GENERATED ALWAYS AS IDENTITY 可以不指定该列进行插入
GENERATED ALWAYS AS IDENTITY不能在该列中插入NULL值
GENERATED ALWAYS AS IDENTITY不能指定具体值插入
GENERATED ALWAYS AS IDENTITY 不能使用update更新该列
sys@newtestCDB> create table test(id number generated by default as identity , name varchar2(20));

Table created.

Elapsed: 00:00:00.03
sys@newtestCDB> insert into test(name) values('smith');

1 row created.

Elapsed: 00:00:00.01
sys@newtestCDB> insert into test(name) values('smith3');

1 row created.

Elapsed: 00:00:00.01
sys@newtestCDB> insert into test(name) values('smith4');

1 row created.

Elapsed: 00:00:00.01
sys@newtestCDB> insert into test(id,name) values(null,'smith4');
insert into test(id,name) values(null,'smith4')
*
ERROR at line 1:
ORA-01400: cannot insert NULL into ("SYS"."TEST"."ID")

Elapsed: 00:00:00.02
sys@newtestCDB> insert into test(id,name) values(2,'smith3');

1 row created.

Elapsed: 00:00:00.01
sys@newtestCDB> update test set id = NULL where id=2;
update test set id = NULL where id=2
*
ERROR at line 1:
ORA-01407: cannot update ("SYS"."TEST"."ID") to NULL
结论:
GENERATED BY DEFAULT AS IDENTITY 可以不指定该列进行插入
GENERATED BY DEFAULT AS IDENTITY不能在该列中插入NULL值
GENERATED BY DEFAULT AS IDENTITY 可以指定具体值插入
GENERATED BY DEFAULT AS IDENTITY 可以使用update更新该列,但不能更新为NULL
sys@newtestCDB> create table test(id number generated by default ON NULL as identity , name varchar2(20));

Table created.

Elapsed: 00:00:00.03
sys@newtestCDB> insert into test(id,name) values(null,'smith4');

1 row created.

Elapsed: 00:00:00.01
结论:

GENERATED BY DEFAULT ON NULL AS IDENTITY 可以不指定该列进行插入
GENERATED BY DEFAULT ON NULL AS IDENTITY 方式可以指定具体值插入
GENERATED BY DEFAULT ON NULL AS IDENTITY 可以在该列中插入null值
GENERATED BY DEFAULT ON NULL AS IDENTITY 可以使用update更新该列
sys@newtestCDB> col tablename fORMat A20
sys@newtestCDB> col table_name format A20
sys@newtestCDB> col sequence_name format A20
sys@newtestCDB> SELECT a.name AS table_name,
2 b.name AS sequence_name
3 FROM sys.idnseq$ c
4 JOIN obj$ a ON c.obj# = a.obj#
5 JOIN obj$ b ON c.seqobj# = b.obj#
6 where a.name='TEST';

TABLE_NAME SEQUENCE_NAME


TEST ISEQ$$_83962

Elapsed: 00:00:00.01
sys@newtestCDB> create table test(id number generated by default as identity , name varchar2(20));

Table created.

Elapsed: 00:00:00.03
sys@newtestCDB> SELECT a.name AS table_name,
2 b.name AS sequence_name
3 FROM sys.idnseq$ c
4 JOIN obj$ a ON c.obj# = a.obj#
5 JOIN obj$ b ON c.seqobj# = b.obj#
6 where a.name='TEST';

TABLE_NAME SEQUENCE_NAME


TEST ISEQ$$_83964

Elapsed: 00:00:00.01
sys@newtestCDB> SELECT object_name, object_type FROM user_objects where object_name='ISEQ$$_83964';

OBJECT_NAME

OBJECT_TYPE

ISEQ$$_83964
SEQUENCE

Elapsed: 00:00:00.05
sys@newtestCDB> drop table test;

Table dropped.

Elapsed: 00:00:00.04
sys@newtestCDB> SELECT object_name, object_type FROM user_objects where object_name='ISEQ$$_83964';

no rows selected

Elapsed: 00:00:00.00
sys@newtestCDB> create table test(id number generated by default as identity , name varchar2(20));

Table created.

Elapsed: 00:00:00.06
sys@newtestCDB> SELECT a.name AS table_name,
2 b.name AS sequence_name
3 FROM sys.idnseq$ c
4 JOIN obj$ a ON c.obj# = a.obj#
5 JOIN obj$ b ON c.seqobj# = b.obj#
6 where a.name='TEST';

TABLE_NAME SEQUENCE_NAME


TEST ISEQ$$_83966

Elapsed: 00:00:00.01
sys@newtestCDB> drop SEQUENCE ISEQ$$_83966;
drop SEQUENCE ISEQ$$_83966
*
ERROR at line 1:
ORA-32794: cannot drop a system-generated sequence

Elapsed: 00:00:00.02
结论:
Identity Columns 是基于序列实现的
GENERATED IDENTITY 中sequence不能单独被删除
GENERATED IDENTITY 中sequence 表被删除时同时删除
ORACLE 12C基础这是12.1的图,12.2还有新变化

您可能感兴趣的文档:

--结束END--

本文标题: ORACLE 12C基础

本文链接: https://lsjlt.com/news/39189.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
  • ORACLE 12C基础
    1.CON_ID,0为cdb,1为cdb$root, 2为pdb seed,3以上为pdb2.自增长列在12c之前,Oracle只能通过sequence来实现这个功能sys@newtestCDB> c...
    99+
    2024-04-02
  • Oracle 12c CDB&PDB 基本维护
    1.查看数据库是否为多租户数据库(CDB)SQL> SELECT CDB FROM V$DATABASE; CDB YES2.查看当前容器名字以下命令只能在12c客户端输入SQL> sh...
    99+
    2024-04-02
  • 基于CentOS7安装部署 Oracle 12c
    基于CentOS7安装部署 Oracle 12c 简介 Oracle Database,又名Oracle RDBMS,或简称Oracle。是甲骨文公司的一款关系数据库管理系统。是目前最流行的客户/服务...
    99+
    2024-04-02
  • Oracle基础(一)
          数据库系统:     微软的SQL  server ,  IBM的DB2, 甲骨文公司的Ora...
    99+
    2024-04-02
  • Oracle基础知识
    1、Oracle分页查询 现有表employee_tbl,要求按年龄降序,分页查询数据,每页3条数据。 ID  NAME         DATE                             SIGNIN   AGE 1 ...
    99+
    2018-10-23
    Oracle基础知识
  • oracle基础~rac-asm
    原文:https://www.cnblogs.com/danhuangpai/p/14490187.html...
    99+
    2021-07-28
    oracle基础~rac-asm 数据库入门 数据库基础教程
  • Oracle基础语句
    1、创建表create table IT_EMPLOYEES(ENPLOYEES_ID NUMBER(6) NOT NULL UNIQUE,FIRST_NAME VARCHAR2(20),LAST_...
    99+
    2024-04-02
  • 数据库基础(Oracle)
    1.前言 2.select简单查询 3.单值函数 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~...
    99+
    2021-08-08
    数据库基础(Oracle)
  • 01. Oracle(基础语法)
    1. 函数 1.1 大小写转换函数 函数 描述 LOWER() 全小写 UPPER() 全大写 INITCAP() 首字母大写 1.2 字符串操作函数 函数 描述 concat() 拼接字...
    99+
    2022-03-14
    01. Oracle(基础语法)
  • Oracle数据基础(二)
    一. SQL基础查询基本查询语句    1. FROM子句          SELECT * FROM T...
    99+
    2024-04-02
  • Oracle数据基础(三)
    一. 视图,序列,索引视图    1. 什么是视图          视图(VIEW)也被称作虚表,是一组数据的逻辑...
    99+
    2024-04-02
  • Oracle并行基础二
    Oracle并行基础(连载二)作者:沃趣科技高级数据库技术专家 魏兴华消费者生产者模型的限制根据上面的介绍,你已经知道了,一个并行操作内一般会具有两组PX slave进程,一组为生产者,一组为消费...
    99+
    2024-04-02
  • Oracle并行基础一
    Oracle并行基础(连载一)作者:沃趣科技高级数据库技术专家 魏兴华概述Oracle企业版有一项非常厉害的技术:并行查询,也就是说一个语句可以雇佣多个服务器进程(parallel slaves也...
    99+
    2024-04-02
  • Oracle数据基础(一)
    一. Oracle字符串操作字符串类型    1. CHAR和VARCHAR2类型          表示字符串数据...
    99+
    2024-04-02
  • oracle 12c ocp - 1
    To implement Automatic Memory Management (AMM), you set the following parameters:When you try to start ...
    99+
    2024-04-02
  • ORACLE 12C安装
    上班比较忙慢慢些,慢慢更新win2012R2+oracle12cr2静默安装需要关注里面的配置,比11G多一些选项似乎模板注释有问题,搞了半天静默配置侦听服务 ...
    99+
    2024-04-02
  • Oracle 12c Refreshable Clone
    这个例子将介绍通过克隆一个远程PDB(jypdb)来创建一个目标PDB(ycpdb)。这种克隆是对源PDB的一种可以刷新的副本,它意味着对源PDB所执行的任何改变都可以通过刷新来对目标PDB进行更新。这...
    99+
    2024-04-02
  • oracle 12c 监听
    ########################################## ...
    99+
    2024-04-02
  • oracle 12c ocp - 3
    Examine the following query output:You issue the following command to import tables into the hr schema:$ > impdp hr/h...
    99+
    2023-01-31
    oracle ocp
  • Oracle 12c Study之--Installer Oracle
    Oracle 12c Study之--Installer Oracle系统环境:     操作系统: Oracle Linux 5.6_64    &nbs...
    99+
    2024-04-02
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作