hi i'm using oracle 11g to create a table with Object-Relational Features but its not creating the table for some reason
here what i have
create type Name as object (
firstname varchar2(20),
surname varchar2(20))
final
create type Address as object (
street varchar2(20),
city varchar2(20),
postal_code varchar2(8))
not final
and for the table
create table people (
(pname Name,
paddress Address,
dateOfBirth date);
yet its not creating the table, i know its probably something simple and straight forward but i just cant seam to get it to create the table, if somebody could point me in the right direction to get it to create the table that would be great
also when i try create the table i get the following error
ORA-00904: "%s: invalid identifier"
*Cause:
*Action:
Vendor code 904Error at line:2 colimn:2
You can try this:
CREATE TYPE Name as object (firstname varchar2(20), surname varchar2(20)) FINAL;
CREATE TYPE Address as object (street varchar2(20), city varchar2(20), postal_code varchar2(8)) NOT FINAL;
CREATE TABLE people (pname Name, paddress Address, dateOfBirth date);
DEMO
try this
create type Name as object (
firstname varchar2(20),
surname varchar2(20))
final );
create type Address as object (
street varchar2(20),
city varchar2(20),
postal_code varchar2(8))
not final);
Related
I created the following types :
CREATE TYPE Adress AS Object (Street varchar2(50), PostalC number, Ville varchar2(50));
CREATE TYPE PhoneNumber;
A person can have a set of PhoneNumbers, when I try to create the Type Person :
CREATE TYPE Person AS Object (FirstName varchar2(50), LastName varchar2(50), Adr Adress, Mobile SET(PhoneNumber));
I get the following error :
Errors: TYPE PERSON Line/Col: 0/0 PL/SQL: Compilation unit analysis
terminated Line/Col: 1/90 PLS-00488: 'SET' must be a type
If you want an array of phone numbers for each person, define the phone number type as a nested table:
create or replace type address as object (
street varchar2(50), postalc number, ville varchar2(50)
);
/
create or replace type phonenumber as table of varchar2(20);
/
create or replace type person as object (
firstname varchar2(50), lastname varchar2(50),
adr address, mobile phonenumber
);
I am trying to create a basic table using subtypes and insert some data into this in Oracle Express 11g.
My table is successfully created but i am having issues with inserting data.
The result of my insert statement always throws back an error 'SQL Error: ORA-00904: "BRANCH_PHONE": invalid identifier'.
The column which shows up in the error message is always the column which is at the end of the insert statement, despite the column existing in the table. I have tried the following code:
create type addressType as object(
street varchar2(20),
city varchar2(20),
postCode varchar2(8))
not final
/
create type branchType as object(
branchID int,
branch_address addressType,
branch_phone int(11))
not final
/
create table Branch of branchType(
constraint branch_pk primary key(branchID));
/
insert into Branch values (
branchID('2364'),
addressType('12 Rooster','Atlantis','A13 4UG'),
branch_phone('01316521311'));
I would really appreciate any ideas.
I made some changes, including changing the branch_phone to varchar2. A Phone number, while is "numbers" is not a data type of number. it is a string of characters. Also you were passing branchID as a string, but you are declaring it as a number, so changed that also. BranchID and branch_phone are primitive data types, so no constructor needed.
create type addressType as object(
street varchar2(20),
city varchar2(20),
postCode varchar2(8))
not final
/
create type branchType as object(
branchID int,
branch_address addressType,
branch_phone varchar2(11))
not final
/
create table Branch of branchType(
constraint branch_pk primary key(branchID));
/
insert into Branch values (
branchtype(2364,
addressType('12 Rooster','Atlantis','A13 4UG'),
'01316521311') )
I am trying to insert an alphanumeric sequence in Oracle but it is not working.
create sequence LIB start with 1 increment by 1;
select 'LIBR'||to_char(seq_no.nextval,'FM0000099') from dual;
create table addLib(
USER_ID VARCHAR2(20) PRIMARY KEY,
NAME VARCHAR2(20),
PASSWORD VARCHAR2(20),
FATHER_NAME VARCHAR2(20),
DOB DATE,
QUALIFICATION VARCHAR2(20),
DOJ DATE,
STATE VARCHAR2(20),
ADDRESS VARCHAR2(20),
PINCODE NUMBER(6));
INSERT INTO addLibrarian
values(
LIB.nextval(LIBR),
'abc',
'1234',
'xyz',
to_date('19970503','YYYYMMDD'),
'b.tech',
to_date('19970308','YYYYMMDD'),
'tanakpur',
262309);
I expect it to insert all values into the table but an error shows not enough values.
There are multiple issues:
LIB.nextval(LIBR) is not a valid syntax.
table name is not valid.
value for address is missing in VALUES clause.
Try this:
create table addLib( -- changed table name
USER_ID VARCHAR2(20) PRIMARY KEY,
NAME VARCHAR2(20),
PASSWORD VARCHAR2(20),
FATHER_NAME VARCHAR2(20),
DOB DATE,
QUALIFICATION VARCHAR2(20),
DOJ DATE,
STATE VARCHAR2(20),
ADDRESS VARCHAR2(20),
PINCODE NUMBER(6));
INSERT INTO addLib -- changed table name
values(
'LIBR' || LAPD(LIB.nextval, 7, 0), -- use something like this
'abc',
'1234',
'xyz',
to_date('19970503','YYYYMMDD'),
'b.tech',
to_date('19970308','YYYYMMDD'),
'tanakpur',
'<address>', -- add this value
262309);
Cheers!!
You have 10 columns and insert 9 values: but error show not enough values. Add the last correct value to your insertion.
This type of error can be prevented by formatting your code or use a prettifier to do it for you automatically.
I am having a hard time getting an output from a table.
Here is the table creation
CREATE OR REPLACE TYPE FULL_MAILING_ADDRESS AS OBJECT
( STREET VARCHAR2(80),
CITY VARCHAR2(80),
STATE CHAR(2),
ZIP VARCHAR2(10));
CREATE TABLE CUSTOMER
(
FULL_ADDRESS FULL_MAILING_ADDRESS
);
INSERT INTO CUSTOMER VALUES (FULL_MAILING_ADDRESS('55 SOUTH','ARLINGTON','VA','2222'));
when I do select on the table I don't get the values instead I get
[ORACLE.FULL_MAILING_ADDRESS]
Here is an image:
This is how far I gone into coding:
CREATE TYPE appointment_list_type AS TABLE OF REF appointment_type;
/
CREATE OR REPLACE TYPE person_type AS OBJECT (
personID NUMBER,
Surname varchar2(10),
Forname varchar2(10),
dateOfBirth date,
AddressLine1 varchar2(30),
AddressLine2 varchar2(30),
Town varchar2(10),
contacTel1 varchar2(10),
contacTel2 varchar2(10)) NOT FINAL;
/
CREATE TYPE applicant_type UNDER person_type(
applicantID NUMBER,
maxPrice number(7,2),
desiredArea varchar2(10),
Attends appointment_list_type
);
/
CREATE TYPE salesperson_type UNDER person_type(
salespersonID NUMBER,
manager varchar2(10),
Makes appointment_list_type
);
/
This is creating the types of person seperating it into inheritance of Salesperson and Applicant.
CREATE TYPE appointment_type AS OBJECT(
appointmentID NUMBER,
Appdate date,
Apptime timestamp,
appointmentType varchar2(10),
levelOfInterest varchar2(10),
offerMade varchar2(10),
Made_by REF salesperson_type,
Attends_by REF applicant_type
);
/
This is appointment type, The references work for relating them together.
For creating the table:
CREATE TABLE person_table OF person_type (
personID PRIMARY KEY NOT NULL)
NESTED TABLE Attends STORE AS attend_meeting_table;
CREATE TABLE applicant_table OF applicant_type (
personID PRIMARY KEY NOT NULL)
NESTED TABLE Attends STORE AS attend_meeting_table;
CREATE TABLE salesperson_table OF salesperson_type (
personID PRIMARY KEY NOT NULL)
NESTED TABLE Makes STORE AS makes_meeting_table;
CREATE TABLE appointment_table OF appointment_type (
appointmentID PRIMARY KEY NOT NULL,
SCOPE FOR (Made_by) IS person_table,
SCOPE FOR (Attends_by) IS person_table);
Also here is some code of what I done, I now here is my question:
How does inheritance work with doing 1 to many directly into Appointment?
I am realy confused by this. Can anyone out me help me on how to do this?
phuh, I think I finally figured whats bothering you...
Currently, the appointments REFd in applicant_table and salesperson_table are totally independent. That means that applicants could come to meetings with sales persons that are actually in a meeting with someone else :)
Of course you want all appointments to be stored in appointment_table.
That is the perfect use case for object views. You do not need these object tables at all. Relational tables are much easier to manage.
Just create normal tables and then object views, just like this one for SALESPERSON:
create view ov_salesperson as
(select personID,
salespersonID,
SALESPERSON_TYPE
(personID
Surname,
Forname,
dateOfBirth,
AddressLine1,
AddressLine2,
Town,
contacTel1,
contacTel2,
salespersonID,
manager,
CAST
(MULTISET
(Select appointment_type
(appointmentID,
Appdate,
Apptime,
appointmentType,
levelOfInterest,
offerMade,
salesperson_id,
applicant_id
)
From appointment_table A
Where A.salesperson_id = S.salesperson_id
)
as appointment_list_type
)
) as salesperson_obj
from salesperson_table S
);