Synapse increment rank Partition By split groupings of duplicate values - sql
In my synapse, I have a schedule table that stores information about all programs for a given day. It would be helpful if I could include rank/dense_rank in the output from this table based on the title and ordered by the event number and program date. Here is the table script and sample records. Could you please help me in achieving the What I expect column from my screenshot -
CREATE TABLE [Prod].[Schedule]
(
[EventNo] [int] NOT NULL,
[ProgramDate] [date] NOT NULL,
[PlannedStartDateTime] [datetime2](3) NOT NULL,
[PlannedEndDateTime] [datetime2](3) NOT NULL,
[PlannedDuration] [varchar](15) NOT NULL,
[Title] [varchar](500) NOT NULL,
[Type] [varchar](10) NOT NULL
)
WITH
(
DISTRIBUTION = ROUND_ROBIN
);
INSERT INTO [Prod].[Schedule] VALUES(1,'2023-01-27','2023-01-27 06:00:00','2023-01-27 06:20:00','00:20:00:00','Breakfast - Episode 49','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(7,'2023-01-27','2023-01-27 06:22:00','2023-01-27 06:35:00','00:13:00:00','Breakfast - Episode 49','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(11,'2023-01-27','2023-01-27 06:37:00','2023-01-27 06:50:00','00:13:00:00','Breakfast - Episode 49','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(16,'2023-01-27','2023-01-27 06:52:00','2023-01-27 07:20:00','00:28:00:00','Breakfast - Episode 49','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(25,'2023-01-27','2023-01-27 07:23:30','2023-01-27 07:35:00','00:11:30:00','Breakfast - Episode 49','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(32,'2023-01-27','2023-01-27 07:38:30','2023-01-27 07:50:00','00:11:30:00','Breakfast - Episode 49','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(40,'2023-01-27','2023-01-27 07:53:30','2023-01-27 08:20:00','00:26:30:00','Breakfast - Episode 49','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(48,'2023-01-27','2023-01-27 08:23:30','2023-01-27 08:35:00','00:11:30:00','Breakfast - Episode 49','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(56,'2023-01-27','2023-01-27 08:38:30','2023-01-27 08:50:00','00:11:30:00','Breakfast - Episode 49','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(63,'2023-01-27','2023-01-27 08:53:30','2023-01-27 09:10:00','00:16:30:00','Breakfast - Episode 49','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(68,'2023-01-27','2023-01-27 09:13:30','2023-01-27 09:26:30','00:13:00:00','Breakfast - Episode 49','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(76,'2023-01-27','2023-01-27 09:30:00','2023-01-27 09:56:30','00:26:30:00','Briefing - Episode 336','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(84,'2023-01-27','2023-01-27 10:00:00','2023-01-27 10:20:00','00:20:00:00','Friday Morning - Episode 20','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(86,'2023-01-27','2023-01-27 10:22:00','2023-01-27 10:35:00','00:13:00:00','Friday Morning - Episode 20','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(91,'2023-01-27','2023-01-27 10:37:00','2023-01-27 10:50:00','00:13:00:00','Friday Morning - Episode 20','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(95,'2023-01-27','2023-01-27 10:52:00','2023-01-27 11:20:00','00:28:00:00','Friday Morning - Episode 20','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(97,'2023-01-27','2023-01-27 11:23:00','2023-01-27 11:35:00','00:12:00:00','Friday Morning - Episode 20','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(103,'2023-01-27','2023-01-27 11:37:00','2023-01-27 11:58:00','00:21:00:00','Friday Morning - Episode 20','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(109,'2023-01-27','2023-01-27 12:00:00','2023-01-27 12:20:00','00:20:00:00','Friday Afternoon - Episode 12','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(111,'2023-01-27','2023-01-27 12:22:00','2023-01-27 12:35:00','00:13:00:00','Friday Afternoon - Episode 12','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(115,'2023-01-27','2023-01-27 12:37:00','2023-01-27 12:50:00','00:13:00:00','Friday Afternoon - Episode 12','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(118,'2023-01-27','2023-01-27 12:52:00','2023-01-27 13:20:00','00:28:00:00','Friday Afternoon - Episode 12','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(120,'2023-01-27','2023-01-27 13:22:00','2023-01-27 13:35:00','00:13:00:00','Friday Afternoon - Episode 12','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(123,'2023-01-27','2023-01-27 13:37:00','2023-01-27 13:58:00','00:21:00:00','Friday Afternoon - Episode 12','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(131,'2023-01-27','2023-01-27 14:00:00','2023-01-27 14:20:00','00:20:00:00','The Briefing - Episode 62','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(133,'2023-01-27','2023-01-27 14:22:00','2023-01-27 14:35:00','00:13:00:00','The Briefing - Episode 62','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(138,'2023-01-27','2023-01-27 14:37:00','2023-01-27 14:58:00','00:21:00:00','The Briefing - Episode 62','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(142,'2023-01-27','2023-01-27 15:00:00','2023-01-27 15:20:00','00:20:00:00','Friday Show - Episode 59','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(144,'2023-01-27','2023-01-27 15:23:00','2023-01-27 15:35:00','00:12:00:00','Friday Show - Episode 59','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(148,'2023-01-27','2023-01-27 15:37:00','2023-01-27 15:50:00','00:13:00:00','Friday Show - Episode 59','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(153,'2023-01-27','2023-01-27 15:52:00','2023-01-27 16:20:00','00:28:00:00','Friday Show - Episode 59','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(155,'2023-01-27','2023-01-27 16:22:00','2023-01-27 16:35:00','00:13:00:00','Friday Show - Episode 59','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(161,'2023-01-27','2023-01-27 16:37:00','2023-01-27 16:50:00','00:13:00:00','Friday Show - Episode 59','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(165,'2023-01-27','2023-01-27 16:52:00','2023-01-27 17:20:00','00:28:00:00','Friday Show - Episode 59','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(167,'2023-01-27','2023-01-27 17:22:00','2023-01-27 17:35:00','00:13:00:00','Friday Show - Episode 59','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(172,'2023-01-27','2023-01-27 17:37:00','2023-01-27 17:58:00','00:21:00:00','Friday Show - Episode 59','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(176,'2023-01-27','2023-01-27 18:00:00','2023-01-27 18:15:00','00:15:00:00','Send to Phone - Episode 392','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(182,'2023-01-27','2023-01-27 18:17:00','2023-01-27 18:30:00','00:13:00:00','Send to Phone - Episode 392','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(186,'2023-01-27','2023-01-27 18:32:00','2023-01-27 18:45:00','00:13:00:00','Send to Phone - Episode 392','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(191,'2023-01-27','2023-01-27 18:47:00','2023-01-27 18:58:00','00:11:00:00','Send to Phone - Episode 392','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(196,'2023-01-27','2023-01-27 19:00:00','2023-01-27 19:15:00','00:15:00:00','Listen to Music - Episode 18','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(198,'2023-01-27','2023-01-27 19:18:00','2023-01-27 19:30:00','00:12:00:00','Listen to Music - Episode 18','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(205,'2023-01-27','2023-01-27 19:33:00','2023-01-27 19:45:00','00:12:00:00','Listen to Music - Episode 18','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(213,'2023-01-27','2023-01-27 19:48:00','2023-01-27 19:57:00','00:09:00:00','Listen to Music - Episode 18','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(215,'2023-01-27','2023-01-27 20:00:00','2023-01-27 20:15:00','00:15:00:00','Tonight Game - Episode 16','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(222,'2023-01-27','2023-01-27 20:18:00','2023-01-27 20:30:00','00:12:00:00','Tonight Game - Episode 16','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(229,'2023-01-27','2023-01-27 20:33:00','2023-01-27 20:45:00','00:12:00:00','Tonight Game - Episode 16','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(236,'2023-01-27','2023-01-27 20:48:00','2023-01-27 20:57:00','00:09:00:00','Tonight Game - Episode 16','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(242,'2023-01-27','2023-01-27 21:00:00','2023-01-27 21:15:00','00:15:00:00','Tonight Game - Episode 16','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(249,'2023-01-27','2023-01-27 21:18:00','2023-01-27 21:30:00','00:12:00:00','Tonight Game - Episode 16','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(256,'2023-01-27','2023-01-27 21:33:00','2023-01-27 21:45:00','00:12:00:00','Tonight Game - Episode 16','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(263,'2023-01-27','2023-01-27 21:48:00','2023-01-27 21:57:00','00:09:00:00','Tonight Game - Episode 16','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(271,'2023-01-27','2023-01-27 22:00:00','2023-01-27 22:15:00','00:15:00:00','Tonight Game - Episode 16','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(279,'2023-01-27','2023-01-27 22:18:00','2023-01-27 22:30:00','00:12:00:00','Tonight Game - Episode 16','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(286,'2023-01-27','2023-01-27 22:33:00','2023-01-27 22:45:00','00:12:00:00','Tonight Game - Episode 16','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(292,'2023-01-27','2023-01-27 22:48:00','2023-01-27 22:57:00','00:09:00:00','Tonight Game - Episode 16','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(300,'2023-01-27','2023-01-27 23:00:00','2023-01-27 23:15:00','00:15:00:00','Head - Episode 418','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(305,'2023-01-27','2023-01-27 23:17:00','2023-01-27 23:30:00','00:13:00:00','Head - Episode 418','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(310,'2023-01-27','2023-01-27 23:32:00','2023-01-27 23:45:00','00:13:00:00','Head - Episode 418','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(314,'2023-01-27','2023-01-27 23:47:00','2023-01-27 23:57:00','00:10:00:00','Head - Episode 418','LIVE');
INSERT INTO [Prod].[Schedule] VALUES(322,'2023-01-27','2023-01-27 00:00:00','2023-01-27 00:15:00','00:15:00:00','Listen to Music Replay - Episode 18','REPLAY');
INSERT INTO [Prod].[Schedule] VALUES(324,'2023-01-27','2023-01-27 00:18:00','2023-01-27 00:35:00','00:17:00:00','Listen to Music Replay - Episode 18','REPLAY');
INSERT INTO [Prod].[Schedule] VALUES(326,'2023-01-27','2023-01-27 00:38:00','2023-01-27 00:45:00','00:07:00:00','Listen to Music Replay - Episode 18','REPLAY');
INSERT INTO [Prod].[Schedule] VALUES(328,'2023-01-27','2023-01-27 00:48:00','2023-01-27 00:57:00','00:09:00:00','Listen to Music Replay - Episode 18','REPLAY');
INSERT INTO [Prod].[Schedule] VALUES(330,'2023-01-27','2023-01-27 01:00:00','2023-01-27 01:15:00','00:15:00:00','Head Replay - Episode 418','REPLAY');
INSERT INTO [Prod].[Schedule] VALUES(332,'2023-01-27','2023-01-27 01:17:00','2023-01-27 01:30:00','00:13:00:00','Head Replay - Episode 418','REPLAY');
INSERT INTO [Prod].[Schedule] VALUES(334,'2023-01-27','2023-01-27 01:32:00','2023-01-27 01:45:00','00:13:00:00','Head Replay - Episode 418','REPLAY');
INSERT INTO [Prod].[Schedule] VALUES(336,'2023-01-27','2023-01-27 01:47:00','2023-01-27 01:57:00','00:10:00:00','Head Replay - Episode 418','REPLAY');
INSERT INTO [Prod].[Schedule] VALUES(338,'2023-01-27','2023-01-27 02:00:00','2023-01-27 02:15:00','00:15:00:00','Tonight Game Replay - Episode 16','REPLAY');
INSERT INTO [Prod].[Schedule] VALUES(340,'2023-01-27','2023-01-27 02:18:00','2023-01-27 02:30:00','00:12:00:00','Tonight Game Replay - Episode 16','REPLAY');
INSERT INTO [Prod].[Schedule] VALUES(342,'2023-01-27','2023-01-27 02:33:00','2023-01-27 02:45:00','00:12:00:00','Tonight Game Replay - Episode 16','REPLAY');
INSERT INTO [Prod].[Schedule] VALUES(344,'2023-01-27','2023-01-27 02:48:00','2023-01-27 02:57:00','00:09:00:00','Tonight Game Replay - Episode 16','REPLAY');
INSERT INTO [Prod].[Schedule] VALUES(346,'2023-01-27','2023-01-27 03:00:00','2023-01-27 03:15:00','00:15:00:00','Tonight Game Replay - Episode 16','REPLAY');
INSERT INTO [Prod].[Schedule] VALUES(348,'2023-01-27','2023-01-27 03:18:00','2023-01-27 03:30:00','00:12:00:00','Tonight Game Replay - Episode 16','REPLAY');
INSERT INTO [Prod].[Schedule] VALUES(350,'2023-01-27','2023-01-27 03:33:00','2023-01-27 03:45:00','00:12:00:00','Tonight Game Replay - Episode 16','REPLAY');
INSERT INTO [Prod].[Schedule] VALUES(352,'2023-01-27','2023-01-27 03:48:00','2023-01-27 03:57:00','00:09:00:00','Tonight Game Replay - Episode 16','REPLAY');
INSERT INTO [Prod].[Schedule] VALUES(354,'2023-01-27','2023-01-27 04:00:00','2023-01-27 04:15:00','00:15:00:00','Tonight Game Replay - Episode 16','REPLAY');
INSERT INTO [Prod].[Schedule] VALUES(356,'2023-01-27','2023-01-27 04:18:00','2023-01-27 04:30:00','00:12:00:00','Tonight Game Replay - Episode 16','REPLAY');
INSERT INTO [Prod].[Schedule] VALUES(358,'2023-01-27','2023-01-27 04:33:00','2023-01-27 04:45:00','00:12:00:00','Tonight Game Replay - Episode 16','REPLAY');
INSERT INTO [Prod].[Schedule] VALUES(360,'2023-01-27','2023-01-27 04:48:00','2023-01-27 04:57:00','00:09:00:00','Tonight Game Replay - Episode 16','REPLAY');
INSERT INTO [Prod].[Schedule] VALUES(362,'2023-01-27','2023-01-27 05:00:00','2023-01-27 05:15:00','00:15:00:00','Head Replay - Episode 418','REPLAY');
INSERT INTO [Prod].[Schedule] VALUES(364,'2023-01-27','2023-01-27 05:17:00','2023-01-27 05:30:00','00:13:00:00','Head Replay - Episode 418','REPLAY');
INSERT INTO [Prod].[Schedule] VALUES(366,'2023-01-27','2023-01-27 05:32:00','2023-01-27 05:45:00','00:13:00:00','Head Replay - Episode 418','REPLAY');
INSERT INTO [Prod].[Schedule] VALUES(368,'2023-01-27','2023-01-27 05:47:00','2023-01-27 05:57:00','00:10:00:00','Head Replay - Episode 418','REPLAY');
INSERT INTO [Prod].[Schedule] VALUES(373,'2023-01-27','2023-01-27 05:59:00','2023-01-27 06:00:00','00:01:00:00','UK National Anthem - Episode 369','LIVE');
Related
Triggers working correctly, but raise application error causing some errors with insert statements
I have my code shown below. Everything is working correctly but when my insert statements violate the trigger it throws errors because of my raise_application_error. --Drop tables in case they were created previously DROP TABLE enrollment Purge; DROP TABLE offering Purge; DROP TABLE faculty Purge; DROP TABLE course Purge; DROP TABLE student Purge; --Create student table CREATE TABLE student(StdID number(3) constraint student_StdID_PK primary key, StdFN varchar2(10), StdLN varchar2(15), StdCity varchar2(15), StdState char(2), StdZip number(5), StdMajor varchar2(4), StdClass char(2), StdGPA number(2,1), StdBalance NUMBER (12,2)); --create a table for courses and their descriptions CREATE TABLE course(CourseNo varchar2(8) constraint course_courseNo_PK primary key, CrsDesc varchar2(40), CrsCredits number(1)); --create faculty table CREATE TABLE Faculty(FacID number(4) constraint faculty_FacID_PK primary key, FacFN varchar2(10), FacLN varchar2(15), FacDept varchar2(4), FacRank varchar2(4), FacHireDate date, FacSalary number(6), FacSupervisor number(4)); --create table for offered courses CREATE TABLE Offering(OfferNo number(4) constraint offering_OfferNo_PK primary key, CourseNo varchar(8)constraint offering_crs_no references course(courseno), OffTerm varchar2(6), OffYear number(4), OffLoca varchar(6), OffTime varchar(8), OffDay varchar(5), FacSSN number(4)constraint offering_fac_FK references faculty(facID)); --create table for student enrollment CREATE TABLE enrollment(StdID number(3), OfferNo number(4), EnrGrade char(2), constraint enrollment_PK primary key (StdID,OfferNo), constraint enrollment_std_ID foreign key(StdID) references student(stdID), constraint enrollment_class_ID foreign key(offerno) references offering(offerno)); CREATE OR REPLACE TRIGGER UNPAID_BALANCE BEFORE INSERT ON STUDENT FOR EACH ROW DECLARE BAL NUMBER; BEGIN BAL := :NEW.STDBALANCE; IF BAL > 500 THEN RAISE_APPLICATION_ERROR(-20001, 'Your balance is too high to register. Please pay to continue.'); END IF; END; / CREATE OR REPLACE TRIGGER ENROLL_MAX BEFORE INSERT ON ENROLLMENT FOR EACH ROW DECLARE NOFSTUDENTS BINARY_INTEGER; BEGIN SELECT COUNT(*) INTO NOFSTUDENTS FROM ENROLLMENT WHERE OFFERNO = :NEW.OFFERNO AND ENRGRADE IS NULL; DBMS_OUTPUT.PUT_LINE(NOFSTUDENTS); IF (NOFSTUDENTS + 1) > 2 THEN RAISE_APPLICATION_ERROR(-20003, 'EXCEED MAX NO OF STUDENTS ALLOWED'); END IF; END; / --populate student table INSERT INTO student values(101,'Joe','Smith','Eau Clare','WI',18121,'IS','FR',3.8,225.25); INSERT INTO student values(102, 'Rob','King', 'Melrose', 'MN', 56352, 'IS','JR',3.2,120.98); INSERT INTO student values(103, 'Dan','Robinson', 'Sartell', 'MN', 98042, 'IS','JR',3.6, 36); INSERT INTO student values(104,'Sue','Williams','St.Cloud','MN',56301,'ACCT','SR',3.2,2386.55); INSERT INTO student values(105,'Don','Robinson','St.Paul','MN',55103,'MKTG','SR',3.4, 306); --populate course table INSERT INTO Course values('CSCI 200','Elements of Computing',3); INSERT INTO Course values('IS 250','Application of Program Dev. I',3); INSERT INTO Course values('IS 251','Application of Program Dev. II',3); INSERT INTO Course values('IS 454', 'Data Mining for Decision Support',3); INSERT INTO Course values('IS 356','Systems Analysis and Design I',3); INSERT INTO Course values('IS 460', 'Project Management',3); INSERT INTO Course Values('ACCT 291','Accounting Principles II',3); INSERT INTO Course values('IS 443','Database Design',3); --populate faculty table INSERT INTO faculty values(9001,'Leonard','Vince','IS','ASST','12-Apr-1997',67000,9003); INSERT INTO faculty values(9002,'Victor','Strong','CSCI','ASSO','8-Aug-1999',70000,9003); INSERT INTO faculty values(9003,'Nicki','Colan','IS','PROF','20-Aug-1981',75000,9010); INSERT INTO faculty values(9004,'Fred','Wells','ACCT','ASST','28-Aug-1996',60000,9010); INSERT INTO faculty values(9010,'Chris','Macon','ACCT','ASST','4-Aug-1980',75000,Null); --populate offering table INSERT INTO offering values(2201,'CSCI 200','Spring',2017,'ECC135','10:30AM','MWF',9002); INSERT INTO offering values(2202,'CSCI 200','Spring',2017,'ECC135','8:00AM','MWF',9002); INSERT INTO offering values(1102,'ACCT 291','Spring',2017,'CH 14A','2:00AM','MWF',9004); INSERT INTO offering values(2203,'IS 356','Fall',2017,'CH494','3:30AM','TTH',9001); INSERT INTO offering values(2204,'IS 251','Fall',2017,'CH494','12:30AM','TTH',9003); INSERT INTO offering values(1101,'ACCT 291','Fall',2017,'CH350','12:30AM','TTH',9010); INSERT INTO offering values(2205,'IS 443','Fall',2017,'CH494','9:30AM','MWF',9003); --populate enrollment table INSERT INTO enrollment values(101,2201,'A'); INSERT INTO enrollment values(102,2202,'B'); INSERT INTO enrollment values(102,2203,null); INSERT INTO enrollment values(103,2203,null); INSERT INTO enrollment values(103,2201,'C'); INSERT INTO enrollment values(103,1101,null); INSERT INTO enrollment values(104,2202,'A'); INSERT INTO enrollment values(101,2203,null); INSERT INTO enrollment values(101,1101,null); INSERT INTO enrollment values(101,2205,null); INSERT INTO enrollment values(102,2205,null); INSERT INTO enrollment values(104,2205,null); Is there a way I can make this look cleaner/better in the script output section because one specific case is this error message that pops up because of the raise application error. Error starting at line : 129 in command - INSERT INTO enrollment values(104,2202,'A') Error report - ORA-02291: integrity constraint (ADMIN_BF.ENROLLMENT_STD_ID) violated - parent key not found
The error that you are facing is clear enough. There is not student 104 in the table, so you cannot create a dependent record in enrollment. This error is not related to your triggers, but to your data. Now let's look at the insert statement for that particular user: INSERT INTO student values(104,'Sue','Williams','St.Cloud','MN',56301,'ACCT','SR',3.2,2386.55); You are attempting to input a balance of 2386.55. But your trigger UNPAID_BALANCE prevents balances that are above 500, so that insert raises application error "Your balance is too high to register", which is the root cause of the problem. You need to fix that insert. Side note: there is another problem lurking in the last series of inserts into enrollments. Trigger ENROLL_MAX allows only two students per OFFERNO, but you are attempting to assign three students to offer 2203, and three as well to offer 2205. This will raise application error "EXCEED MAX NO OF STUDENTS ALLOWED".
oracle apex giving me an error when using INSERT INTO to add data to tables
I have an assignment due in a few days but cannot remember coming across this error before, im sure its something tiny that ive skimmed over but could someone take a look? error is : ORA-00984: column not allowed here ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_190100", line 590 ORA-06512: at "SYS.DBMS_SYS_SQL", line 1658 ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_190100", line 576 ORA-06512: at "APEX_190100.WWV_FLOW_DYNAMIC_EXEC", line 2033 ive tried rewriting single lines but it will not take any code that i put into it. The code i have written is in asterisks (bottom 14 lines) it works fine without these lines so i cannot figure out why. Im a newbie to this kind of stuff (first year uni) so any help would be appreciated! CREATE TABLE vet( vetno NUMBER(6) PRIMARY KEY, vetname VARCHAR2(16) NOT NULL, vetaddressln1 VARCHAR2(20)NOT NULL, vetaddressln2 VARCHAR2(20), vetpostcode VARCHAR2(8)NOT NULL); DROP TABLE client cascade constraints; CREATE TABLE client( clientno NUMBER(6)PRIMARY KEY, surname VARCHAR2(15)NOT NULL, firstnames VARCHAR2(15)NOT NULL, clientaddressln1 VARCHAR2(20)NOT NULL, clientaddressln2 VARCHAR2(20), clientpostcode VARCHAR2(8)NOT NULL); DROP TABLE animal cascade constraints; CREATE TABLE animal( animalno NUMBER(6) PRIMARY KEY, name VARCHAR2(15)NOT NULL , sex VARCHAR2(6), dateofbirth DATE, species VARCHAR2(30)NOT NULL , clientno NUMBER(6) REFERENCES client(clientno)); DROP TABLE consultation cascade constraints; CREATE TABLE consultation( consultationno NUMBER(6), consultationdate DATE NOT NULL, animalno NUMBER(6) REFERENCES animal(animalno), vetno NUMBER(6) REFERENCES vet(vetno), Outcomenote VARCHAR2(25) NOT NULL ); INSERT INTO vet VALUES (001,'James Herriot','Skeldale, High St', 'Yarm', 'YM3 6WP'); INSERT INTO vet VALUES (002,'Siegfried Farnon','61 Farnby Mount', 'Yarm', 'YM3 6WD'); INSERT INTO vet VALUES (003,'Danielle Chang','North St', 'Leeds', 'LS6 3NG'); INSERT INTO vet VALUES (004,'Emma Milne','87 Arncliffe Road', 'Harrogate', 'HG5 5HY'); INSERT INTO vet VALUES (005,'Harry Cooper','15, Coniston Avenue', 'Leeds', 'LS11 4PE'); INSERT INTO client VALUES (0034,'Wong','Judy','Flat 5, Victoria Av', 'Leeds', 'LS5 9PL'); INSERT INTO client VALUES (0035,'Spencer','Tom','4, Broad Lane', 'Harrogate', 'HG4 9DL'); INSERT INTO client VALUES (0036,'Hamza','Farhan','35A, Waterloo Cres', 'Harrogate', 'HG3 3FD'); INSERT INTO client VALUES (0037,'Cummins','Dominic','184, Queenswood Rd', 'Bradford', 'BR3 2GD'); INSERT INTO client VALUES (0038,'Stuart','Moira','77, Westgate', 'Leeds', 'LS1 4KL'); ** INSERT INTO animal VALUES (00100,'Elsie','M', 01-FEB-13, 'PERSIAN CAT', '0034'); INSERT INTO animal VALUES (00101,'Thurston','M', 15-MAY-11, 'MAINE COON CAT', '0034'); INSERT INTO animal VALUES (00102,'Jeff','F', 11-SEP-19, 'NORWEIGAN FOREST CAT', '0035'); INSERT INTO animal VALUES (00103,'Monkey','M', 16-SEP-99, 'BOMBAY CAT', '0036'); INSERT INTO animal VALUES (00104,'Terry','M', 11-MAY-14, 'RED-FOOTED TORTOISE', '0037'); INSERT INTO animal VALUES (00105,'Emilia','F', 29-OCT-19, 'RED-KNEE TARANTULA', '0038'); INSERT INTO consultation VALUES (001001,14-jan-20,'00101','001','Given antibiotics'); INSERT INTO consultation VALUES (001002,11-JUL-20,'00101','002','Given respiratory tablets'); INSERT INTO consultation VALUES (001003,08-JUN-20,'00102','003','Given antibiotics'); INSERT INTO consultation VALUES (001004,11-AUG-20,'00103','005','Saline Drip'); INSERT INTO consultation VALUES (001005,11-SEP-20,'00104','001','Laid 3 eggs'); INSERT INTO consultation VALUES (001006,17-NOV-20,'00102','004','Given antibiotics'); INSERT INTO consultation VALUES (001007,11-DEC-20,'00105','004','Moult Assistance'); INSERT INTO consultation VALUES (001008,04-OCT-20,'00101','005','Given antibiotics');** ```
It is about invalid dates. The way you tried to do it is wrong - not just because it didn't work, but because you wanted to insert them as strings (only if they were enclosed into single quotes). You should insert dates. One option is to use date literal which is always in format date 'yyyy-mm-dd': SQL> INSERT INTO animal VALUES (00100,'Elsie','M', date '2013-02-01', 'PERSIAN CAT', '0034'); 1 row created. SQL> Another is to use TO_DATE function with appropriate format mask: SQL> INSERT INTO animal VALUES (00101,'Thurston','M', to_date('15-MAY-11', 'dd-mon-yy', 'nls_date_language = english'), 'MAINE COON CAT', '0034'); 1 row created. SQL> The same goes for the consultation table.
How to add time query in Oracle?
CREATE TABLE Appointment ( appointID INTEGER, appoint_date DATE, appoint_time TIME, appoint_type VARCHAR(5), primary key (appointID) ); INSERT INTO Appointment VALUES(1, '15-Apr-2017', '10:00', 'long'); INSERT INTO Appointment VALUES(2, '15-Apr-2017', '10:30', 'short'); INSERT INTO Appointment VALUES(3, '28-May-2017', '14:00', 'long'); INSERT INTO Appointment VALUES(4, '20-May-2017', '15:00', 'short'); INSERT INTO Appointment VALUES(5, '11-May-2017', '10:30', 'long'); INSERT INTO Appointment VALUES(6, '26-Jun-2017', '9:30', 'short'); INSERT INTO Appointment VALUES(7, '30-Jun-2017', '14:00', 'long'); INSERT INTO Appointment VALUES(8, '30-Jun-2017', '15:30', 'short'); INSERT INTO Appointment VALUES(9, '28-Apr-2017', '16:00', 'short'); INSERT INTO Appointment VALUES(10,'30-Apr-2017', '13:00', 'short'); I keep getting this error when I try to add TIME: Error starting at line : 24 in command - CREATE TABLE Appointment( appointID INTEGER, appoint_date DATE, appoint_time TIME, appoint_type VARCHAR(5), primary key (appointID) ) Error report - ORA-00902: invalid datatype 00902. 00000 - "invalid datatype" *Cause: *Action: I'm also trying to add my DOCTOR TABLE, but I keep getting a Error report ORA-00907: missing right parenthesis 00907. 00000 - "missing right parenthesis" *Cause: *Action:** create table Doctor ( appointID INTEGER not null, regnum CHAR(6), doc_name VARCHAR(40), doc_gender CHAR(1), qual VARCHAR(80), foreign key (appointID) references Appointment primary key (appointID, regnum) );
Here's my suggestion: avoid CHAR datatype unless it makes sense (such as in gender, as you did), as well as VARCHAR >>> use VARCHAR2 instead (personally, I never use CHAR, and have never ever used VARCHAR). DATE datatype contains both date and time component, so you're safe if you use it. Columns that make the primary key constraint don't have to have the NOT NULL constraint specified, because primary keys don't allow nulls anyway. So, here it is, a working example: SQL> create table appointment 2 (appointid integer constraint pk_app primary key, 3 appoint_date date, 4 appoint_type varchar2(5) 5 ); Table created. SQL> SQL> insert into appointment values 2 (1, to_date('15.04.2017 10:00', 'dd.mm.yyyy hh24:mi'), 'long'); 1 row created. SQL> SQL> create table doctor 2 (appointid integer constraint fk_doc_app references appointment (appointid), 3 regnum varchar2(6), 4 doc_name varchar2(40), 5 doc_gender char(1), 6 qual varchar2(80), 7 -- 8 constraint pk_doc primary key (appointid, regnum) 9 ); Table created. SQL>
There is no data type called 'TIME', you can use timestamp : CREATE TABLE Appointment ( appointID INT, appoint_date DATE, appoint_time timestamp , appoint_type VARCHAR(5), primary key (appointID) ); For insert you have to use TO_DATE and TO_TIMESTAMP functions, as what you are inserting is string.: INSERT INTO Appointment VALUES(3, To_date('15-Apr-2017','DD-MON-YY'), TO_TIMESTAMP('10:00','HH24:MI'), 'long'); http://sqlfiddle.com/#!4/59f5ef
Schema "tmp" doesn't exist inside SQL generated dump file?
I'm trying to import my SQL dump to psql but there is a problem (as mentioned in the title). I'm not to sure why this happens, and what to do against it. This is the command I am using psql -U postgres -d app -1 -f postgres.sql This is the error in cmd C:\Users\Admin\Documents> psql -U postgres -d app -1 -f postgres.sql Password for user postgres: psql:postgres.sql:3: ERROR: schema "tmp" does not exist and this is my SQL file DROP SCHEMA tmp CASCADE; CREATE SCHEMA tmp ; SET search_path=tmp; CREATE TABLE users ( id INTEGER NOT NULL, email VARCHAR(120), PRIMARY KEY (id), UNIQUE (email) ); INSERT INTO users VALUES(1,'KimFake1#outlook.com'); INSERT INTO users VALUES(2,'osman.narnia#live.co.uk'); INSERT INTO users VALUES(3,'KimFake1#outlook.com'); INSERT INTO users VALUES(4,'jaakume#gmail.com'); INSERT INTO users VALUES(5,'omarblack#protonmail.com'); INSERT INTO users VALUES(6,'osman.everton#hotmail.com'); INSERT INTO users VALUES(7,'radoslaw#ganczarek.in'); INSERT INTO users VALUES(8,'kane1001#live.co.uk'); INSERT INTO users VALUES(9,'osman.soloking009#outlook.com'); INSERT INTO users VALUES(10,'Shum1945#fleckens.hu'); CREATE TABLE raffle ( id INTEGER NOT NULL, user_id INTEGER, colour VARCHAR(120), up1 VARCHAR(4), up2 VARCHAR(4), PRIMARY KEY (id), CONSTRAINT _color_up1_up2_uc UNIQUE (colour, up1, up2), FOREIGN KEY(user_id) REFERENCES users (id) ); INSERT INTO raffle VALUES(1,1,'Blue','7c4c','5c7e'); INSERT INTO raffle VALUES(2,1,'Pink','635d','853f'); INSERT INTO raffle VALUES(3,1,'Plum','5e80','7611'); INSERT INTO raffle VALUES(4,1,'Aqua','937c','1b75'); INSERT INTO raffle VALUES(5,2,'Navy','1d9a','8914'); INSERT INTO raffle VALUES(6,1,'Grey','d869','fc97'); INSERT INTO raffle VALUES(7,4,'Rose','5fee','b31f'); INSERT INTO raffle VALUES(8,1,'Ruby','d5b4','e749'); INSERT INTO raffle VALUES(9,2,'Teal','cf0b','3bf5'); INSERT INTO raffle VALUES(10,1,'Gold','98a7','3079'); INSERT INTO raffle VALUES(11,1,'Jade','5c69','66f8'); INSERT INTO raffle VALUES(12,1,'Lime','156f','6b34'); INSERT INTO raffle VALUES(13,1,'Blue','7da3','d95b'); INSERT INTO raffle VALUES(14,1,'Pink','a63e','b9b6'); INSERT INTO raffle VALUES(15,1,'Plum','d989','71a5'); INSERT INTO raffle VALUES(16,1,'Aqua','7372','0682'); /**** INSERT INTO raffle VALUES(17,9,'Navy','01b3','e444'); INSERT INTO raffle VALUES(18,1,'Grey','d679','0123'); INSERT INTO raffle VALUES(19,1,'Rose','5963','692d'); ... ***/ COMMIT;
ORA-00942: table or view does not exist when trying to use constraints
I have been trying to create a table using constraints because that is what our professor wants ous to do. However, when I do so I get a ton of errors when before I had none. My code looks like the following: DROP TABLE movie CASCADE CONSTRAINTS; CREATE TABLE movie( movie_id NUMBER(5), title VARCHAR2(45) NOT NULL, description VARCHAR2(250) NOT NULL, released_by NUMBER(3) NOT NULL, released_on DATE NOT NULL constraint movie_pk primary key (movie_id)); INSERT INTO movie (movie_id, title, description, released_by, released_on)VALUES ('1', 'Edge of Tomorrow', 'Lieutenant Colonel Bill Cage is a skilled tactician who has honed his abilities through his experiences as a soldier. However, there is still much he can learn, and soon he is going to get his chance.', '1', '07-OCT-2014'); INSERT INTO movie (movie_id, title, description, released_by, released_on)VALUES('2', 'Captain America: Winter Soldier', 'Steve Rogers is finding it difficult to adjust to living life in the contemporary world. He is working for S.H.I.E.L.D. and begins to suspect a mystery is brewing there.', '2', '09-SEP-2014'); INSERT INTO movie (movie_id, title, description, released_by, released_on)VALUES('3', 'Fed Up', 'America’s problem with obesity is caused by our inactivity. Or is it? Katie Couric and Stephanie Soechtig tempt us to restructure our beliefs about the American diet, through this thought-provoking expose.', '3', '09-SEP-2014'); INSERT INTO movie (movie_id, title, description, released_by, released_on)VALUES('4', 'Godzilla', 'The legendary tale of Godzilla comes roaring back to life. This time, its the modern era, and Godzilla is a giant lizard who has been made fearsome through the interference of radiation.', '1', '16-SEP-2014'); INSERT INTO movie (movie_id, title, description, released_by, released_on)VALUES('5', 'Neighbors', 'New parents Mac and Kelly settle into domesticity in a quiet neighborhood. The tranquility they have been afforded ceases to exist when a fraternity moves into the house next door.', '2', '14-SEP-2014'); COMMIT; The out put from me running this code in Oracle is as follows: SQL> #test.sql DROP TABLE movie CASCADE CONSTRAINTS * ERROR at line 1: ORA-00942: table or view does not exist constraint movie_pk primary key (movie_id)) * ERROR at line 7: ORA-00907: missing right parenthesis INSERT INTO movie (movie_id, title, description, released_by, released_on)VALUES ('1', 'Edge of Tomorrow', 'Lieutenant Colonel Bill Cage is a skilled tactician who has honed his abilities through his experiences as a soldier. However, there is still much he can learn, and soon he is going to get his chance.', '1', '07-OCT-2014') * ERROR at line 1: ORA-00942: table or view does not exist INSERT INTO movie (movie_id, title, description, released_by, released_on)VALUES('2', 'Captain America: Winter Soldier', 'Steve Rogers is finding it difficult to adjust to living life in the contemporary world. He is working for S.H.I.E.L.D. and begins to suspect a mystery is brewing there.', '2', '09-SEP-2014') * ERROR at line 1: ORA-00942: table or view does not exist INSERT INTO movie (movie_id, title, description, released_by, released_on)VALUES('3', 'Fed Up', 'Americas problem with obesity is caused by our inactivity. Or is it? Katie Couric and Stephanie Soechtig tempt us to restructure our beliefs about the American diet, through this thought-provoking expose.', '3', '09-SEP-2014') * ERROR at line 1: ORA-00942: table or view does not exist INSERT INTO movie (movie_id, title, description, released_by, released_on)VALUES('4', 'Godzilla', 'The legendary tale of Godzilla comes roaring back to life. This time, its the modern era, and Godzilla is a giant lizard who has been made fearsome through the interference of radiation.', '1', '16-SEP-2014') * ERROR at line 1: ORA-00942: table or view does not exist INSERT INTO movie (movie_id, title, description, released_by, released_on)VALUES('5', 'Neighbors', 'New parents Mac and Kelly settle into domesticity in a quiet neighborhood. The tranquility they have been afforded ceases to exist when a fraternity moves into the house next door.', '2', '14-SEP-2014') * ERROR at line 1: ORA-00942: table or view does not exist Commit complete. As you can see there are multiple errors within this code just from me adding constraints. Any help would be appreciated.
Missing a comma: released_on DATE NOT NULL, ^ constraint movie_pk primary key (movie_id));