Object-oriented database design and application of 03 - to create data tables and insert records

First, the purpose of the experiment

  1. This experiment focus is required to be able to create object oriented data table, including the types of data created and inserted proficient recording command;
  2. Master the entire object-oriented database design and creation process in ORACLE, and grasp the key details of the experiment, the two methods to master the object-oriented database records inserted in ORACLE;

All in all, that is required to master data types and data tables to create a basic table objects using the method handle, skilled use of the command record is inserted, and can create a preliminary understanding of the basic processes ORACLE function.

 

 

 

Second, the experimental content

Import experimental background:

The company has completed creating the database, the next requires that the database administrator control logic in the design phase of the modal split of documents and reference data dictionary to create the tables, complete the following requirements according to schedule requirements:

Creating ① mode. Before you create a data table, to take into account in order to better manage the entire database, you must first create the model.

② create data tables. After you create the model, the corresponding database design and data dictionary document OOM data types and create data tables in this mode. Membership information table, product category table, table of merchandise information, employee information table, table payment, order information table, create an order details table stand, respectively.

③ built for the above data tables, each of the two or more records to be added.

 

For the needs of the structural model detailed design, in a test, the User abstracted as a super-type object, and subordinate subclass object inherits attributes are: members, merchants and administrators. In this study, the integrated design of repetitive and demand factors such as the complexity of the algorithm in the applications, OR mode will now be adjusted as follows:

 

 

 

 

Third, experimental platform

    Software: WORD, ORACLE

 

 

 

Fourth, the experimental procedures

Creating ① mode.

Create users, and then use the CREATE SCHEMA AUTHORIZATION command, authorize directly to the user.

 

Figure 4-1 Creating users and authorized

 

 

 

② create data tables.

Use CREATE TYPE command type of creation, and create tables using the CREATE TABLE command.

create or replace type RD_Member as object(

                 Member_ID varchar(11),

                 Member_Password varchar(50),

                 Member_name varchar(11),

                 Birth date,

                 Address varchar(20),

                 Mobile varchar(11),

                 WeChat varchar(11),

                 Reputation varchar(15),

                 Hobby varchar(50),

                 Sex varchar(20),

                 Jobe varchar(30));

create or replace type RD_Employee as object(

                 Employee_ID varchar(11),

                 Employee_Password varchar(50),

                 Employee_name varchar(11),

                 Birth date,

                 Address varchar(20),

                 Mobile varchar(11),

                 WeChat varchar(11),

                 Reputation varchar(15),

                 department varchar(50),

                 Sex varchar(20),

                 company varchar(30)

);

create or replace type RD_Payment_type as object(

                   Payment_type_ID varchar(11),

                   Payment_type varchar(11)

);

create or replace type  RD_Commodity_type as object(

                   Commodity_type_ID varchar(11),

                   status varchar(10),

                   Commodity_type varchar(10)

);

create or replace type RD_Good as object(

                 Good_ID varchar(11),

                 Discount varchar(5),

                 Goods varchar(100),

                 Unit_Price number,

    Purchase_Date varchar(10),

                 Good_type ref RD_Commodity_type

);

create or replace type RD_Order_details as object(

    Order_details_id varchar(11),

                 Order_details varchar(11),

                 Good_info ref RD_Good,

                 Payment_type_info ref RD_Payment_type,

                 Employee_info ref RD_Employee,

    Member_info ref RD_Member);

create or replace type RD_Order as object(

                 Order_ID varchar(11),

                 Goods_Number number,

                 Total_price number,

                 Setup_time varchar(20),

    Order_details ref RD_Order_details);

CREATE OR REPLACE FUNCTION cur_datetime

RETURN VARCHAR

IS

BEGIN

 RETURN TO_CHAR(sysdate,

   'YYYY"年"MM"月"DD"日"HH24"时"MI"分"SS"秒"');

END;

create or replace function Calculated_price(para1 in number, para2 in number)

return number

as

begin

  if para1 > para2 then

      return para1;

  else

      return para2;

  end if;

end Calculated_price;

create or replace FUNCTION login

RETURN VARCHAR2

IS

BEGIN

 RETURN TO_CHAR('用户已登录!!');

END;

 

 

create table RD_Commodity_types OF RD_Commodity_type;

create table RD_Goods of RD_Good;

create table RD_Payment_types of RD_Payment_type;

create table RD_Employees of RD_Employee;

create table RD_Members of RD_Member;

create table RD_Order_detailss of RD_Order_details;

create table RD_Orders of RD_Order;

 

 

 

③    对于上述建好的数据表,每张表需使用INSERT INTO命令添加两条以上的记录。

Insert into C##RD.RD_MEMBERS (MEMBER_ID,MEMBER_PASSWORD,MEMBER_NAME,BIRTH,ADDRESS,MOBILE,WECHAT,REPUTATION,HOBBY,SEX,JOBE) values ('0001','123456','昊哥',to_date('18-11月-19','DD-MON-RR'),'广西南宁','1008611','10010','100','喜欢吃臭豆腐','','导师');

Insert into C##RD.RD_MEMBERS (MEMBER_ID,MEMBER_PASSWORD,MEMBER_NAME,BIRTH,ADDRESS,MOBILE,WECHAT,REPUTATION,HOBBY,SEX,JOBE) values ('0002','123456','小弟',to_date('18-11月-19','DD-MON-RR'),'广西藤县','10010','1008611','100','喜欢吃臭豆腐','','学生');

