Object-Oriented Programming of PL/SQL

Source: Internet
Author: User
Everything is an object. Everything in the world is an object. We can use PLSQL to implement object-oriented functions, so that programs can have better performance and readability without CREATEORREPLACETYPEliao_opp_testASOBJECT (-- Author: HAND -- Created: 20131516: 44: 20 -- Purpose: -- Attributesmail_ho

Everything is an object. Everything in the world is an object. We can use PL/SQL to implement object-oriented functions, enable the program to have better performance and readability without creating or replace type liao_opp_test as object (-- Author: HAND -- Created: 16:44:20 -- Purpose: -- Attributes mail_ho

Everything is an object. Everything in the world is an object. We can use PL/SQL to implement object-oriented functions, so that programs can have better performance and readability.

<无>
Create or replace type liao_opp_test as object (-- Author: HAND -- Created: Created 16:44:20 -- Purpose: -- Attributes mail_host VARCHAR2 (20), mail_port INTEGER, -- Member functions and procedures member procedure sent_mail, member function get_address (I NUMBER) RETURN VARCHAR2) CREATE OR REPLACE TYPE BODY liao_opp_test IS -- Member procedures and functions MEMBER PROCEDURE sent_mail IS BEGIN orders ('send email success to '| self. mail_host | ':' | self. mail_port); END sent_mail; member function get_address (I NUMBER) RETURN VARCHAR2 is begin return I | '. '| self. mail_host | ':' | self. mail_port; END get_address; END; DECLARE -- init Object's Attributes t liao_opp_test: = liao_opp_test ('192. 168.1.1 ', 8080); BEGIN t. sent_mail; END; create table cux_liao_opp_test of liao_opp_test; insert into cux_liao_opp_test (mail_host, mail_port) values ('2017. 168.1.1 ', 8081); insert into cux_liao_opp_test (mail_host, mail_port) values ('2017. 168.1.2 ', 8082); insert into cux_liao_opp_test (mail_host, mail_port) values ('2017. 168.1.3 ', 8083); insert into cux_liao_opp_test (mail_host, mail_port) values ('2017. 168.1.4 ', 8084); insert into cux_liao_opp_test (mail_host, mail_port) values ('2017. 168.1.5 ', 8085); insert into cux_liao_opp_test (mail_host, mail_port) values ('2017. 168.1.6 ', 8086); SELECT lot. mail_host, lot. mail_port, lot. get_address (1) FROM cux_liao_opp_test lot -- the previous section does not support subclass derivation. The following section describes the create or replace type cux_person as object (p_name VARCHAR2 (50 ), p_sex VARCHAR2 (2), p_age INT, member function get_person RETURN VARCHAR2) not final; create or replace type body cux_person is member function get_person RETURN VARCHAR2 is begin return self. p_name | ',' | self. p_sex | ',' | self. p_age; END get_person; END; create or replace type cux_student UNDER cux_person (stuid NUMBER, member function get_student RETURN VARCHAR2 ); create or replace type body cux_student IS -- Member procedures and functions member function get_student RETURN VARCHAR2 is begin return self. stuid | '. '| self. get_person; END get_student; END; drop TYPE cux_student; drop TYPE cux_person; drop table cux_stuInfo; create table cux_stuInfo of cux_student; insert into cux_stuInfo (p_Name, p_Sex, p_Age, Stuid) values ('dumb ',' B ',); insert into cux_stuInfo (p_Name, p_Sex, p_Age, Stuid) values ('silly', 'G ); insert into cux_stuInfo (p_Name, p_Sex, p_Age, Stuid) values ('dump', 'G', 12,3); select cs. p_name, cs. p_sex, cs. p_age, cs. get_person (), cs. get_student () from cux_stuInfo cs; -- ref (table alias) function is used to return the OID of the object, that is, the object identifier. The object table also has rowidselect ref (cs) from cux_stuInfo cs; -- create a Student Score table. Note that the foreign key drop table cux_stuScore; create table cux_stuScore (stu ref cux_student, -- the value of the stu column must appear in the stuInfo table, -- And the OID of the object stored in the stu column is not the object itself. Operations on this column are based on the OID score int -- Score); insert into cux_stuScore (Stu, score) select ref (s), round (dbms_random.value (20, 40) + 70 from cux_stuInfo s; select * from cux_stuScore; -- The deref (column name) function can restore OID to an object, the primary key column shows a problem with select deref (s. stu) from cux_stuscore s;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.