Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, Can i know is this the correct way to declare using MySQL? Because i keep hitting error which state that I have an error in your SQL syntax;

What I have tried:

<pre>CREATE DEFINER = 'root'@'localhost'
PROCEDURE db.Hello( )
 
BEGIN
DECLARE @Text VARCHAR(MAX);


SET @Text = 'hello';
  END
Posted
Updated 23-Jul-20 0:53am
v2
Comments
Garth J Lancaster 23-Jul-20 6:22am    
I think VARCHAR(MAX) is a MS SQL Server declaration - try
DECLARE @Text VARCHAR(65535);
as a replacement

1 solution

As shared by Garth in comments, VARCHAR(MAX) is SQL Server way.

For MySQL: Refer: MySQL :: MySQL 8.0 Reference Manual :: 11.3.2 The CHAR and VARCHAR Types[^]

How to declare in MySQL:
SQL
DECLARE variable_name datatype(size) [DEFAULT default_value];

Quote:
Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 65,535. The effective maximum length of a VARCHAR is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used. See Section 8.4.7, “Limits on Table Column Count and Row Size”.

In contrast to CHAR, VARCHAR values are stored as a 1-byte or 2-byte length prefix plus data. The length prefix indicates the number of bytes in the value. A column uses one length byte if values require no more than 255 bytes, two length bytes if values may require more than 255 bytes.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900