Create Block Chain table
sqlplus / as sysdba <<EOF
set echo on;
set feedback on;
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;
col name form a20;
select inst_id,name,open_mode from gv\$pdbs where name='${tpdb}';
alter session set container=${tpdb};
show con_name;
CREATE BLOCKCHAIN TABLE items (ITEMID NUMBER, PRICE NUMBER(2,0), QTY NUMBER, DESCRIPTION VARCHAR2(60)) NO DROP UNTIL 25 DAYS IDLE NO DELETE LOCKED HASHING USING "SHA2_512" VERSION "v1";
Note: No allow to create blockchain table in CDB$ROOT
Commit;
exit;
EOF
Insert data into BlockChain table
rec_number=100
echo "Insert 100 rows"
sqlplus / as sysdba <<EOF
set echo on;
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;
alter session set container=${tpdb};
declare
begin
for i in 1..${rec_number}
loop
insert into items values (1, 35, 5, 'Apple');
commit;
end loop;
end;
/
select count(*) from items;
exit;
EOF
Query Hash value
select itemid, SUBSTR(ORABCTAB_HASH$,1,10) from items;
Compare the speed of common table and blockchain table:
Blockchain table | Common table |
---|---|
create blockchain table bc_tab2(id number,name varchar2(10), price number ( 6,2)) no drop until 31 days idle no delete locked hashing using "SHA2_512" version "v1"; SQL> set timing on SQL> begin for i in 1..10000 loop insert into bc_tab2 values(i,'anbob'||i,100); commit; end loop; end; / PL/SQL procedure successfully completed. Elapsed: 00:00:13.26 | create table tab2 (id number,name varchar2(10), price number ( 6,2)); SQL> begin for i in 1..10000 loop insert into tab2 values(i,'anbob'||i,100); commit; end loop; end; / PL/SQL procedure successfully completed. Elapsed: 00:00:00.86
|
Drop blockchain table:
BlockChain table | Command |
---|---|
Empty data | SQL> create blockchain table bc_table( 2 id number primary key, 3 name varchar2(20), 4 join_date date) 5 NO DROP UNTIL 365 DAYS IDLE 6 NO DELETE LOCKED 7 HASHING USING "SHA2_512" VERSION "v1"; Table created. SQL> drop table enmotech; Table dropped. |
With data | Drop PDB/CDB |