oracle 错误:ORA-01730:指定的列名数量无效

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20919257/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 02:09:34  来源:igfitidea点击:

error: ORA-01730: invalid number of column names specified

sqloracle

提问by Ralph Blackk

Please help. I want to create an object view from the ffl tables but i keep getting the above error and can't find any solution.

请帮忙。我想从 ffl 表创建一个对象视图,但我不断收到上述错误并且找不到任何解决方案。

create table COPY_BOOK (
  NUM number(4,0), 
  DATE_Purchase date, 
  PRICE number(5,2), 
  LOAN_code varchar2(20) ,
  STATUS varchar2(15) check (STATUS in ('GOOD','DAMAGED')), 
  CONSTRAINT CP_PK primary key (num) ,
  constraint Loan_code_D  check (LOAN_CODE in ('NO', 'LOAN')) 
);

create or replace type copy_book_t as object(
  num   number(4, 0),
  loan_code   varchar2 (20)
);
/

create or replace view Vcopy_book of copy_book_t
with object oid (num)
as select cb.num, cb.date_purchase, cb.price, cb.loan_code, cb.status
from copy_book cb;
/

Is there a problem with the type definition?

类型定义有问题吗?

回答by Alex Poole

From the documentation:

文档

The procedure for defining an object view is:

  1. Define an object type, where each attribute of the type corresponds to an existing column in a relational table.

  2. Write a query that specifies how to extract the data from the relational table. Specify the columns in the same order as the attributes in the object type.

定义对象视图的过程是:

  1. 定义对象类型,其中该类型的每个属性对应于关系表中的现有列。

  2. 编写一个查询,指定如何从关系表中提取数据。按照与对象类型中的属性相同的顺序指定列。

You have created your object type with two attributes, but you're trying to populate it with five columns from your relational table.

您已经创建了具有两个属性的对象类型,但您正试图用关系表中的五列填充它。

You either need to change your object type to have the same five attributes (demo), or only select the numand loan_codecolumns in the view (demo).

您需要将对象类型更改为具有相同的五个属性 ( demo),或者仅选择视图中的numloan_code列 ( demo)。

Incidentally, the documentationalso recommends using with object identifierrather than with object oid.

顺便说一句,文档还建议使用with object identifier而不是with object oid.