Insert into C##RD.RD_EMPLOYEES (EMPLOYEE_ID,EMPLOYEE_PASSWORD,EMPLOYEE_NAME,BIRTH,ADDRESS,MOBILE,WECHAT,REPUTATION,DEPARTMENT,SEX,COMPANY) values ('0001','123456','张三',to_date('03-3月 -19','DD-MON-RR'),'北京八达岭','1109635','53425223','98','销售部门','','北京岭科技有限公司');

Insert into C##RD.RD_EMPLOYEES (EMPLOYEE_ID,EMPLOYEE_PASSWORD,EMPLOYEE_NAME,BIRTH,ADDRESS,MOBILE,WECHAT,REPUTATION,DEPARTMENT,SEX,COMPANY) values ('0002','123456','李四',to_date('03-3月 -19','DD-MON-RR'),'杭州西湖边','1109635','53425223','98','作坊','','西湖臭豆腐西施作坊');

Insert into RD_PAYMENT_TYPES (PAYMENT_TYPE_ID,PAYMENT_TYPE) values ('0001','支付宝');

Insert into RD_PAYMENT_TYPES (PAYMENT_TYPE_ID,PAYMENT_TYPE) values ('0002','微信');

 

Insert into RD_COMMODITY_TYPES (COMMODITY_TYPE_ID,STATUS,COMMODITY_TYPE) values ('0001','1','推荐');

Insert into RD_COMMODITY_TYPES (COMMODITY_TYPE_ID,STATUS,COMMODITY_TYPE) values ('0002','0','推荐');

 

Insert into C##RD.RD_GOODS (GOOD_ID,DISCOUNT,GOODS,UNIT_PRICE,PURCHASE_DATE,GOOD_TYPE) values ('0001','0.8','豆浆',23.5,'2017-32-23', (select ref(a) from RD_COMMODITY_TYPES a where COMMODITY_TYPE_ID='0001'));

Insert into C##RD.RD_GOODS (GOOD_ID,DISCOUNT,GOODS,UNIT_PRICE,PURCHASE_DATE,GOOD_TYPE) values ('0002','0.8','豆浆',23.5,'2017-32-23', (select ref(a) from RD_COMMODITY_TYPES a where COMMODITY_TYPE_ID='0001'));

INSERT INTO RD_GOODS  VALUES (RD_GOOD('0003', '0.8', '豆浆', '23.5', '2017-32-23', (select ref(a) from RD_COMMODITY_TYPES a where COMMODITY_TYPE_ID='0001')));

 

Insert into C##RD.RD_ORDER_DETAILSS (ORDER_DETAILS_ID,ORDER_DETAILS,GOOD_INFO,PAYMENT_TYPE_INFO,EMPLOYEE_INFO,MEMBER_INFO) values ('0001','es',(select ref(a) from RD_Goods a where GOOD_ID='0001'),(select ref(a) from RD_PAYMENT_TYPES a where PAYMENT_TYPE_ID='0001'),(select ref(a) from RD_EMPLOYEES a where EMPLOYEE_ID='0001'),(select ref(a) from RD_MEMBERS a where MEMBER_ID='0001'));

Insert into C##RD.RD_ORDER_DETAILSS (ORDER_DETAILS_ID,ORDER_DETAILS,GOOD_INFO,PAYMENT_TYPE_INFO,EMPLOYEE_INFO,MEMBER_INFO) values ('0002','es',(select ref(a) from RD_Goods a where GOOD_ID='0001'),(select ref(a) from RD_PAYMENT_TYPES a where PAYMENT_TYPE_ID='0001'),(select ref(a) from RD_EMPLOYEES a where EMPLOYEE_ID='0001'),(select ref(a) from RD_MEMBERS a where MEMBER_ID='0001'));

 

Insert into C##RD.RD_ORDERS (ORDER_ID,GOODS_NUMBER,TOTAL_PRICE,SETUP_TIME,ORDER_DETAILS)  VALUES ('0001',4,23,'2017-23-07',(select ref(a) from RD_Order_detailss a where ORDER_DETAILS_ID='0001'));

INSERT INTO RD_ORDERS  VALUES (RD_ORDER('0002',4,23,'2017-23-07',(select ref(a) from RD_Order_detailss a where ORDER_DETAILS_ID='0001')));

 


  

 

五、运行结果

①    模式的创建。

 

图5-1 用户模式创建成功

 

 

②    数据表的创建。

 

图5-2 数据表创建成功

 

 

图5-3 获取时间函数执行成功

 

 

③    添加记录。

 

图5-4 插入数据记录成功

 

 

 

六、实验总结

        通过实验,相关的总结和经验收获,可分点总结如下:

  1. 通过本实验,已初步掌握了面向对象数据表的创建方法,并且对数据类型的创建也有了一定的自我理解;
  2. 本实验过程中遇到的问题比前两次都要多,例如:在对象数据库插入数据时提示,ORA-00984列在此处不允许的错误,而我的解决办法首先就是检查字段的数据类型是否匹配,之所以会出现这种问题的原因就是,在插入字符或字符串型字段时,如果插入的数据是纯数字,则不会有错误;但是如果出现字符,就会报ORA-00984列在此处不允许异常;
  3. 对于字符型字段,在插入数据时最好在字段值两端加上单引号,就可以很好的避免ORA-00984错误;
  4. 在实验的记录插入过程中,发现对于对象数据库的记录插入可以有多种方法,而对于引用类型的字段,在赋值时需得使用类似于“(select ref(a) from RD_Order_detailss a where ORDER_DETAILS_ID='0001')”的句型,将其认为是该字段的内容;等。

Guess you like

Origin www.cnblogs.com/Raodi/p/12155542.html