Oracle 区块链表创建过程详解


当前第2页 返回上一页

无论当前的保留期限是多少,如果将 NO DROP 修改为永久保留的话都会返回 ORA-00600 错误:

alter table bct_t1 no drop;

Error starting at line : 1 in command -
alter table bct_t1 no drop
Error report -
ORA-00600: internal error code, arguments: [atbbctable_1], [0], [], [], [], [], [], [], [], [], [], []

这可能是一个问题,因为大多数人可能想从保留期限为 0 天开始尝试,然后再增加保留期限。从保留期限为 1 天开始可能会导致一定的风险,因为想要删除测试表的唯一办法就是删除整个模式。

如果没有指定 LOCKED 选项,我们可以使用 ALTER TABLE 命令修改 NO DELETE 子句,当然只能增加保留期限。我们的测试表目前的数据保留期限为 16 天,下面我们将它修改为 32 天:

-- 增加到 32 天
alter table bct_t1 no delete until 32 days after insert;

Table BCT_T1 altered.


-- 减少到 16 天时返回错误
alter table bct_t1 no delete until 16 days after insert;

Error report -
ORA-05732: retention value cannot be lowered

当前版本中,如果尝试将数据保留期限修改为 NO DELETE(增加保留期限)将会导致 ORA-00600 错误,应该也是一个 bug。

alter table bct_t1 no delete;

Error report -
ORA-00600: internal error code, arguments: [atbbctable_1], [0], [], [], [], [], [], [], [], [], [], []

阻止 DML 和 DDL 语句

区块链表只支持数据的插入,所有导致数据修改或删除的 DML 和 DDL 语句都会返回错误。例如:

-- INSERT
insert into bct_t1 (id, fruit, quantity, created_date ) values (1, 'apple', 20, sysdate);

1 row inserted.

SQL> commit;

Commit complete.


-- UPDATE
update bct_t1 set quantity = 10 where id = 1;

Error report -
SQL Error: ORA-05715: operation not allowed on the blockchain table


-- DELETE
delete from bct_t1 where id = 1;

Error report -
SQL Error: ORA-05715: operation not allowed on the blockchain table

导致数据变化的 DDL 语句同样会返回错误,以下是一个 TRUNCATE 语句示例:

truncate table bct_t1;

Error report -
ORA-05715: operation not allowed on the blockchain table

我们可以扩展已有字段的长度,但是不能增加字段或者删除已有字段:

-- 修改字段长度
alter table bct_t1 modify (fruit varchar2(25));

Table BCT_T1 altered.


-- 增加字段
alter table bct_t1 add (additional_info varchar2(50));

Error report -
ORA-05715: operation not allowed on the blockchain table


-- 删除字段
alter table bct_t1 drop column quantity;

Error report -
ORA-05715: operation not allowed on the blockchain table

DBMS_BLOCKCHAIN_TABLE

系统程序包DBMS_BLOCKCHAIN_TABLE 可以用于维护区块链表。

其中,存储过程 DELETE_EXPIRED_ROWS 可以用于删除超过保留期限的数据行,这些数据无法使用正常的 DELETE 语句进行删除。

set serveroutput on
declare
  l_rows  number;
begin
  dbms_blockchain_table.delete_expired_rows(
    schema_name            => 'admin',
    table_name             => 'bct_t1',
    before_timestamp       => null,
    number_of_rows_deleted => l_rows);

  dbms_output.put_line('Rows Deleted=' || l_rows);
end;
/
Rows Deleted=0

PL/SQL procedure successfully completed.

另外,我们也可以增加一个日期限制,只有超过保留期限并且满足日期要求的数据行才会被删除。

set serveroutput on
declare
  l_rows  number;
begin
  dbms_blockchain_table.delete_expired_rows(
    schema_name            => 'testuser1',
    table_name             => 'it_t1',
    before_timestamp       => systimestamp - 60,
    number_of_rows_deleted => l_rows);

  dbms_output.put_line('Rows Deleted=' || l_rows);
end;
/
Rows Deleted=0

PL/SQL procedure successfully completed.

存储过程 VERIFY_ROWS 可以用于检查数据行拥有一致性哈希值,以及用户签名(如果使用了的话)。

set serveroutput on
declare
  l_rows      number;
  l_verified  number;
begin
  select count(*)
  into   l_rows
  from   admin.bct_t1;

  dbms_blockchain_table.verify_rows(
    schema_name             => 'admin',
    table_name              => 'bct_t1',
    number_of_rows_verified => l_verified);

  dbms_output.put_line('Rows=' || l_rows || '  Verified Rows=' || l_verified);
end;
/
Rows=1  Verified Rows=1

PL/SQL procedure successfully completed.

注意事项

在使用区块链表之前需要考虑以下问题:

  • 目前区块链表的功能还存在一些问题,某些功能并不完全像官方文档描述。
  • 区块链表比普通表的性能差一些,因为它需要执行更多的操作,例如计算哈希值。
  • 区块链表可以像其他表一样支持索引和分区。
  • 区块链表的导入导出还存在一些限制。
  • 区块链表的使用限制。
  • Oracle 推荐将每个区块链的当前哈希算法和相应的序列号存储在数据库之外,这样就可以将存储的值和表中的数据进行比较,提供额外的安全保护。
  • 在 data guard 配置中,Oracle 推荐使用最大保护模式或者最大高可用性模式同步区块链表。
  • DBMS_USER_CERTS 程序包中的 ADD_CERTIFICATE 存储过程可以用于增加用户证书,然后使用 DBMS_BLOCKCHAIN_TABLE 程序包中的 SIGN_ROW 存储过程将其应用到已有的数据行。

以上就是Oracle 一个集中式的区块链平台的详细内容,更多关于Oracle区块链平台的资料请关注其它相关文章!


打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...