'SET' must be a type - sql

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
);

Related

How to overcome a persistent oracle 'invalid identifier' error on a basic insert?

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') )

How to manipulate objects with inheritance in sql (oracle)?

Supposing that i have that hierarchy, how can i manipulate (add, edit) an agent or a client ?
CREATE TYPE TPRENOM AS varray(3) OF VARCHAR2(20);
CREATE TYPE tadr as object(
cp int not null,
state varchar2(20),
city varchar2(20),
street varchar2(20),
doorNum int
);
create type tperson as object(
fname varchar2(20),
lname tprenom,
adress tadr,
phoneNum varchar2(10),
email varchar2(50)
)not final;
create type tutilisateur under tperson(
username varchar2(20),
password varchar2(20)
);
create table agent(
id_ag int not null,
infos tutilisateur not null
, CONSTRAINT agent_pk PRIMARY KEY
(
ID_ag
)
enable
);
create table client(
id_cl int not null,
infos tperson not null,
num_chec varchar2(30) not null,
CONSTRAINT client_pk PRIMARY KEY
(
ID_cl
)
enable
);
I've tried these, but it didn't work :
insert into agent values(1, tutilisateur( tperson( 'name', tprenom('bilel',
'dani','lastname3'), tadr(3,'state', 'miliana', 'hammama', 20),
'2140547854', 'email#gmail.com'), 'username', 'password'));
insert into client values(0, tperson('name', tprenom('bilel', 'dani',
'lastname3'), tadr(3,'state2','miliana','hammama',20)),'123456789');
That's the error displaying when excecuting the sql above :
Erreur SQL : ORA-02315: incorrect number of arguments for default constructor
00000 - "incorrect number of arguments for default constructor"
*Cause: The number of arguments specified for the default constructor
doesn't match the number of attributes of the object type.
*Action: Specify the correct number of arguments for the default
constructor and retry the operation.
I'm i doing inheritance wrong ?
Thanks for your response
Okay i found the solution, i can't beleive how easy it was,that's how to insert into agent table :
insert into agent
values(1,tutilisateur('name',tprenom('bilel','dani','lastname3'),tadr(3,'ain
delfa','miliana','hammama',20),'2140547854','email#gmail.com','username','password'));
That's how to insert into client table :
insert into client
values(0,tperson('name',tprenom('bilel','dani','lastname3'),tadr(3,'ain
delfa','miliana','hammama',20),'11225','email#gmail.com'),'123456789');

PLSQL TYPE modifications

I have created the below type,
create or replace
TYPE MSSINT.TEST_TYPE
AS OBJECT
(service_phone_num varchar2(15),
name_last varchar2(50),
name_first varchar2(50));
Now I need to change the dataype of service_phone_num to NUMBER.
Can we achieve this using the below command or something like below?
ALTER TYPE MSSINT.TEST_TYPE MODIFY ATTRIBUTE (service_phone_num NUMBER) CASCADE;
Execute the following:
create or replace
TYPE MSSINT.TEST_TYPE
AS OBJECT
(service_phone_num number(15),
name_last varchar2(50),
name_first varchar2(50));
Should work, as you have create or replace.
Use the command
create or replace
TYPE MSSINT.TEST_TYPE
AS OBJECT
(service_phone_num number,
name_last varchar2(50),
name_first varchar2(50));
Replace modify your type.

Oracle 11g creating table

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);

error- declaration is incomplete or malformed

I have the error- the declaration of ... is incomplete or malformed coming from the last type- "Subscriber_T" but I don't see a problem with the syntax. These are the scripts:
CREATE OR REPLACE TYPE Surnames_T AS OBJECT (
Surname varchar (20)
);
/
CREATE OR REPLACE TYPE listSurnames_T
AS Varray(4) of Surnames_T;
/
CREATE OR REPLACE TYPE listTels as object(
Tel number (12)
);
/
CREATE OR REPLACE TYPE listTels_T as Varray(5) of listTels;
/
CREATE OR REPLACE TYPE ADDRESS_T AS OBJECT (
NUM number (6),
STREET varchar (20),
TOWN varchar (20)
);
/
CREATE or replace type TAddress
as table of Address_T;
/
create or replace type Subscriber_T as object(
num_s number(6),
sName varchar(30),
surname listSurnames_T,
Adds TAddress,
DateOfBirth date,
member function cal_Age return number,
phoneNo listTels_T
);
/
show error
I need a fix please!
You have to put member functions after all other fields; you can't sneak a field in at the end:
create or replace type Subscriber_T as object(
num_s number(6),
sName varchar(30),
surname listSurnames_T,
Adds TAddress,
DateOfBirth date,
phoneNo listTels_T,
member function cal_Age return number
);
/
TYPE SUBSCRIBER_T compiled
Obligatory SQL Fiddle.
This is shown in the syntax diagram in the documentation; you can have one or more attributes, and then one or more elements (including functions), but you can't mix them around. Notice which bits have loops, and where they loop back to.