gpt4 book ai didi

sql - 如何在不影响已经存在的值的情况下更改列的属性?

转载 作者:搜寻专家 更新时间:2023-10-30 21:55:07 24 4
gpt4 key购买 nike

简而言之 - 在 oracle 数据库中,我想创建一个列 varchar2(16),现在是 varchar2(8),而不影响值 presnet。我已经试过了,它做了一些奇怪的事情。

我尝试的查询是 - alter table SOME_TABLE modify (SOME_COL varchar2(16));但是表中已经存在的值(有些不是全部)得到当我运行上述查询时,'\0' 附加到它们。

那么,做我想做的事情的正确方法是什么?

最佳答案

非常怀疑表中的原始数据正在被更改。由于您的一些评论暗示您正在使用 SQLPlus 以外的工具和应用程序来查看和处理数据,我认为您需要查看它们是否以某种方式错误地处理了数据。

这是一个示例,我试图在其中重现您在直接 SQLPlus 中所做的操作。没有空字节附加到现有数据:

SQL> create table foo (bar varchar2(8));

Table created.

SQL> insert into foo
2 select lpad(to_char(level),level)
3 from dual
4 connect by level <=8;

8 rows created.

SQL> commit;

Commit complete.

SQL> select bar,dump(bar) from foo;

BAR
--------
DUMP(BAR)
--------------------------------------------------------------------------------
1
Typ=1 Len=1: 49

2
Typ=1 Len=2: 32,50

3
Typ=1 Len=3: 32,32,51

4
Typ=1 Len=4: 32,32,32,52

5
Typ=1 Len=5: 32,32,32,32,53

6
Typ=1 Len=6: 32,32,32,32,32,54

7
Typ=1 Len=7: 32,32,32,32,32,32,55

8
Typ=1 Len=8: 32,32,32,32,32,32,32,56


8 rows selected.

SQL> alter table foo modify (bar varchar2(16));

Table altered.

SQL> select bar,dump(bar) from foo;

BAR
----------------
DUMP(BAR)
--------------------------------------------------------------------------------
1
Typ=1 Len=1: 49

2
Typ=1 Len=2: 32,50

3
Typ=1 Len=3: 32,32,51

4
Typ=1 Len=4: 32,32,32,52

5
Typ=1 Len=5: 32,32,32,32,53

6
Typ=1 Len=6: 32,32,32,32,32,54

7
Typ=1 Len=7: 32,32,32,32,32,32,55

8
Typ=1 Len=8: 32,32,32,32,32,32,32,56

关于sql - 如何在不影响已经存在的值的情况下更改列的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/950134/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com