将我的数据从关系表插入对象关系表

时间:2016-01-29 12:48:26

标签: oracle user-defined-types object-relational-model

我尝试使用命令<!doctype html> <html > <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-animate.js"></script> <script src="https://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-1.1.1.js"></script> <script src="example.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> </head> <body> <div ng-app="demo"> <div ng-controller="MainCtrl" class="container"> <button class="btn btn-default" ng-click="open()">Open Modal</button> </div> <script type="text/ng-template" id="myModalContent.html"> <div class="modal-header"> <h3 class="modal-title">Modal with a DatePicker</h3> </div> <div class="modal-body"> <div class="col-md-6"> <p class="input-group"> <input type="text" class="form-control" datepicker-popup="shortDate" ng-model="dt" is-open="opened" /> <span class="input-group-btn"> <button type="button" class="btn btn-default" ng-click="open($event)"><i class="glyphicon glyphicon-calendar"></i></button> </span> </p> </div> </div> <div class="modal-footer"> <button class="btn btn-primary" ng-click="cancel()">Cancel</button> </div> </script> </div> </body> </html>,但它没有用。如何将Relational表中的数据加载到Object-Relational表?

表类别的示例:

insert into select...

上述方法有效,但类似的方法对其他表格无效。

以下是所有表格:

关系表

insert into CATEGORIES_NEW select * from Categories;

对象关系表

    CREATE TABLE Customers (
    CUSTOMERID NUMBER NOT NULL,
    FIRSTNAME VARCHAR2 (20) NOT NULL,
    LASTNAME VARCHAR2 (20) NOT NULL,
    ADDRESS1 VARCHAR2 (40) NOT NULL,
    ADDRESS2 VARCHAR2 (40),
    CITY VARCHAR2 (20) NOT NULL,
    STATE VARCHAR2 (20) NOT NULL,
    ZIP VARCHAR2 (20) NOT NULL,
    COUNTRY VARCHAR2 (20) NOT NULL,
    REGION VARCHAR2 (20) NOT NULL,
    EMAIL VARCHAR2 (20) NOT NULL,
    PHONE VARCHAR2 (20) NOT NULL,
    CREDITCARDTYPE VARCHAR2 (20) NOT NULL,
    CREDITCARD VARCHAR2 (20) NOT NULL,
    CREDITCARDEXPIRATION VARCHAR (10) NOT NULL,
    USERNAME VARCHAR2 (20) NOT NULL,
    "PASSWORD" VARCHAR2 (20) NOT NULL,
    AGE NUMBER NOT NULL,
    INCOME NUMBER NOT NULL,
    GENDER VARCHAR2 (8) NOT NULL,
    PRIMARY KEY (CUSTOMERID));

    CREATE TABLE Orders (
    ORDERID NUMBER NOT NULL,
    ORDERDATE DATE NOT NULL,
    CUSTOMERID NUMBER NOT NULL REFERENCES Customers,
    NETAMOUNT NUMBER NOT NULL,
    TAX NUMBER NOT NULL,
    TOTALAMOUNT NUMBER NOT NULL,
    PRIMARY KEY (ORDERID));

    CREATE TABLE Categories (
    "CATEGORY" NUMBER NOT NULL,
    CATEGORYNAME VARCHAR (20) NOT NULL,
    PRIMARY KEY ("CATEGORY"));

CREATE TABLE Products (
    PROD_ID NUMBER NOT NULL ,
    "CATEGORY" NUMBER NOT NULL REFERENCES Categories,
    TITLE VARCHAR (40) NOT NULL,
    ACTOR VARCHAR (40) NOT NULL,
    PRICE VARCHAR (40) NOT NULL,
    PRIMARY KEY (PROD_ID));

    CREATE TABLE Orderlines (
    ORDERLINEID NUMBER NOT NULL,
    ORDERID NUMBER NOT NULL REFERENCES Orders,
    PROD_ID NUMBER NOT NULL REFERENCES Products,
    QUANTITY NUMBER NOT NULL,
    ORDERDATE VARCHAR2 (80) NOT NULL,
    PRIMARY KEY (ORDERLINEID,ORDERID));

1 个答案:

答案 0 :(得分:0)

对象表很棘手,可能不值得付出努力。但无论如何。

您正在使用对象,这意味着您需要实例化它们。当对象表定义在一个只具有标量属性的类型时,Oracle足够聪明地隐式实例化该对象。但是当Type很复杂时,属性本身就是类型ypu需要明确地实例化它们。

这是CUSTOMERS_NEW的插入

insert into CUSTOMERS_NEW 
select Customer_obj (
        c.CUSTOMERID , 
        c.FIRSTNAME||' '||c.LASTNAME ,
        ADDRESS_TYPE(
            c.ADDRESS1||' ' ||c.ADDRESS2 , 
            c.CITY  , 
            c.STATE , 
            c.ZIP  ,
            c.COUNTRY ,
            c.REGION
        ),
        CONTACT_INFO(
            c.EMAIL,
            c.PHONE 
        ),
        CREDITCARD_INFO (
            c.CREDITCARDTYPE  , 
            c.CREDITCARD  ,
            c.CREDITCARDEXPIRATION  
        ),
        PERSONAL_INFO  (    
            c.USERNAME,
            c.PASSWORD,
            c.AGE  ,
            c.INCOME  ,
            c.GENDER 
    )
)
from customers ;