[20190930]oracle raw型別轉化number指令碼.txt
[20190930]oracle raw型別轉化number指令碼.txt
--//寫一個簡單oracle raw轉化number指令碼,簡單說明:
--//輸入必須是c1,02 或者 c102,不支援c1,2格式。
--//raw2num.sh 指令碼放在最後.
--//測試:
$ cat otest.txt | xargs -n 1 -I {} bash -c "./raw2num.sh {};echo {} " | paste - -
0 80
1 c1,02
2 c1,03
25 c1,1a
123 c2,02,18
4100 c2,2a
-4100 3d,3c,66
41000000 c4,2a
-41000000 3b,3c,66
132004078 c5,02,21,01,29,4f
2.01 c1,03,02
.3 c0,1f
.00000125 be,02,1a
115.200003 c2,02,10,15,01,04
-.00000125 41,64,4c,66
-.3 3f,47,66
-1 3e,64,66
-5 3e,60,66
-20032 3c,63,65,45,66
-234.432 3d,63,43,3a,51,66
999999999999999999999999999999999999999900000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ff,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64
-999999999999999999999999999999999999990000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00,02,02,02,02,02,02,02,02,02,02,02,02,02,02,02,02,02,02,02,02
.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 80,02
-.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 7f,64,66
123456789012345678901234567890123456789000 d5,0d,23,39,4f,5b,0d,23,39,4f,5b,0d,23,39,4f,5b,0d,23,39,4f,5b
-123456789012345678901234567890123456780000 2a,59,43,2d,17,0b,59,43,2d,17,0b,59,43,2d,17,0b,59,43,2d,17,0b
.123456789012345678901234567890123456789 c0,0d,23,39,4f,5b,0d,23,39,4f,5b,0d,23,39,4f,5b,0d,23,39,4f,5b
-.12345678901234567890123456789012345678 3f,59,43,2d,17,0b,59,43,2d,17,0b,59,43,2d,17,0b,59,43,2d,17,0b
$ cat otest.txt
80
c1,02
c1,03
c1,1a
c2,02,18
c2,2a
3d,3c,66
c4,2a
3b,3c,66
c5,02,21,01,29,4f
c1,03,02
c0,1f
be,02,1a
c2,02,10,15,01,04
41,64,4c,66
3f,47,66
3e,64,66
3e,60,66
3c,63,65,45,66
3d,63,43,3a,51,66
ff,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64
00,02,02,02,02,02,02,02,02,02,02,02,02,02,02,02,02,02,02,02,02
80,02
7f,64,66
d5,0d,23,39,4f,5b,0d,23,39,4f,5b,0d,23,39,4f,5b,0d,23,39,4f,5b
2a,59,43,2d,17,0b,59,43,2d,17,0b,59,43,2d,17,0b,59,43,2d,17,0b
c0,0d,23,39,4f,5b,0d,23,39,4f,5b,0d,23,39,4f,5b,0d,23,39,4f,5b
3f,59,43,2d,17,0b,59,43,2d,17,0b,59,43,2d,17,0b,59,43,2d,17,0b
$ cat raw2num.sh
#! /bin/bash
#! oracle raw convert number
odebug=${ODEBUG:-0}
# process input parameter ,delete 0x and "," and all spaces. save to variable v_raw. and its length to variable v_len.
v_raw="$*"
v_raw=${v_raw//0x/}
v_raw=${v_raw//[, ]/}
v_len=${#v_raw}
v_tmp=$(( $v_len % 2 ))
if [ $v_tmp -ne 0 -o $v_len -gt 42 ]; then
echo "$v_raw is illegal! v_len=$v_len or length of v_len>42"
exit 2
fi
if [ $odebug -eq 1 ] ; then
echo v_ram="$v_raw"
fi
if [ "$v_raw" == "80" ]; then
result=0
echo "$result"
exit 0
elif [ "$v_raw" \> "80" ]; then
v_res="0."
v_exp=$(printf "%2d" $(( "0x"${v_raw:0:2} - 0xc0 )))
if [ $odebug -eq 1 ] ; then
echo v_ram="$v_raw" v_exp="$v_exp" v_len="$v_len"
fi
for ((i=2;i<$v_len;i+=2))
do
v_tmp=$(printf "%02d" $(( "0x"${v_raw:i:2} -0x1 )))
if [ $v_tmp -lt 0 -o $v_tmp -gt 99 ]; then
echo "$v_raw is illegal! offset $i = 0x${v_raw:i:2}"
exit 3
fi
if [ $v_tmp -eq 0 -a $i -eq $(( $v_len - 2 )) ];then
echo "$v_raw is illegal! offset $i = 0x${v_raw:i:2}"
exit 3
fi
v_res=${v_res}${v_tmp}
done
#result=$(echo "scale=132; 100^${v_exp} * ${v_res} " | bc -l | tr -d '\n\\\r' | sed -e "s/\.\([0-9]*[1-9]\)0\+$/.\1/" -e "s/\.0\+$//")
else
#negative
v_res="-0."
v_exp=$(printf "%2d" $(( 0xff - "0x"${v_raw:0:2} -0xc0 )))
## substr last 2 char, normal is 0x66 (102)
v_len=$(( $v_len - 2 ))
v_last=$(printf "%02d" $(( "0x"${v_raw:v_len:2} )))
if [ $odebug -eq 1 ] ; then
echo v_ram="$v_raw" v_exp="$v_exp" v_len-2="$v_len" v_last="$v_last"
fi
if [ "$v_last" != "102" -a $v_len -lt 40 ]; then
echo "$v_raw is illegal! offset $v_len = 0x${v_raw:v_len:2}"
exit 4
fi
for ((i=2;i<$v_len;i+=2))
do
v_tmp=$(printf "%02d" $(( 0x65 - "0x"${v_raw:i:2} )))
if [ $v_tmp -lt 0 -o $v_tmp -gt 99 ]; then
echo "$v_raw is illegal! offset $i = 0x${v_raw:i:2}"
exit 3
fi
if [ $v_tmp -eq 0 -a $i -eq $(( $v_len - 2 )) ];then
echo "$v_raw is illegal! offset $i = 0x${v_raw:i:2}"
exit 3
fi
v_res=${v_res}${v_tmp}
done
if [ $v_len -eq 42 -a "$v_last" != '102' ]; then
v_tmp=$(printf "%02d" $(( 101 - $v_last )))
if [ $v_tmp -le 0 -o $v_tmp -gt 99 ]; then
echo "$v_raw is illegal! offset $v_len = 0x${v_raw:v_len:2}"
exit 3
fi
v_res=${v_res}${v_last}
fi
#result=$(echo "scale=132; 100^${v_exp} * ${v_res} " | bc -l | tr -d '\n\\\r' | sed -e "s/\.\([0-9]*[1-9]\)0\+$/.\1/" -e "s/\.0\+$//")
fi
if [ $odebug -eq 1 ] ; then
echo v_ram="$v_raw" v_exp="$v_exp" v_len="$v_len" v_res="$v_res"
fi
result=$(echo "scale=132; 100^${v_exp} * ${v_res} " | bc -l | tr -d '\n\\\r' | sed -e "s/\.\([0-9]*[1-9]\)0\+$/.\1/" -e "s/\.0\+$//")
echo "$result"
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2658888/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20190930]oracle number型別儲存轉化指令碼.txtOracle型別指令碼
- [20191013]oracle number型別儲存轉化指令碼.txtOracle型別指令碼
- [20191003]oracle number型別儲存轉化指令碼.txtOracle型別指令碼
- [20150503]關於oracle的number型別.txtOracle型別
- [20160828]number型別.txt型別
- ORACLE NUMBER資料型別Oracle資料型別
- Oracle的raw資料型別Oracle資料型別
- 【NUMBER】Oracle的NUMBER資料型別特點Oracle資料型別
- [20171203]關於raw型別.txt型別
- Oracle的number資料型別Oracle資料型別
- Oracle中number型別詳解Oracle型別
- ORACLE NUMBER型別內部實現Oracle型別
- Oracle基本資料型別儲存格式淺析——RAW型別Oracle資料型別
- Oracle timestamp型別轉換date格式指令碼(精確到秒)Oracle型別指令碼
- Oracle 中LONG RAW BLOB CLOB型別介紹Oracle型別
- Oracle基本資料型別儲存格式淺析(五)——RAW型別Oracle資料型別
- 一個簡單函式—Number型別轉換Date型別函式型別
- EF:oracle的number型別對映為C#的boolean型別Oracle型別C#Boolean
- jsp頁面number型別自動轉為String型別JS型別
- [20191001]關於oracle number型別的一些疑惑.txtOracle型別
- JS中其他資料型別轉為number資料型別的方法JS資料型別
- oracle集合型別使用的實驗.TXTOracle型別
- 10_深入解析Oracle number資料型別及os層number解析工具分享Oracle資料型別
- Oracle Long型別轉換為Clob型別Oracle型別
- 淺析number型別的值型別
- 征服number型別的input框型別
- 測試NUMBER型別的效能型別
- number(p,s)型別詳解型別
- javascript型別系統——Number數字型別JavaScript型別
- 欄位型別檢測指令碼型別指令碼
- Long raw和Long型別總結型別
- 【轉】ORACLE資料型別Oracle資料型別
- ORACLE 自定義型別[轉]Oracle型別
- [轉]oracle資料型別Oracle資料型別
- 【NUMBER】有關Oracle NUMBER型別定義中precision和scale的測試和總結Oracle型別
- (轉)ORACLE 巡檢指令碼Oracle指令碼
- oracle資料型別date和timestamp的轉化Oracle資料型別
- oracle中dump函式及oracle NUMBER型別內部儲存機制Oracle函式型別