executeSQLScript maximum allowable character vector length error

1 回表示 (過去 30 日間)
Emmanouil
Emmanouil 2020 年 1 月 15 日
回答済み: Piyush Kumar 2024 年 10 月 28 日
I am trying to run an sql script which has approximately 2,000 lines and approximately 100,000 characters with the executeSQLScript function
executeSQLScript( DB_conn , "script_name.sql" )
and i get the error
Error while executing the SQL script: SQL script exceeds maximum allowable character vector length.
Is there a way to increase the allowed character vector length for sql script that can be run using executeSQLScript ?
Thanks,

回答 (1 件)

Piyush Kumar
Piyush Kumar 2024 年 10 月 28 日
Hi,
The error you're encountering is due to a limitation in the executeSQLScript function, which cannot process SQL scripts exceeding 25,000 characters. To work around this, you can read and execute the SQL statements in smaller chunks -
% Open the SQL file
fid = fopen('script_name.sql', 'r');
% Connect to the database (replace with your actual database details)
conn = database('', 'username', 'password', 'Vendor', 'MySQL', 'Server', 'localhost', 'PortNumber', 3306);
% Read and execute each SQL statement line-by-line
while ~feof(fid)
% Read a line from the file
sqlStatement = fgetl(fid);
% Execute the SQL statement if it's a valid string
if ischar(sqlStatement) && ~isempty(sqlStatement)
exec(conn, sqlStatement);
end
end
% Close the file and the database connection
fclose(fid);
close(conn);
This script processes each line individually, which might not work if your SQL statements span multiple lines. You may need to adjust the logic to handle multi-line statements if necessary.

カテゴリ

Help Center および File ExchangeDatabase Toolbox についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by