Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a function with phpMyAdmin [duplicate]

I have trouble creating a function using phpMyAdmin like an interface for MySQL. So I write:

DELIMITER //
Create or Replace Function  affecter (id_patient IN integer , id_maladie IN VARCHAR2 ) 
Return VARCHAR2(30) IS  msg Varchar2(30);
Begin
    Insert into souffrir values (id_patient,id_maladie);
    msg:= 'Insertion effectuée';
    Return msg;
END//

I get this error:

#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 'Function affecter (id_patient IN integer , id_maladie IN VARCHAR2 ) Returns V' at line 1

How do I fix this error?

like image 489
Wassim Sboui Avatar asked May 16 '26 01:05

Wassim Sboui


1 Answers

Try this:

DELIMITER $$
CREATE FUNCTION calcProfit(cost FLOAT, price FLOAT) RETURNS DECIMAL(9,2)
BEGIN
  DECLARE profit DECIMAL(9,2);
  SET profit = price-cost;
  RETURN profit;
END$$
DELIMITER ;

Got it from https://www.a2hosting.com/kb/developer-corner/mysql/mysql-stored-functions-and-procedures

like image 182
Vijay Satluri Avatar answered May 18 '26 13:05

Vijay Satluri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!