I am attempting to create a procedure that will allow me to insert values into a table
the code I have is
Create procedure add_instructor
#Name char(40),
#IAccount char(20)
AS
BEGIN
set nocount on
insert into final_instructors (Name, IAccount)
values (#name, #IAccount)
end
go;
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 '#Name char(40), #IAccount char(20)
Related
This is for a trigger I'm creating that responds to inserts on the table groceries
CREATE TABLE grocery_changes (
ID INT NOT NULL AUTO_INCREMENT,
changed_table VARCHAR(255),
date_time DATETIME,
operation CHAR(10) NOT NULL,
PRIMARY KEY(ID)
);
CREATE TRIGGER trg_grocery_audit AFTER INSERT ON groceries
for each ROW BEGIN
INSERT INTO grocery_changes (modified_table, action_date_time, operation) VALUES ('groceries', NOW(), 'INS');
I keep getting this error But I cant figure it out and could really appreciate a second pair of eyes at this point. Thank you
ERROR 1064 (42000): 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 '' at line 3
I am trying to execute a PL/SQL statement in MySQL. but, when I try to create a table it shows a syntax error. I get the following error
CREATE TABLE supplier(supid NUMBER(5) PRIMARY KEY, suppname VARCHAR2(15));
ERROR 1064 (42000): 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 'NUMBER(5) PRIMARY KEY, suppname VARCHAR2(15))' at line 1
full code is as follows:
DROP TABLE supplier;
DROP SEQUENCE practical2_sequence;
*/
CREATE TABLE supplier(supid NUMBER(5) PRIMARY KEY, suppname VARCHAR2(15));
CREATE SEQUENCE practical2_sequence START WITH 1 MAXVALUE 100;
BEGIN
LOOP
INSERT INTO supplier VALUES(practical2_sequence.NEXTVAL, 1);
EXIT WHEN practical2_sequence.CURRVAL >= 100;
END LOOP;
END;
/
SELECT * FROM supplier;
Help me, as I am not that experienced in MySQL.
You seem to be trying to use Oracle syntax with MySQL.
MySQL doesn't have sequences, it uses the AUTO_INCREMENT attribute of the column. When inserting, either assign NULL to the column or leave it out of the column list, and it will get the next value in the sequence.
MySQL doesn't have the NUMBER datatype, it uses INT. It doesn't have VARCHAR2, just VARCHAR.
DECLARE counter INT DEFAULT 0;
DROP TABLE IF EXISTS supplier;
CREATE TABLE supplier(
supid INT(5) PRIMARY KEY AUTO_INCREMENT,
suppname VARCHAR(15)
);
WHILE counter < 100 DO
INSERT INTO supplier (suppname) VALUES('1');
END WHILE;
Note that variable declarations and WHILE loops can only be used inside stored procedures, not as ordinary queries.
Can someone please tell me what exactly is wrong with this MySQL statement?
DROP TABLE IF EXISTS tempdelv6
CREATE TEMPORARY TABLE tempdelv6 (
'despatchmethod' VARCHAR(50),
'tracking' int,
'refCount' int
)
This is the response I get when the above is executed:
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 'CREATE TEMPORARY TABLE tempdelv6 ( 'despatchmethod' VARCHAR(50), 'tr' at line 2
VERSION: 5.7.23-0ubuntu0.16.04.1
Add a semicolon end of the first line. And remove the single quotes
DROP TABLE IF EXISTS tempdelv6;
CREATE TEMPORARY TABLE tempdelv6 (
despatchmethod VARCHAR(50),
tracking int,
refCount int
)
Apart from the missing terminators you are using single quotes instead of backtick'
DROP TABLE IF EXISTS tempdelv6;
CREATE TEMPORARY TABLE tempdelv6(
`despatchmethod` VARCHAR(50),
`tracking` int,
`refCount` int
);
I am using MySQL Workbench 8.0 CE and i'm trying to create a stored procedure to show 2 fields from my table. I am receiving the following error:
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 3
This is my table:
CREATE TABLE student (
id INT PRIMARY KEY,
name VARCHAR(200),
age INT,
final_grade DOUBLE,
sex VARCHAR(1)
)
And this is the procedure:
CREATE PROCEDURE show_name_grade ()
BEGIN
SELECT name,final_grade FROM student;
END
You will need to redefine Delimiter to something else other than ;. At the end, define it back to ;
DELIMITER $$
CREATE PROCEDURE show_name_grade ()
BEGIN
SELECT name,final_grade FROM student;
END $$
DELIMITER ;
I am trying to create a trigger but I am getting a syntax error and I am not really sure why I am.
CREATE TRIGGER Section_Insert AFTER INSERT ON Section
-> FOR EACH ROW BEGIN
-> INSERT INTO Audit(changeTime, tableName, Action) VALUES (NOW(), 'Section', 'INSERT');
ERROR 1064 (42000): 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 '' at line 3
The following may be useful:
DELIMITER //
DROP TRIGGER IF EXISTS `Section_Insert`//
DROP TABLE IF EXISTS `Section`//
CREATE TABLE `Section` (
`changeTime` DATETIME NOT NULL,
`tableName` VARCHAR(64) NOT NULL,
`Action` VARCHAR(64) NOT NULL
)//
CREATE TRIGGER `Section_Insert` AFTER INSERT ON `Section`
FOR EACH ROW
BEGIN
INSERT INTO `Audit`(`changeTime`, `tableName`, `Action`) VALUES (NOW(), 'Section', 'INSERT');
END//
DELIMITER ;