oracle 什么是数据库中的升级脚本?为什么要使用它们?[closed]

ipakzgxi  于 2022-12-11  发布在  Oracle
关注(0)|答案(1)|浏览(96)

已关闭。此问题需要details or clarity。当前不接受答案。
**想要改进此问题吗?**通过editing this post添加详细信息并阐明问题。

2天前关闭。
此帖子已在2天前编辑并提交审核,无法重新打开帖子:
原始关闭原因未解决
Improve this question
我正在处理这样一个场景:我需要为必须插入记录的表数据编写升级脚本。
我试着写它,但我不知道我在做什么。需要一个解释和一个示例升级脚本的例子。

jjjwad0x

jjjwad0x1#

The way I understood it, it might be something like this: there's a simple table:

SQL> create table test
  2    (id         number,
  3     name       varchar2(5)
  4    );

Table created.

The upgrade script might then - for example - add a primary key constraint:

SQL> alter table test add constraint pk_test primary key (id);

Table altered.

Then, during work with the table, you'd want to insert a row and hit an error because column is too small:

SQL> insert into test (id, name) values (1, 'Littlefoot');
insert into test (id, name) values (1, 'Littlefoot')
                                       *
ERROR at line 1:
ORA-12899: value too large for column "SCOTT"."TEST"."NAME" (actual: 10,
maximum: 5)

OK; enlarge it:

SQL> alter table test modify name varchar2(20);

Table altered.

SQL> insert into test (id, name) values (1, 'Littlefoot');

1 row created.

SQL>

Therefore, the upgrade script would contain two statements:

alter table test add constraint pk_test primary key (id);
alter table test modify name varchar2(20);

相关问题