DBMS_BLOCKCHAIN_TABLE Package-Database Tables
By Michele leonti / June 24, 2023 / No Comments / An Overview of Oracle Indexes, Oracle Certifications, Setting PCTFREE Values
Oracle provides an internal PL/SQL package DBMS_BLOCKCHAIN_TABLE that can be used to perform the following:
•\ Delete rows in a blockchain table that are allowed to be removed viathe specified retention period.
•\ Retrieve the bytes required that are the input to the signaturealgorithm so that you can sign an inserted row.
•\ Retrieve the bytes that are the input to the cryptographic hash for aninserted row. This can be used to verify the row’s hash.
•\ Sign a row inserted into the table.
•\ Verify the hashes and signatures on rows in the table.
For full details on DBMS_BLOCKCHAIN_TABLE, refer to Oracle’s PL/SQL Packages and Types Reference guide. I’ll show a couple of examples here to give you an idea of how you can use this package to verify that the data has not been compromised in any way.
This next example calls the DBMS_BLOCKCHAIN_TABLE.VERIFY_ROWS procedure to do just that:
$ sqlplus sys/foo@PB1
SQL> set serverout ondeclareactual_rows number;verified_rows number;beginselect count(*)into actual_rowsfrom eoda.ledger;–dbms_blockchain_table.verify_rows(schema_name => ‘EODA’,table_name => ‘LEDGER’,number_of_rows_verified => verified_rows);dbms_output.put_line(‘Actual rows: ‘ || actual_rows || ‘ Verified rows: ‘|| verified_rows);end;/
Actual rows: 1 Verified rows: 1
This allows you to verify rows on all applicable chains for the integrity of the HASH column value.
You cannot use a DELETE command to remove rows from a blockchain table.
The only way to delete rows from a blockchain table is via the DBMS_BLOCKCHAIN_TABLE. DELETE_EXPIRED_ROWS procedure. For example:
SQL> set serverout on
SQL> declarenumber_rows number;begin
dbms_blockchain_table.delete_expired_rows(‘EODA’,’LEDGER’, null, number_rows);
dbms_output.put_line(‘Number of rows deleted: ‘ || number_rows);end;/
This allows you to remove rows that are eligible to be deleted as specified in the blockchain row retention clause.
Blockchain Table Summary
Many businesses store sensitive financial information in databases. This could be in the form of contracts, bank statements, accounting information, and so on.
Without blockchain technology, it’s possible a user with access to these tables could make illicit changes to the data. Oracle has introduced blockchain tables to prevent these unwanted changes from ever happening.
Blockchain tables are special tables that have restrictions on removing or modifying data. These are meant to be insert-only tables. As data is inserted, the new rows have cryptographic hash signatures generated and are stored as part of the row information.