我正在尝试使用sql loader将数据加载到我的oracle表中

时间:2018-05-23 19:36:16

标签: sql oracle sqldatatypes sql-loader

这是我的表...它有Number作为列名

CREATE TABLE pwc_it_service (
  "SEQ"                  NUMBER,
  "NUMBER"               VARCHAR2(10),
  "CI_NAME"              VARCHAR2(200),
  "CI_CLASS"             VARCHAR2(200),
  "OWNED_BY_PRIMARY"     VARCHAR2(200),
  "OWNED_BY_SECONDARY"   VARCHAR2(200),
  "MANAGING_TERRITORY"   VARCHAR2(200),
  "LOS"                  VARCHAR2(100),
  "BUSINESS_UNIT"        VARCHAR2(100),
  "IMPORTED"             DATE,
  "LAST_UPDATED"         DATE
)

当我运行我的ctl文件时,我收到以下错误:

Record 1: Rejected - Error on table PWC_IT_SERVICE, column NUMBER.
ORA-01747: invalid user.table.column, table.column, or column specification

如何在不更改列名的情况下插入值

1 个答案:

答案 0 :(得分:1)

命名列"NUMBER"真是个坏主意(是的,双引号和大写包含在内)。你可以这样做的事实并不意味着你应该这样做。现在你必须处理它并一直使用相同的语法 - 双引号和大写。看看:

SQL> create table test ("NUMBER" varchar2(10));

Table created.

SQL> insert into test (number) values ('A');
insert into test (number) values ('A')
                  *
ERROR at line 1:
ORA-00928: missing SELECT keyword


SQL> insert into test ("number") values ('A');
insert into test ("number") values ('A')
                  *
ERROR at line 1:
ORA-00904: "number": invalid identifier


SQL> insert into test ("NUMBER") values ('A');

1 row created.

SQL>

在控制文件中执行相同操作。

load data 
infile *
replace
into table test
( 
"NUMBER" terminated by whitespace
)

begindata
Little
Foot

它如何运作?

SQL> desc test
 Name                          Null?    Type
 ----------------------------- -------- --------------------
 NUMBER                                 VARCHAR2(10)

SQL> $sqlldr scott/tiger@xe control=test02.ctl log=test02.log

SQL*Loader: Release 11.2.0.2.0 - Production on Sri Svi 23 22:23:07 2018

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

Commit point reached - logical record count 1
Commit point reached - logical record count 2

SQL> select * From test;

NUMBER
----------
Little
Foot

SQL>

工作正常。

但是,我建议你重命名这个unforunate列。现在和永远摆脱双引号。