I wrote a stored procedure (sp_archivev3) on MySQl Workbench which is as follows. Basically, Inserting values from one database to another.
-- --------------------------------------------------------------------------------
-- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- --------------------------------------------------------------------------------
DELIMITER $$
CREATE DEFINER=`MailMe`@`%` PROCEDURE `sp_archivev3`()
BEGIN
INSERT INTO
send.sgev3_archive(a_bi,
b_vc,
c_int,
d_int,
e_vc,
f_vc,
g_vc,
h_vc,
i_dt,
j_vc,
k_vc,
l_vc,
m_dt,
n_vch,
o_bit)
SELECT a_bi,
b_vc,
c_int,
d_int,
e_vc,
f_vc,
g_vc,
h_vc,
i_dt,
j_vc,
k_vc,
l_vc,
m_dt,
n_vch,
o_bit
FROM send.sgev3
WHERE m_dt BETWEEN '2014-06-09' AND CURDATE();
END
When I run call sp_archivev3();
, I get an error with an error code 1046: No database
selected SELECT the default DB to be used by double-clicking its name in the SCHEMAS list in the sidebar.
Please let me know what's wrong with my stored procedure.
Now, we can choose any database. Suppose I am using the database 'business', therefore we can choose with the help of 'use' command. After using database 'business', we can create the above table and we will not get any error.
You need to replace [database_name] with the name of a database that exists in your MySQL server. You can also list the names of all databases available on your server with the SHOW DATABASES command. The error should be resolved once mysql responds with Database changed as shown above.
Error 1046 occurs when we miss to connect our table with a database. In this case, we don't have any database and that's why at first we will create a new database and then will instruct to use that database for the created table.
The problem is that MySQL doesn't know which procedure named sp_archivev3
is supposed to be executed; MySQL doesn't know which database to look in. (Stored programs are objects in a specific database, just like tables are objects in a specific database.)
Either specify the current database with USE
statement:
use mydatabase;
call sp_archivev3();
or qualify the procedure with the name of database:
call mydatabase.sp_archivev3();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With