Column not allowed here pl sql - sql

i am trying to create a procedure to add a new sale, but for some reason i am getting an error that says the column not allowed here
Here is the code:
CREATE OR REPLACE PROCEDURE AddSale
(
In_CID customers.CID%Type,
In_EmpID Employees.EmpID%Type,
In_car_num cars.car_num%Type,
In_Pay_M Sales.Pay_method%Type,
In_Payment_duration Sales.Pay_duration%Type,
In_Payment_type Sales.S_type%Type,
In_sh_id Sales.sh_id%Type,
)
IS
number := 0;
Id_sale number;
BEGIN
INSERT INTO Sales(Sales_ID, CID, EmpID, car_num, S_time,
S_type, Pay_method, Pay_duration, sh_id)
VALUES (Sales_ID_Seq.nextval, In_CID, In_EmpID, In_car_num, SYSDATE,
In_Payment_type, In_Payment_M, In_Payment_duration, In_sh_id);
And here is the table definition:
create table Sales
(
Pay_duration number(15),
Car_num number(15),
Sales_ID number(15),
S_type varchar2(15),
CID number(15),
Pay_method varchar2(32),
S_time timestamp,
EmpID number(15),
Sh_id number(15),
discount number(5,3),
Disc_status varchar2(20),
ApprovedBy number(15)
);

I've formatted the code in your request. You will see that proper formatting is a great help when coding.
In your declaration you have:
In_Pay_M
In your insert statement you have:
In_Payment_M
Then, there is a comma too many after your last parameter:
In_sh_id Sales.sh_id%Type,
)

Related

I try to insert query alphanumeric sequence in table but it is not working

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.

PL SQL UPDATE STATEMENT

create table item_stock
( itemcode varchar2(11) not null,
name varchar(27) not null,
des varchar2(30),
pcs number(11),
unit varchar(7),
qty number(11),
stkdate date,
constraint itemcodef_pk primary key(itemcode, name)
);
BEGIN
update table item_stock
set 'item_stock.itemcode' = 'item_stock.itemcode';
END;
Error 103 at line 2, column 14
Encountered the sysmbol "ITEM_STOCK" when expecting one of the following.
Can anybody help me to resolve this error.
This one:
Update item_stock A
Set A.itemcode = item_stock.itemcode;
Note:
The data type of the item_stock.itemcode must be same as A.itemcode.

ORA-00936: missing expression error when inserting values

I spend lot of time searching where i made the mistake but i was unable to find it when its going to insert the last record there is a error message showing "ORA-00936: missing expression" How to solve this please help me
create type pearson_types as object(
name varchar2(50),
sysID char(6)
)NOT FINAL;
create type doctor_types under pearson_types(
regNo char(10),
specialization varchar2(25)
)
create table doctor of doctor_types(
regNo primary key
)
create type hospVisits_types as object(
hosChg float,
vDate varchar2(20),
refDoc REF doctor_types,
docChg float
)
create type hospvisits_tbl_types as table of hospVisits_types
create type phone_arr as VARRAY(3) of char(10)
create type patient_types under pearson_types
(
id char(10),
dob varchar(20),
phone phone_arr,
hospVisits hospvisits_tbl_types
)
create table patients of patient_types(
id primary key
)nested table hospVisits store as Hospital_tables
alter table Hospital_tables add scope for (refDoc) is doctor
insert into doctor values ('Dr.k.perera','D001','1223441234','Gynecologist');
insert into doctor values ('Dr.p.weerasingha','D002','1234421131','Dermatalogist');
insert into doctor values ('Prof .S. Fernando','D003','2342111322','Pediatrician');
insert into doctor values ('Dr.k.Sathgunanathan','D004','2344114344','Pediatrician');
insert into patients values('Sampath Weerasingha','P001','732821122V','23-JAN-73',phone_arr('0332124222'),hospvisits_tbl_types(hospVisits_types(50.00,'24-MAY-06',select ref (a) from doctor a where a.regNo='1223441234',500.00)))
Add parentheses to SELECT statements inside a SQL statement:
insert into patients values(
'Sampath Weerasingha','P001','732821122V','23-JAN-73',phone_arr('0332124222'),
hospvisits_tbl_types(hospVisits_types(50.00,'24-MAY-06',
( -- ADD ME
select ref (a) from doctor a where a.regNo='1223441234'
) -- ADD ME
,500.00))
);

Unable to create trigger in Oracle/iSQL

I made a table student, in which there is an attribute evaluation.
Now i am making a trigger in which i want that if i insert a value of zero in evaluation then a trigger should fire and store some values in audit_table.
here is my code
Create table Student ( Student_Id Number(8,2), Student_Name Varchar2(50), Gender Varchar(8), Telephone_No Number(15), Location Varchar2(200), Education Varchar2(100), Company_name Varchar2(200), No_of_attempt Number(2), Offering_Id Number(3) , EVALUATION NUMBER(2), Primary Key (Student_Id), Constraint fk_Oid Foreign Key (Offering_Id) References Course(Offering_Id) );
And now the audit table code
CREATE TABLE AUDIT_TABLE ( STUD_NAME VARCHAR2(100), COURSE_NAME
VARCHAR2(100), INSTRUCTOR_NAME VARCHAR2(200), EVALUATION NUMBER (2)
);
Now my main question is this my trigger not working
create trigger tr_student
after insert or update on student
for each row
declare
s_name student.student_name%type;
s_eval student.evaluation%type;
s_offr_id student.offering_id%type;
s_course_name student.student_name%type;
s_instr student.student_name%type;
begin
if evaluation == 0;
s_offr_id =(select offering_id from student where evaluation==0);
s_eval =0;
s_name =(select student_name from student where evaluation==0);
s_course_name =(select course_name from course where offering_id==s_offr_id);
s_instr=(select name from instructor where offering_id==s_offr_id);
insert into AUDIT_TABLE values(s_name,s_course,s_instr,s_eval);
end;
Is there some problem with my trigger?
This is not possible:
s_name =(select student_name from student where evaluation==0);
Change it to
select student_name into s_name from student where evaluation = 0;
Note there are two problems. First, you need into to select a value into a variable. Second, the comparison operator in SQL is only a single =.
The same goes for
if evaluation == 0;
..
end;
It should be
if :new.evaluation = 0 then
...
end if;
So there, the you forgot the then and end if, the comparison operator is wrong and you need :new.fieldname to get the value of the field, instead of a local variable.
The assignment operator in PLSQL is :=, so
s_eval =0;
should be changed to
s_eval := 0;
It seems you need to grab the schoolbook again and do some more reading. :)

SQL Oracle Inheritance Relational Database

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