我有一个sqlite数据库,有很多桌子。每个表都有很多行。在一个专栏中,我有类似以下内容:
[58458, 65856, 75658, 98456, 98578, ... N]
创建数据库时,我犯了一个错误(我不再有访问初始数据的权限),我需要在第二个数字后加一个点来使这些数字具有以下含义:
[58.458, 65.856, 75.658, 98.456, 98.578, ... N]
有什么办法可以做到吗?我更喜欢Java。还是已经有任何工具可以做到这一点?
最佳答案
使用此功能可以解析每列中的信息。
public static String convertColumn(String textF)
{
String textAux = "";
String newText = "[";
int i = 0;
textF = textF.substring(1, textF.length() - 1);
while(i < textF.length())
{
textAux = textF.substring(i, i + 5);
int nrAux = Integer.parseInt(textAux);
i+=7;
int a;
int b;
a = nrAux / 1000;
b = nrAux - a * 1000;
double newNr;
newNr = a + b * 0.001;
newText = newText + newNr + ", ";
}
newText = newText.substring(0, newText.length() - 2);
newText += "]";
return newText;
}
该函数将具有作为参数的字符串,例如[58458,65856,75658,98456,98578],您可以从中获取
SQL表,返回值为[58.458、65.856、75.658、98.456、98.578],这是更新列所需要的值。
对于SQL,基本思想是:
UPDATE table
SET column = convertColumn(column);