MySQL从另一个存储过程调用存储过程

发布于 2024-10-01 06:10:58 字数 1364 浏览 0 评论 0原文

抱歉,帖子很长: 我是否可以从另一个地方调用存储过程 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

望笑 2024-10-08 06:10:58

您无法加入存储过程,也许使用视图可能更合适?

you can't join onto a stored procedure, perhaps using views might be more suitable ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文