I want to create Interim table from main table for DBMS_Redefinition Process.
but the requirement is not to write entire create syntax because there are n number of tables and i cant take each value every time.
INTERIM TABLE = table_INTER
MAIN_TABLE = table_MAIN
for eg..
CREATE TABLE table_INTER (
ContactPartKey NUMBER(20) NOT NULL,
PartyKey NUMBER(10) NOT NULL,
ConParticipationRoleKey NUMBER(10) NOT NULL,
ChannelKey NUMBER(10) NOT NULL,
StateKey NUMBER(10) NOT NULL,
StateReasonKey NUMBER(10) NOT NULL,
NextStateKey NUMBER(10) NOT NULL,
PreviousStateKey NUMBER(10) NOT NULL,
QueueKey NUMBER(10) NOT NULL,
RtgPointKey NUMBER(10) NOT NULL,
ContactPartIndKey NUMBER(10) NOT NULL,
DeviceKey NUMBER(10) NOT NULL,
ContactID NUMBER(20) NOT NULL,
Parent1ContactID NUMBER(20) ,
StartDateKey NUMBER(10) NOT NULL,
EndDateKey NUMBER(10) NOT NULL,
StartTimeKey NUMBER(3) NOT NULL,
EndTimeKey NUMBER(3) NOT NULL,
StartDateTime DATE NOT NULL,
EndDateTime DATE NOT NULL,
StateDur NUMBER(10) NOT NULL,
ContactAllocatedCost decimal(14,4) ,
ContactPartSeqNum NUMBER(10) NOT NULL,
ContactInProcessInd NUMBER(3) NOT NULL,
FinalPartInd NUMBER(3) NOT NULL,
Counter NUMBER(10) NOT NULL,
SourceKey NUMBER(10) NOT NULL,
StreamKey NUMBER(10) NOT NULL,
ProcessKey NUMBER(10) ,
SelfServiceInd NUMBER(3) )
--PRIMARY KEY(ContactPartKey)
TABLESPACE AVAYAIQFACT1
STORAGE (INITIAL 2097152 NEXT 2097152)
PCTFREE 0
PARTITION BY RANGE (STARTDATETIME)
INTERVAL(NUMTOYMINTERVAL(1, 'MONTH'))
(PARTITION P1 VALUES LESS THAN (TO_DATE('01/09/2013', 'DD/MM/YYYY')) TABLESPACE T1,
PARTITION P2 VALUES LESS THAN (TO_DATE('01/10/2013', 'DD/MM/YYYY')) TABLESPACE T1);
In above syntax, column name value cant be given every time. So what i did was
create table table_INTER as (select * from table_MAIN);
But can anyone tell me how to introduce partition in this interim table (table_INTER).
Can you try this?
CREATE TABLE TABLE_INTER
PARTITION BY RANGE (STARTDATETIME)
INTERVAL ( NUMTOYMINTERVAL ( 1,
'MONTH' ) )
( PARTITION P1
VALUES LESS THAN
(TO_DATE ( '01/09/2013',
'DD/MM/YYYY' ))
TABLESPACE T1,
PARTITION P2
VALUES LESS THAN
(TO_DATE ( '01/10/2013',
'DD/MM/YYYY' ))
TABLESPACE T1 )
AS
( SELECT * FROM TABLE_MAIN );
Related
I have done this and it works.
CREATE TABLE Employee (
Employee_ID varchar2(10) PRIMARY KEY NOT NULL,
Office_ID varchar2(7) NOT NULL,
Emp_FirstName varchar2(20) NOT NULL,
Emp_LastName varchar2(20) NOT NULL,
Emp_Gender varchar2(1) NOT NULL,
Emp_DateOfBirth Date NOT NULL,
Hire_Date date NOT NULL,
Emp_CurrentDate date default sysdate,
Emp_Telephone varchar2(11) NOT NULL,
Emp_Email varchar2(30) NOT NULL,
Emp_AddressLine varchar2(50) NOT NULL,
Emp_PostCode varchar2(8) NOT NULL,
Emp_Speciality varchar2(20) NOT NULL,
Emp_Qualification varchar2(20) NOT NULL,
Emp_AwardingBody varchar2(30) NOT NULL,
Emp_Salary number(6) NOT NULL,
Emp_Supervised_By varchar2(10) NOT NULL,
Employment_History1 varchar2(50),
Employment_History2 varchar2(50),
Employment_History3 varchar2(50) ,
CONSTRAINT fk_staff_office FOREIGN KEY (Office_ID) REFERENCES office (Office_ID),
CONSTRAINT Hire_Date_CK check (Hire_Date < Emp_CurrentDate AND (Hire_Date - Emp_DateOfBirth)/365 > 18),
CONSTRAINT Emp_DateOfBirth_CK check (Emp_DateOfBirth > TO_DATE('1900-01-01', 'YYYY-MM-DD')),
CONSTRAINT Emp_Salary_CK check (Emp_Salary > 0 AND Emp_Salary < 150000),
CONSTRAINT Emp_Gender_CK CHECK (Emp_Gender in ('M','F')),
CONSTRAINT Emp_Email_CK CHECK ( Emp_Email like '%_#__%._%'),
CONSTRAINT Emp_Telephone_CK CHECK (regexp_like(Emp_Telephone, '^[0123456789]{11}$') AND Emp_Telephone like '0%'),
CONSTRAINT Emp_FirstName_CK CHECK (regexp_like(Emp_FirstName, '^[ABCDEFGHIJKLMNOPQRSTUVWXYZ]{1,20}$')),
CONSTRAINT Emp_LastName_CK CHECK (regexp_like(Emp_LastName, '^[ABCDEFGHIJKLMNOPQRSTUVWXYZ]{1,20}$')),
CONSTRAINT Emp_PostCode_CK CHECK (regexp_like ( Emp_PostCode , '([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z]))))\s?[0-9][A-Za-z]{2})')),
CONSTRAINT Emp_Speciality_CK CHECK (regexp_like(Emp_Speciality, '^[ABCDEFGHIJKLMNOPQRSTUVWXYZ ]{1,20}$')),
CONSTRAINT Emp_Qualification_CK CHECK (regexp_like(Emp_Qualification, '^[ABCDEFGHIJKLMNOPQRSTUVWXYZ ]{1,20}$')),
CONSTRAINT Emp_AwardingBody_CK CHECK (regexp_like(Emp_AwardingBody, '^[ABCDEFGHIJKLMNOPQRSTUVWXYZ ]{1,30}$'))
);
What I want to do now is to create a constraint that enables me to set the value of the attribute Emp_Supervised_By automatically as the same value of the Employee_ID attribute when the Emp_Speciality is 'Manager'.
I tried to do it like this but it doesn't work:
CONSTRAINT Emp_Supervised_By_CK check (CASE WHEN Emp_Speciality = 'MANAGER' THEN Emp_Supervised_By = Employee_ID)
Is a requirement to use CONSTRAINTS NOT TRIGGERS.
Because you mentioned computed columns, maybe your business requirement can be satisfied with the below instead of a constraint.
CREATE TABLE Employee (
...
Employee_ID varchar2(10) PRIMARY KEY NOT NULL,
Emp_Speciality varchar2(20) NOT NULL,
Emp_Supervised_By AS (CASE WHEN Emp_Speciality = 'Manager' THEN Employee_ID ELSE NULL END)
....
);
I did this and it works:
CREATE TABLE OrderLine (
Invoice_ID varchar2(10) PRIMARY KEY NOT NULL,
Item_ID varchar2(10) NOT NULL,
Unit_Price number(6,2) NOT NULL,
Quantity number(6) NOT NULL,
Total_Price number(38,2) AS (CASE WHEN Quantity >= 50 THEN
((Unit_Price*Quantity)-((Unit_Price*Quantity)*0.80)) ELSE Unit_Price*Quantity END) NOT NULL,
CONSTRAINT fk_item_invoice FOREIGN KEY(Invoice_ID) REFERENCES Invoice (Invoice_ID),
CONSTRAINT fk_item_item FOREIGN KEY(Item_ID) REFERENCES Item (Item_ID),
CONSTRAINT Unit_Price_CK CHECK (Unit_Price > 0),
CONSTRAINT Quantity_CK CHECK (Quantity > 0),
CONSTRAINT Total_Price_CK CHECK (Total_Price > 0)
);
CREATE TABLE Invoice (
Invoice_ID varchar2(10) PRIMARY KEY NOT NULL,
Office_ID varchar2(7) NOT NULL,
Invoice_Date Date NOT NULL,
Total_Cost number (9) NOT NULL,
CONSTRAINT fk_order_Office FOREIGN KEY(Office_ID) REFERENCES Office (Office_ID),
CONSTRAINT Total_Cost_CK CHECK (Total_Cost > 0)
);
I want to calculate The TotalCost like the sum of TotalPrice(s).
Is there a way to use the same approach ass before ?
What i am trying to do is calculate diner_payment_due (DINER TABLE), by multiplying food_serve_cost (FOOD_SERVE TABLE) by food_serve_size (FS_DINER TABLE)
CREATE TABLE diner (
diner_no NUMBER(8) NOT NULL,
diner_payment_due NUMBER(6,2) NOT NULL,
diner_seat_no NUMBER(2) NOT NULL,
diner_seated DATE NOT NULL,
diner_completed DATE,
table_no NUMBER(2) NOT NULL
);
CREATE TABLE food_serve (
food_item_no NUMBER(4) NOT NULL,
food_serve_size CHAR(2) NOT NULL,
food_serve_kilojoules NUMBER(4) NOT NULL,
food_serve_cost NUMBER(5,2) NOT NULL
);
CREATE TABLE FS_DINER (
DINER_NO NUMBER(8) NOT NULL,
FOOD_ITEM_NO NUMBER(4) NOT NULL,
FOOD_SERVE_SIZE CHAR(2 BYTE) NOT NULL,
FS_DINER_NO_SERVES NUMBER(1) NOT NULL,
FS_DINER_ITEM_SERVED CHAR (1) NOT NULL,
CONSTRAINT pk_fs_diner PRIMARY KEY (DINER_NO, FOOD_ITEM_NO,FOOD_SERVE_SIZE)
);
I just need to return a single values and then insert into the diner table, i'm thinking that I need to do a Inner Join, then simply sum (food_serve_cost * NO_SERVES) then group by DINER_NO ?
INSERT INTO DINER ( DINER_NO, DINER_PAYMENT_DUE, DINER_SEAT_NO, DINER_SEATED, DINER_COMPLETED, TABLE_NO) INSERT INTO DINER VALUES (1, SELECT SUM (FOOD_SERVE.FOOD_SERVE_COST * FS_DINER..., , 1, 1/05/2017, 1 /05/2017, 1);
Am updating diner table based on the value from other two tables.
INSERT INTO DINER
(SELECT fs.diner_no,
(fs.food_serve_cost * fd.FOOD_SERVE_SIZE),
11,sysdate,sysdate,11 /*Am assuming, Due to Not null constraint, there will be error*/
FROM food_serve fs,
FS_DINER fd
WHERE fs.food_item_no = fd.food_item_no)
I'm trying to create a table, but I keep getting this error:
ORA-00904: : invalid identifier
Please help.
CREATE TABLE salesreport
(
pid number(10) NOT NULL,
uid number(10) NOT NULL,
pname varchar2(50) NOT NULL,
price number(10) NOT NULL,
qty number(10) NOT NULL,
dateoforder varchar2(20) DEFAULT NULL,
total varchar2(30) NOT NULL
)
CREATE INDEX pid ON salesreport (pid, uid);
uid is a reserved word. Pick something else and it should work.
OR write it like this
CREATE TABLE salesreport (
pid number(10) NOT NULL,
"uid" number(10) NOT NULL,
pname varchar2(50) NOT NULL,
price number(10) NOT NULL,
qty number(10) NOT NULL,
dateoforder date DEFAULT SYSDATE,
total varchar2(30) NOT NULL
);
INDEX pid ON salesreport (pid,"uid");
Having started at the same statements over and over again, I still cannot find the missing right parenthesis. It's appeared when running both of these statements and in order to run the rest of my tables I need to be able to locate the right parenthesis.
I've selected the parenthesis used in the statements and all seemed to match up to the right ones. Can anyone suggest anything?
CREATE TABLE booking (
bookingNo NUMBER(8) PRIMARY KEY,
customerNo NUMBER(8) NOT NULL
REFERENCES customer(customerNo),
registrationNo VARCHAR2(10) NOT NULL
REFERENCES vehicle(registrationNo),
dateOfBooking DATE NOT NULL
DEFAULT SYSDATE,
pickupStreetAddressLine VARCHAR2(30) NOT NULL,
pickupTown VARCHAR2(30) NOT NULL,
pickupPostcode VARCHAR2(10) NOT NULL,
startTime NUMBER(4,2) NOT NULL,
startDate DATE NOT NULL
DEFAULT SYSDATE,
endTime NUMBER(4,2) NOT NULL,
endDate DATE NOT NULL
DEFAULTSYSDATE,
noOfPassengers NUMBER(3) NOT NULL
CONSTRAINT CHECK(noOfPassengers > 0 AND noOfPassengers <= 73)
price NUMBER(8,2) NOT NULL
);
CREATE TABLE employees (
nationalInsuranceNo VARCHAR2(10) PRIMARY KEY,
fullName VARCHAR2(50) NOT NULL,
streetAddress VARCHAR2(30) NOT NULL,
town VARCHAR2(30),
postcode VARCHAR2(10) NOT NULL,
homeNo NUMBER(11)
dateOfBirth DATE NOT NULL,
gender VARCHAR2(8) NOT NULL
CONSTRAINT CHECK(gender="Male" OR gender="Female"),
jobDescription VARCHAR2(30) NOT NULL,
currentSalary NUMBER(6) NOT NULL
CONSTRAINT CHECK(currentSalary>0)
);
Try using a standard indentation scheme to visually verify your formatting.
Here I moved each significant paren to a newline and indented each piece separately.
I put comments next to a few items that seem wrong:
CREATE TABLE
booking
(
bookingNo NUMBER(8) PRIMARY KEY,
customerNo NUMBER(8) NOT NULL
REFERENCES customer(customerNo),
registrationNo VARCHAR2(10) NOT NULL
REFERENCES vehicle(registrationNo),
dateOfBooking DATE NOT NULL
DEFAULT SYSDATE,
pickupStreetAddressLine VARCHAR2(30) NOT NULL,
pickupTown VARCHAR2(30) NOT NULL,
pickupPostcode VARCHAR2(10) NOT NULL,
startTime NUMBER(4,2) NOT NULL,
startDate DATE NOT NULL
DEFAULT SYSDATE,
endTime NUMBER(4,2) NOT NULL,
endDate DATE NOT NULL
DEFAULT SYSDATE, -- THERE WAS A MISSING SPACE HERE *********************
noOfPassengers NUMBER(3) NOT NULL, -- MISSING COMMA ********
CONSTRAINT Check_noOfPassengers CHECK -- ADD A CONSTRAINT NAME *********
(
noOfPassengers > 0
AND noOfPassengers <= 73
), -- THERE WAS A MISSING COMMA HERE *******************
price NUMBER(8,2) NOT NULL
);
CREATE TABLE
employees
(
nationalInsuranceNo VARCHAR2(10) PRIMARY KEY,
fullName VARCHAR2(50) NOT NULL,
streetAddress VARCHAR2(30) NOT NULL,
town VARCHAR2(30),
postcode VARCHAR2(10) NOT NULL,
homeNo NUMBER(11), -- THERE WAS A MISSING COMMA HERE ***************
dateOfBirth DATE NOT NULL,
gender VARCHAR2(8) NOT NULL, -- MISSING COMMA *****
CONSTRAINT Check_gender CHECK -- ADD A CONSTRAINT NAME *********
(
gender="Male"
OR gender="Female"
),
jobDescription VARCHAR2(30) NOT NULL,
currentSalary NUMBER(6) NOT NULL, -- MISSING COMMA
CONSTRAINT Check_currentSalary CHECK -- ADD A CONSTRAINT NAME *********
(
currentSalary>0
)
);
I don't have Oracle installed to test, but is there a missing comma for the column noOfPassengers above? More generally, it may not be a missing right parens, but a parens that is out of place because of another syntax error. Hope that helps.
Change this DEFAULTSYSDATE to this DEFAULT SYSDATE on the 17th line
Also, add the column name before each CHECK and after the CONSTRAINT words. And add a comma after the first CONSTRAINT statement.
Hope it helps :)
I'm trying to run a file which contains INSERT statements. The statements will either give me an not enough values error or unique constraint error.
Below is my create table statement:
CREATE TABLE PART
(PNum VARCHAR(25) NOT NULL,
PName VARCHAR(75) NOT NULL,
PUnitPrice NUMBER(7,2) NOT NULL,
ComponentOf VARCHAR(25),
CONSTRAINT PART_PKEY PRIMARY KEY(PNum),
CONSTRAINT PART_FKEY FOREIGN KEY(ComponentOf)
REFERENCES PART(PNum)
};
CREATE TABLE MANUFACTURER
(MName VARCHAR(50) NOT NULL,
MAddress VARCHAR(100) NOT NULL,
MPhone VARCHAR(25) NOT NULL,
CONSTRAINT MANUFACTURER_PKEY PRIMARY KEY(MName),
);
CREATE TABLE PART-MANUFACTURED
(MDate DATE,not null
PNum VARCHAR(25) NOT NULL,
MName VARCHAR(50) NOT NULL,
Quantity NUMBER(10) NOT NULL,
CONSTRAINT PART-MANUFACTURED_PKEY PRIMARY KEY(MName,PNum,MDate),
CONSTRAINT PART-MANUFACTURED_FKEY1 FOREIGN KEY(PNum)
REFERENCES PART(PNum),
CONSTRAINT PART-MANUFACTURED_FKEY2 FOREIGN KEY(MName)
REFERENCES MANUFACTURER(MName)
);
CREATE TABLE CUSTOMER
(CNum VARCHAR(25) NOT NULL,
CName VARCHAR(75) NOT NULL,
CType VARCHAR(20) NOT NULL,
CONSTRAINT CUSTOMER_PKEY PRIMARY KEY(CNum),
CONSTRAINT CHECK_CType
CHECK(CType IN (‘INDIVIDUAL,’INSTITUITION’))
);
CREATE TABLE ORDERS
(CNum VARCHAR(25) NOT NULL,
PNum VARCHAR(25) NOT NULL,
OrderDate DATE NOT NULL,
OrderQuantity NUMBER(7,2) NOT NULL,
CONSTRAINT ORDERS_PKEY PRIMARY KEY(CNum,PNum,OrderDate),
CONSTRAINT ORDERS_FKEY1 FOREIGN KEY(CNum)
REFERENCES CUSTOMER(CNum),
CONSTRAINT ORDERS_FKEY2 FOREIGN KEY(PNum)
REFERENCES PART(PNum)
);
Below is the statement that gives me the not enough values error:
INSERT INTO PART
VALUES('S001','System-Economy',1100,null);
INSERT INTO PART
VALUES('M001','Monitor-17 inch',250,'S001');
For the unique constraints error, I believe i have to insert the data in order of their primary and referencing keys right?
So what do I need to change in order for the the insert statements to work?
I dont see any error on Insert. The problem is with your create table. Plenty to correct. Try this
CREATE TABLE PART ( PNUM VARCHAR ( 25 ) NOT NULL,
PNAME VARCHAR ( 75 ) NOT NULL,
PUNITPRICE NUMBER ( 7, 2 ) NOT NULL,
COMPONENTOF VARCHAR ( 25 ),
CONSTRAINT PART_PKEY PRIMARY KEY ( PNUM ),
CONSTRAINT PART_FKEY FOREIGN KEY
( COMPONENTOF )
REFERENCES PART ( PNUM ) );
CREATE TABLE MANUFACTURER ( MNAME VARCHAR ( 50 ) NOT NULL,
MADDRESS VARCHAR ( 100 ) NOT NULL,
MPHONE VARCHAR ( 25 ) NOT NULL,
CONSTRAINT MANUFACTURER_PKEY PRIMARY KEY ( MNAME ) );
CREATE TABLE PART_MANUFACTURED ( MDATE DATE NOT NULL,
PNUM VARCHAR ( 25 ) NOT NULL,
MNAME VARCHAR ( 50 ) NOT NULL,
QUANTITY NUMBER ( 10 ) NOT NULL,
CONSTRAINT PART_MANUFACTURED_PKEY PRIMARY KEY
( MNAME, PNUM, MDATE ),
CONSTRAINT PART_MANUFACTURED_FKEY1 FOREIGN KEY
( PNUM )
REFERENCES PART ( PNUM ),
CONSTRAINT PART_MANUFACTURED_FKEY2 FOREIGN KEY
( MNAME )
REFERENCES MANUFACTURER ( MNAME ) );
CREATE TABLE CUSTOMER ( CNUM VARCHAR ( 25 ) NOT NULL,
CNAME VARCHAR ( 75 ) NOT NULL,
CTYPE VARCHAR ( 20 ) NOT NULL,
CONSTRAINT CUSTOMER_PKEY PRIMARY KEY ( CNUM ),
CONSTRAINT CHECK_CTYPE CHECK
( CTYPE IN ('INDIVIDUAL', 'INSTITUITION') ) );
CREATE TABLE ORDERS ( CNUM VARCHAR ( 25 ) NOT NULL,
PNUM VARCHAR ( 25 ) NOT NULL,
ORDERDATE DATE NOT NULL,
ORDERQUANTITY NUMBER ( 7, 2 ) NOT NULL,
CONSTRAINT ORDERS_PKEY PRIMARY KEY
( CNUM, PNUM, ORDERDATE ),
CONSTRAINT ORDERS_FKEY1 FOREIGN KEY
( CNUM )
REFERENCES CUSTOMER ( CNUM ),
CONSTRAINT ORDERS_FKEY2 FOREIGN KEY
( PNUM )
REFERENCES PART ( PNUM ) );
INSERT INTO
PART
VALUES
( 'S001',
'System-Economy',
1100,
NULL );
INSERT INTO
PART
VALUES
( 'M001',
'Monitor-17 inch',
250,
'S001' );