MySQL从另一个存储过程调用存储过程
抱歉,帖子很长: 我是否可以从另一个地方调用存储过程 MySQL 中的存储过程。 例如: 我有两个表(test 和 testcomp): 具有以下结构:
-- 表 test
的表结构
CREATE TABLE IF NOT EXISTS `test` (
`t_id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`t_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
和
-- 表 testcomp
的表结构
CREATE TABLE IF NOT EXISTS `testcomp` (
`c_id` int(11) NOT NULL AUTO_INCREMENT,
`t_id` int(4) NOT NULL,
`place` varchar(255) NOT NULL,
PRIMARY KEY (`c_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
现在我用以下内容填充测试表:
INSERT INTO `test` (`t_id`, `name`) VALUES
(1, 'foo'),
(2, 'bar'),
(3, 'ma');
并用以下内容填充表 testcomp
INSERT INTO `testcomp` (`c_id`, `t_id`, `place`) VALUES
(1, 1, 'gugs'),
(2, 2, 'nyanga'),
(3, 1, 'gugs'),
(4, 3, 'skom');
现在如果我有2 程序:
第一个 QryTestComp:
SELECT t_id, place FROM TestComp
上面的程序相当于查询普通表: 但是第二个 QryTestPlac 调用上述过程:
SELECT * FROM Test INNER JOIN QryTestComp ON Test.t_id = QryTestComp.t_id
出现错误:
它显示错误:1146 (42S01):表“mydb.qrytestcomp”不存在。 它不是一个表,而是一个过程。
请指点一下。
问候,
--Jongi
Sorry for long POST:
Is it possible that I can call a Stored Procedures from another
Stored procedure in MySQL.
For example:
I have two tables (test and testcomp):
With the structures below:
-- Table structure for table test
CREATE TABLE IF NOT EXISTS `test` (
`t_id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`t_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
and
-- Table structure for table testcomp
CREATE TABLE IF NOT EXISTS `testcomp` (
`c_id` int(11) NOT NULL AUTO_INCREMENT,
`t_id` int(4) NOT NULL,
`place` varchar(255) NOT NULL,
PRIMARY KEY (`c_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
Now I populated test table with:
INSERT INTO `test` (`t_id`, `name`) VALUES
(1, 'foo'),
(2, 'bar'),
(3, 'ma');
and table testcomp with:
INSERT INTO `testcomp` (`c_id`, `t_id`, `place`) VALUES
(1, 1, 'gugs'),
(2, 2, 'nyanga'),
(3, 1, 'gugs'),
(4, 3, 'skom');
Now if I have 2 Procedures:
First QryTestComp:
SELECT t_id, place FROM TestComp
The one above works as the just querying normal table:
But the Second One QryTestPlac, which calls the above procedure:
SELECT * FROM Test INNER JOIN QryTestComp ON Test.t_id = QryTestComp.t_id
Comes with a error:
It says Error: 1146 (42S01): Table 'mydb.qrytestcomp' doesn't exist.
It not a table but a procedure.
Pointer, please.
Regards,
--Jongi
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法加入存储过程,也许使用视图可能更合适?
you can't join onto a stored procedure, perhaps using views might be more suitable ?