I need to insert a row to a table in oracle.
insert into policy_tab values ('4325','29-APR-98','29-APR-2007',32424,(select ref(a) from agent_tab a where a.nic='242424v'),claim_ntty(
claim_t('25-APR-2005','25-JUN-2005'),
claim_t('26-APR-2005','26-JUN-2005')
));
But when I executed it will show this error. "ORA-01722: invalid number ORA-06512: at "SYS.DBMS_SQL", line 1721"
create type policy_ty as object(
pid char(5),
sDate date,
eDate date,
premium number(10,2),
agent ref agent_ty,
claims claim_ntty
);
create table policy_tab of policy_ty(
pid primary key,
agent SCOPE IS agent_tab
)
nested table claims store as claim_nttab;
create type claim_t AS OBJECT(
eDate date,
amount number(10,2)
);
create type claim_ntty as table of claim_t;
create type agent_ty as object(
nic char(10),
name varchar(50),
address varchar(50),
contactNo contactNo_vaty
) NOT FINAL;
create table agent_tab of agent_ty(
nic primary key
);
So how to resolve it?
From the first look you need to use like below. However the information provided is not sufficient to resolve the issue. Related Objects defintion as well needed.
This has to be changed - '29-APR-98' to '29-APR-1998'
INSERT INTO policy_tab
VALUES (
'4325',
'29-APR-1998',
'29-APR-2007',
32424,
(SELECT REF (a)
FROM agent_tab a
WHERE a.nic = '242424v'),
claim_ntty (claim_t ('25-APR-2005', '25-JUN-2005'),
claim_t ('26-APR-2005', '26-JUN-2005')));
Edit:
Second observation. You created the below object:
create type claim_t AS OBJECT(
eDate date,
amount number(10,2)
);
And using it like:
claim_ntty (claim_t ('25-APR-2005', '25-JUN-2005'),
claim_t ('26-APR-2005', '26-JUN-2005')));
Second Argument should be number not date.
So your insert should be:
INSERT INTO policy_tab
VALUES (
'4325',
'29-APR-1998',
'29-APR-2007',
32424,
(SELECT REF (a)
FROM agent_tab a
WHERE a.nic = '242424v'),
claim_ntty (claim_t ('25-APR-2005', 123), claim_t ('26-APR-2005', 456)));
Related
I am getting an error ORA-00909 in when inserting an object of a superType in an object table. These are the definitions for the objects:
CREATE OR REPLACE TYPE address AS OBJECT (
street VARCHAR(20),
country VARCHAR(20),
province VARCHAR(20),
city VARCHAR2(20),
zipcode VARCHAR(10)
) FINAL;
CREATE OR REPLACE TYPE company AS OBJECT (
CIF VARCHAR2(9),
code VARCHAR2(10),
name VARCHAR2(20),
signUpDate DATE,
email VARCHAR2(20),
adminAddress address
) NOT FINAL;
CREATE OR REPLACE TYPE inCourseCompany UNDER company (
postalAddress address,
numEmployees NUMBER
) FINAL;
And the object table:
CREATE TABLE companies_objtab OF company (PRIMARY KEY CIF) OBJECT IDENTIFIER IS PRIMARY KEY;
I try to insert an object with the following statement:
INSERT INTO companies_objtab VALUES (
company('J12345678','000001','Test Company',TO_DATE(sysdate, 'dd/mm/yyyy hh24:mi:ss'),'',address('','','','',''))
);
and I get error Error
SQL: ORA-00909: invalid number of arguments
00909. 00000 - "invalid number of arguments"
However, when I insert an object of the subtype inCourseCompany it is inserted correctly:
INSERT INTO companies_objtab VALUES (
inCourseCompany('G11111111','','',TO_DATE(sysdate, 'dd/mm/yyyy hh24:mi:ss'),'',address('','','','',''), address('','','','',''), 100)
);
Any hint about what causes the error?
I am using Oracle SQL Developer 4.0.2.15.21 and Oracle Database Express Edition 11g Release 2.
Thank you in advance.
i tried all your statements right as you posted them (copy-paste). Both on 12c and 11gR2. Everything worked, both inserts. The only thing I noticed is that your create table is a bit incorrect. This is the correct one (but this does not explain the error you get). HTH KR
CREATE TABLE companies_objtab OF company (CIF PRIMARY KEY) OBJECT IDENTIFIER IS PRIMARY KEY;
Maybe try dropping the table and creating it again.
create table mbastudent
(
semester varchar2(20) ,
stud_info student
);
this is object table i have created
now iserting value--
insert into mbastudent
(semester,stud_info )
values
('1st' ,student(1100 ,'KUMAR', '07-OCT-80', '04-MAR-14', 15000))
insert into mbastudent
(semester,stud_info )
values ('2nd',student(1101,'SESHU', '07-OCT-81', '04-MAR-14', 15000));
select ref(a) from mbastudent a;
--how to get ref value of object
You may find it in
Oracle docs from site
I dont now structure of student. My sugesstion is
student (
id number,
name varchar2(4000),
birthday date,
begin_date date,
cost number
)
And you want to get a name, cost and semester
SELECT semester, stud_info.name, stud_info.cost
FROM mbastudent s
I am trying to do a trigger that updates a sum of all credits on update of the grade or a insert of a new one. That's my tables
create table Department (
Department_ID varchar(4) not null,
Name varchar(25) unique,
Department_Head_ID varchar(9),
College_ID varchar(4),
Credits_To_Degree NUMBER(3),
constraint pkDepartment primary key (Department_ID));
create table Enrollment (
Student_ID varchar(9) not null,
Course_ID varchar(5) not null,
Registered_Date date,Grade NUMBER,
Status varchar(4),constraint pkEnrollment primary key
(Student_ID, Course_ID));
create table Student (
Student_ID varchar(9) not null,
First_Name varchar(25),
Last_Name varchar(25),
Phone char(11),
Birth_Date date,
Street varchar(100),
Zip_Code char(5),
Department varchar(4),
Credits integer,
Eligible char(4), constraint pkStudent primary key
(Student_ID),constraint fkDeptId foreign key (Department)
references Department(Department_ID));
ALTER TABLE Department ADD FOREIGN KEY (Department_Head_ID)
REFERENCES Faculty(Faculty_Id) INITIALLY DEFERRED;
ALTER TABLE Department ADD FOREIGN KEY(College_ID) REFERENCES
College(College_ID) INITIALLY DEFERRED;
the trigger:
create or replace TRIGGER Credits
after INSERT OR UPDATE
ON enrollment
REFERENCING NEW AS New OLD AS Old
FOR EACH ROW
BEGIN
UPDATE STUDENT
SET CREDITS=(SELECT SUM(c.CREDITS) FROM COURSE c,ENROLLMENT e
WHERE c.COURSE_ID = e.COURSE_ID
and e.STUDENT_ID = :new.student_id
and e.GRADE>= 60 )
WHERE STUDENT.STUDENT_ID=:new.student_id;
END;
The trigger compiles but when i change value of the grade a get this error
UPDATE "FELIX"."ENROLLMENT" SET GRADE = '60' WHERE ROWID = 'AAAGUSAABAAALKJAAF' AND ORA_ROWSCN = '3540016'
ORA-20003: An error has occurred while performing credits trigger
ORA-06512: at "FELIX.CREDITS", line 5
ORA-04088: error during execution of trigger 'FELIX.CREDITS'
One error saving changes to table "FELIX"."ENROLLMENT":
Row 6: ORA-20003: An error has occurred while performing credits trigger
ORA-06512: at "FELIX.CREDITS", line 5
ORA-04088: error during execution of trigger 'FELIX.CREDITS'
line 5 is a FOR EACH ROW command
I figure out that the problem is in the :new.student_id. But how could i get the id of the row that the triggers fires upon.
Thanks in advance for the help.
I have following object tables in oracle DB.
create type deposit_ty as object
(
depno number(6),
depcategory ref depcategory_ty,
amount number(6),
period number(2)
);
create type deposit_ntty as table of deposit_ty;
create type address_ty as object
(
homeno number,
street varchar(30),
city varchar(30)
);
create type customer_ty as object
(
cusid char(4),
custname varchar(40),
address address_ty,
dob DATE,
deposits deposit_ntty
);
can any one tell what is the difference between column address and deposits in customer_ty object table?
An object type/abstract data type/record is like a row or tuple: it contains an ordered set of attributes. To populate address you must set one and only one value for each of homeno, street, and city.
A nested table is like a table: it contains an unordered set of rows. Usually a nested table only contains a set of simple values, like a number. In your example, it is a set of object types. To populate deposits you can create any number of deposit_ty.
For example:
declare
customer customer_ty :=
customer_ty(
'ABC',
'Name',
address_ty('123', 'fake street', 'Springfield'),
sysdate,
deposit_ntty(
deposit_ty(1, null, 100, 1),
deposit_ty(2, null, 200, 2)
)
);
begin
null;
end;
Also, you probably want to use a VARCHAR2 instead of VARCHAR or CHAR. And if it's not too late, throw out all this object stuff and use tables like everyone else.
I have a series of tables and objects I have defined. I have an object nested table that I am trying to insert values into. The values are in the form of a variable array but I don't know how to insert them. my tables and code are as follows.
Table wu.classes
crn number(5)
department varchar2(8)
title carchar2(25)
Table wu.students
student_id char(11)
name varchar2(10)
dept varchar2(8)
advisor varchar(10)
classes wu.classes_va
wu.classes_va varray(5) of number (5)
create type classes_ty as object(crn varchar2(5),department varchar2(8), coursetitle varchar2(25)
create table classes_ot of classes_ty;
insert into classes_ot select crn,department,title from wu.classes;
create or replace type classes_ref_ty as table of ref classes_ty;
create table student_plus(student# varchar2(11),student_name varchar2(10),major varchar2(8), advisor (10), enrolled classes_ref_ty) nested table enrolled store as classes_ref_ty_tab;
Problem here (I need to loop through to fill the table but I just need to know how to do it for one values and i can figure the rest out):
begin
insert into student_plus values('700-123-948','Hooker','CS','VanScoy',classes_ref_ty();
insert into table(select enrolled from student_plus where student#='700-123-948')
select ref(c) from classes_ot c where ???
end;
/
I don't know how to access the variable array and use it with the classes_ref_ty.