PL / SQL与对象类型PRIMARY KEY

时间:2016-10-01 14:45:19

标签: sql oracle

我有如下创建对象关系类型。

<div class="main">
  <div class="left">
    <img src="http://placehold.it/200x200" />
  </div>
  <div class="right">A TEXT</div>
</div>

现在我想为“Sedan”表设置主要内容如下。

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteRule ^index\.php$ - [L,NC]

# add trailing slash to directories
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R=301,NE]

# If the request is not for known file types
RewriteCond %{REQUEST_URI} !\.(?:jpe?g|gif|php|bmp|png|ico|tiff|css|js)$ [NC]
# This rule converts your flat link to a query
RewriteRule .* index.php?_page_location=$0 [L,QSA]

但错误就像是,

  

从命令行中的第4行开始出错 - CREATE TABLE sedan OF sedan_t   (PRIMARY KEY(familycar_t.make,familycar_t.model))错误报告 - SQL   错误:ORA-00904:“FAMILYCAR_T”。“MAKE”:标识符无效   00904. 00000 - “%s:无效标识符”   *原因:
  *操作:

它的解决方案是什么?

2 个答案:

答案 0 :(得分:1)

您无法在类型为REF的属性上创建索引(请参阅here)。 如果REF是作用域,则只能在REF属性或列上定义索引。

CREATE OR REPLACE TYPE sedan_t AS OBJECT (
    familycar familycar_t,
    cylinder_Size  number(10)
    );
/
CREATE TABLE sedan OF sedan_t (PRIMARY KEY (familycar.make, familycar.model));

Table SEDAN created.

答案 1 :(得分:1)

使用引用的另一种方法是使用继承:

CREATE OR REPLACE TYPE familycar_t AS OBJECT (
  make VARCHAR (10),
  model VARCHAR(10),
  year NUMBER (4),
  fuel_type VARCHAR (10)
) NOT FINAL;
/

CREATE OR REPLACE TYPE sedan_t UNDER familycar_t (
  cylinder_Size  number(10)
);
/

CREATE TABLE familycar OF familycar_t (PRIMARY KEY (make,model));

CREATE TABLE sedan OF sedan_t (PRIMARY KEY (make,model));

但是,在这种情况下,您并不需要sedan表:

INSERT INTO familycar
SELECT sedan_t( 'Ford', 'Model-T', 1908, 'Petrol', 4 ) FROM DUAL UNION ALL
SELECT familycar_t( 'Ford', 'Model-A', 1903, 'Petrol' ) FROM DUAL;

SELECT f.*,
       TREAT( VALUE(f) AS sedan_t ).cylinder_size AS cylinder_size
FROM   familycar f;

<强>输出

MAKE       MODEL            YEAR FUEL_TYPE  CYLINDER_SIZE
---------- ---------- ---------- ---------- -------------
Ford       Model-T          1908 Petrol                 4 
Ford       Model-A          1903 Petrol            (null)