I'm really new to SQL and I must create a stored procedure.
My idea is that I want to type my PaperRoll_ID
and to get the "Worker_ID". Since my PaperRoll_ID
values in the table are from 1 to 500 and my Worker_id
values are from 1500 to 2000, I want to make it so that PaperRoll_ID
is equal to the Worker_id
index, not value by index (I mean, index 1 is the first Worker_id
I added, 2 is the second and so on till 500 (the number of workers)). PaperRoll_ID
is located in the table invoice_Paper
and Worker_id
in the table machine_operator
.
Sorry if it's hard to understand, but I lack a lot of knowledge in SQL, so it's a bit hard for me to express myself.
create or replace PROCEDURE name_worker(pi IN NUMBER, mi OUT NUMBER) IS
BEGIN
Select q.worker_ID2 INTO mi
from invoice_paper z,machine_operator o
where z.PaperRoll_ID=pi AND o.WORKER_ID2 = q.worker_ID2;
END;
The tables are
create Table invoice_paper(
PaperRoll_ID Number(10) constraint ppr_id not null,
Single_Layer Varchar(20) Default 'None in stock',
Double_Layer Varchar(20) Default 'None in stock',
Manufacturer_FactoryID Integer,
primary key(PaperRoll_ID),
Constraint pprid_invoice Foreign key (Manufacturer_FactoryID) References Paper_Factory(Factory_ID)
);
create table machine_operator(
Insurence_ID number(10) constraint in_numb not null,
Worker_ID2 number(10) constraint worka_id not null,
operator_name Varchar(20),
Email Varchar(30),
Primary key (Insurence_ID, Worker_ID2),
Constraint wka_id Foreign key(Worker_ID2) References worker(worker_id)
);