導讀:區塊鏈表是僅插入表(Only-Insert),將行組織成許多鏈。通過(guò)使用加密哈希將鏈中除第一行之外的每一行鏈接到鏈中的前一行。
SQL> select banner from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 20c Enterprise Edition Release 20.0.0.0.0 - Production
SQL> create blockchain table yhem
2 (
3 id number primary key,
4 name varchar2(20),
5 join_date date)
6 NO DROP UNTIL 30 DAYS IDLE
7 NO DELETE LOCKED
8 HASHING USING "SHA2_512" VERSION "v1";
Table created.
SQL> insert into yhem values(1,'EYGLE',to_date('2010-08-08','yyyy-mm-dd'));
1 row created.
SQL> insert into yhem values(2,'KAMUS',to_date('2010-08-08','yyyy-mm-dd'));
1 row created.
SQL> insert into yhem values(3,'ORA-600',to_date('2010-08-08','yyyy-mm-dd'));
1 row created.
SQL> insert into yhem values(4,'YANGTINGKUN',to_date('2010-08-08','yyyy-mm-dd'));
1 row created.
SQL> commit;
Commit complete.
SQL> delete yhem where id=1;
delete yhem where id=1
*
ERROR at line 1:
ORA-05715: operation not allowed on the blockchain table
SQL> update yhem set name='Guoqiang,Gai' where id=1;
update yhem set name='Guoqiang,Gai' where id=1
*
ERROR at line 1:
ORA-05715: operation not allowed on the blockchain table
SQL> drop table yhem;
drop table yhem
*
ERROR at line 1:
ORA-05723: drop blockchain table YHEM not allowed
Oracle 還提供了 PACKAGE 去校驗數據的一致性:
SQL> set serveroutput on
SQL> DECLARE
2 verified_rows NUMBER :=0;
3 BEGIN
4 DBMS_BLOCKCHAIN_TABLE.VERIFY_ROWS('EYGLE','YHEM',number_of_rows_verified=> verified_rows);
5 DBMS_OUTPUT.PUT_LINE('Number of rows verified =' || verified_rows);
6 END;
7 /
Number of rows verified =4
PL/SQL procedure successfully completed.
SQL> ALTER TABLE yhem NO DROP UNTIL 18 DAYS IDLE;
ALTER TABLE yhem NO DROP UNTIL 18 DAYS IDLE
*
ERROR at line 1:
ORA-05732: retention value cannot be lowered
SQL> ALTER TABLE yhem NO DROP UNTIL 31 DAYS IDLE;
Table altered.
SQL> ALTER TABLE yhem NO DELETE UNTIL 20 DAYS AFTER INSERT LOCKED;
ALTER TABLE ENMOTECH NO DELETE UNTIL 20 DAYS AFTER INSERT LOCKED
*
ERROR at line 1:
ORA-05731: blockchain table yhem cannot be altered
聯(lián)系客服