mysql的存储过程的参数,MySQL存储过程中的参数

我想用输入参数创建一个MySQL存储过程(SP).

但是,在编写SP时无法确定参数的数量.

(方案是用户将有多个选项可供选择.所选的选项将构成搜索条件:

select ...

where prod_category = option1 && option2 && option3 &&...

因此,如果某人仅选择option1和option2,则仅发送2个参数.有时可能选择了50个选项,因此必须发送50个参数.)

因此,我有3个问题:

1.我可以使用MySQL存储过程(SP)处理这种情况吗?

2. SP是处理这种情况的专业方法吗?

3.如果SP不是处理这些情况的专业方法,那么还有其他方法可以有效地处理这些搜索吗?搜索是我的应用程序的核心功能.

在此先感谢您的帮助!

解决方法:

MySQL存储过程仅接受固定数量的参数.您可以构建由单个字符串参数定界的参数和值的列表,然后在过程中对其进行处理,或者使用应用程序语言来构建查询.

No, MySQL sprocs accept only a fixed number of arguments. ISO SQL is

somewhat optimised for correct RDBMS logic (unless you were to ask EF

Codd, CJ Date or Fabian Pascal), but in many ways SQL is quite

literal, so if SQL seems to make what you are trying to do very

difficult, it could be that your design needs another look, in this

case aspects of the design that require repeated multiple ad hoc

deletions.

If such deletions are unavoidable, here are three options. First, in

an application language build the delete query to include

comma-delimited string of IDs. Second, pass such a string to an sproc

that PREPAREs the query using such a string. Third, populate a temp

table with the target IDs and write a simple join query that deletes

the joined IDs.

标签:mysql,stored-procedures

来源: https://codeday.me/bug/20191127/2075677.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值