I have a table called "instructors" that has columns "name", "dept_name", "salary"
I'm trying to create a procedure that takes a department name (dept_name) for IN and returns the highest and lowest salaries in that department as two OUTs.
DELIMITER //
create procedure min_max(in dept_name_ varchar(20),
out max_salary numeric(12,2),
out min_salary numeric(12,2))
BEGIN
select max(salary) into max_salary,
from instructor
where instructor.dept_name = min_max.dept_name_;
select min(salary) into min_salary,
from instructor
where instructor.dept_name = min_max.dept_name_;
END//
DELIMITER ;
I am getting this error:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'from instructor
where instructor.dept_name = min_max.dept_name_;
' at line 6
I've gone through the procedure a couple times, I cannot figure out what might be causing the error.
Related
I wanna make tringger, so after inserting data, the datas ordered by date (here name 'tanggal')
but got error #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'ORDER BY tanggal ASC;
END' at line 5
DELIMITER $$
CREATE TRIGGER sort_by_tanggal
AFTER INSERT ON laporan_bukubesar
FOR EACH ROW
BEGIN
ALTER TABLE laporan_bukubesar ORDER BY tanggal ASC;
END $$
DELIMITER ;
create procedure checkin_customerid(in customer_id int)
if (select c.customerID from customer_detail c
where customer_id = c.customerID)
then
insert into customer_checkin (customerID)
values (customer_id);
I am trying to create this procedure in MySQL that should:
check if there is a match for the customerID in the table customer_details and
if true, should add the customer_id in the table customer_checkin.
But I am getting an error on the last line: values (customer_id); which says:
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4
Hovering over code error says: Statement incomplete, expecting a ';'
The bracket on the last line for (customer_id) is underlined.
How can I tackle this problem?
Try this. You have a missing END IF;
And i would rewrite the if clause to EXISTS
CREATE PROCEDURE checkin_customerid(in customer_id int)
BEGIN
if (EXISTS(select c.customerID from customer_detail c
where customer_id = c.customerID))
then
insert into customer_checkin (customerID)
values (customer_id);
END IF;
END
But Oiliver is right only for the insert the if clause is not necessary
I am getting this error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'if (t=null) then update employee set grade='x' where empid=id; END' at line 4
I am not able to understand where the syntax is wrong.
I am creating a procedure to get a grade from the table if it grade is present. If it is not present then it should be updated as x.
CREATE PROCEDURE spGETgrade (in id int)
BEGIN
select grade as t from employee where empid=id
if (t=null) then
update employee set grade='x' where empid=id;
END $$
I think you need ";" after the first query
select grade as t from employee where empid=id; <<---
and
IF THEN
...
END IF; <<--
Here is the code:
CREATE PROCEDURE CountOrderByStatus(
IN orderStatus VARCHAR(25),
OUT total INT)
BEGIN
SELECT count(orderNumber)
INTO total
FROM orders
WHERE status = orderStatus;
END
When I try to execute this, i get the following error:
Error SQL (1064): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near '' at line 8
I was googling for a while, but I can't find any information about this problem. Many sources does not refer such type of code as invalid. For example, fragment above found at this site.
Any ideas, why everybody is saying, that is normal, but MySQL produces such strange error?
P.S.: MySQL Server 5.6 at Windows 8.1.
Was forget to add DELIMITER. It must look:
DELIMITER $$
CREATE PROCEDURE CountOrderByStatus(
IN orderStatus VARCHAR(25),
OUT total INT)
BEGIN
SELECT count(orderNumber)
INTO total
FROM orders
WHERE status = orderStatus;
END$$
DELIMITER ;
Someone tell where there is a bug?
CREATE PROCEDURE catalog_get_departments_list()
BEGIN
SELECT department_id, name FROM department ORDER BY department_id;
END$$
And this error crashes:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3
I think you should remove dollars at the end:
CREATE PROCEDURE catalog_get_departments_list()
BEGIN
SELECT department_id, name FROM department ORDER BY department_id;
END
or set delimiter
DELIMITER $$
CREATE PROCEDURE catalog_get_departments_list()
BEGIN
SELECT department_id, name FROM department ORDER BY department_id;
END$$
One more variant for your MySQL client -
CREATE PROCEDURE catalog_get_departments_list()
SELECT department_id, name FROM department ORDER BY department_id;