本文共 2241 字,大约阅读时间需要 7 分钟。
关于DBA的换算问题,我们知道了
10bit的file number,每个对象最多有1022个文件(2个文件预留) 22bit的block number,每个文件最多有4M个BLOCK 及DBA中高10位是文件号,第22位是块号,一般我们使用dbms_utility进行转换,但是 有了算法就可以模拟一个换算的C语言小程序,利用C语言位域结构体 其实我们只要加权相加即可: #include #include #include #include #define dn data->d struct db_addr { unsigned d1:1; unsigned d2:1; unsigned d3:1; unsigned d4:1; unsigned d5:1; unsigned d6:1; unsigned d7:1; unsigned d8:1; unsigned d9:1; unsigned d10:1; unsigned d11:1; unsigned d12:1; unsigned d13:1; unsigned d14:1; unsigned d15:1; unsigned d16:1; unsigned d17:1; unsigned d18:1; unsigned d19:1; unsigned d20:1; unsigned d21:1; unsigned d22:1; unsigned d23:1; unsigned d24:1; unsigned d25:1; unsigned d26:1; unsigned d27:1; unsigned d28:1; unsigned d29:1; unsigned d30:1; unsigned d31:1; unsigned d32:1; }; void main () { long dba,block1,block2,block3,block4,block5,file1,file2; long blocksum,filesum; struct db_addr *data; printf("please input X dba!\n"); scanf("%x",&dba); data=&dba; block1=data->d1+data->d2*2+data->d3*pow(2,2)+data->d4*pow(2,3)+data->d5*pow(2,4); // printf("%d",data->d1); block2=data->d6*pow(2,5)+data->d7*pow(2,6)+data->d8*pow(2,7)+data->d9*pow(2,8)+data->d10*pow(2,9); block3=data->d11*pow(2,10)+data->d12*pow(2,11)+data->d13*pow(2,12)+data->d14*pow(2,13)+data->d15*pow(2,14); block4=data->d16*pow(2,15)+data->d17*pow(2,17)+data->d18*pow(2,17)+data->d19*pow(2,18)+data->d20*pow(2,19); block5=data->d21*pow(2,20)+data->d22*pow(2,21); blocksum=block1+block2+block3+block4+block5; file1=data->d23*pow(2,0)+data->d24*pow(2,1)+data->d25*pow(2,2)+data->d26*pow(2,3)+data->d27*pow(2,4); file2=data->d28*pow(2,5)+data->d29*pow(2,6)+data->d30*pow(2,7)+data->d31*pow(2,8)+data->d32*pow(2,9); filesum=file1+file2; printf("file id is:%ld\nblocks id is :%ld\n",filesum,blocksum); } 如果我们使用程序换算 2c000d3 如下: please input X dba! 2c000d3 file id is:11 blocks id is :211 实际和dbms_utility得到的是相同的。 SQL> select to_number('2c000d3','xxxxxxxxxxxxxx') from dual; TO_NUMBER('2C000D3','XXXXXXXXX ------------------------------ 46137555 SQL> select dbms_utility.data_block_address_file(46137555), 2 dbms_utility.data_block_address_block(46137555) from dual; DBMS_UTILITY.DATA_BLOCK_ADDRES DBMS_UTILITY.DATA_BLOCK_ADDRES ------------------------------ ------------------------------ 11 211 转载地址:http://eiybx.baihongyu.com/