我正在尝试使用SQL从csv文件创建外部表。 csv文件具有以下结构:
I001234
I012344
I000234
...
我为上载编写了以下代码:
create table Arranger_check(
matriid char(8))
organization external (
type oracle_loader default directory ext_tab_data access parameters
(
records delimited by newline
)
location('file.csv')) reject limit unlimited;
如果我尝试询问db,结果是错误的。我有八位数字,最后一位是空格32(ascii)。结果是使用IN或NOT IN的查询不起作用。
matriid
--------
I001234
I012344
I000234
...
我尝试在char(7)中更改矩阵char(8),但创建表时会上传0行。
答案 0 :(得分:2)
如果您将列定义为public class MainActivity extends Activity {
public EditText url_text;
public TextView textView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//url_text = (EditText) findViewById(R.id.address);
//textView = (TextView) findViewById(R.id.tv);
final String url = "http://www.google.com/";
new JSONAsyncTask().execute(url);
}
public class JSONAsyncTask extends AsyncTask<String, Void, Boolean> {
public String resultString = "";
@Override
protected Boolean doInBackground(String... params) {
String url = params[0];
try {
HttpGet httpGet = new HttpGet(url);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httpGet);
int status = response.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);
resultString = data;
return true;
}
} catch (Exception e) {
System.out.println("Some error occured.");
}
return false;
}
@Override
protected void onPostExecute(Boolean result){
Log.d("TAG", resultString);
}
}
}
,则无论文件中的值是否包含空格,都将始终用空格填充:如果我使文件具有混合性:
char(8)
使用create table Arranger_check(
matriid char2(8))
...
select matriid, length(matriid), dump(matriid) as dumped
from Arranger_check;
MATRIID LENGTH(MATRIID) DUMPED
-------- --------------- ----------------------------------------
I001234 8 Typ=96 Len=8: 73,48,48,49,50,51,52,32
I012344 8 Typ=96 Len=8: 73,48,49,50,51,52,52,32
I000234 8 Typ=96 Len=8: 73,48,48,48,50,51,52,32
时,列值将仅在文件尾部有空格的情况下才有空格,因此,使用同一文件混合时,表中的长度会有所不同:
varchar2
如果即使文件值包含列值,也希望它们不包含尾部空格,则需要将它们修剪掉(如果存在):
create table Arranger_check(
matriid varchar2(8))
...
select matriid, length(matriid), dump(matriid) as dumped
from Arranger_check;
MATRIID LENGTH(MATRIID) DUMPED
-------- --------------- ----------------------------------------
I001234 8 Typ=1 Len=8: 73,48,48,49,50,51,52,32
I012344 7 Typ=1 Len=7: 73,48,49,50,51,52,52
I000234 7 Typ=1 Len=7: 73,48,48,48,50,51,52
然后使用包含空格和不带空格的值混合的同一文件:
create table Arranger_check(
matriid varchar2(8))
organization external (
type oracle_loader default directory ext_tab_data access parameters
(
records delimited by newline
fields
(
matriid char(8) rtrim
)
)
location('file.csv')) reject limit unlimited;
请注意,如果您坚持使用select matriid, length(matriid), dump(matriid) as dumped
from Arranger_check;
MATRIID LENGTH(MATRIID) DUMPED
-------- --------------- ----------------------------------------
I001234 7 Typ=1 Len=7: 73,48,48,49,50,51,52
I012344 7 Typ=1 Len=7: 73,48,49,50,51,52,52
I000234 7 Typ=1 Len=7: 73,48,48,48,50,51,52
,rtrim
不会有任何实际效果,因为正是这种数据类型导致所有值都用空格重新填充到列的全部大小。您需要使用char(8)
。