展开全部
以下只是个例子
CREATE procedure test
@n1 char(10),
@n2 char(10),
@n3 char(10),
@n4 char(10),
@n5 char(10),
@n6 char(10),
@n7 char(10),
@n8 datetime,
@n9 datetime,
@n10 int
as
select * --------这部分请将传入的参数带入查询的条件中
from table1 t1,table2 t2,table3 t3
where deldate between @n8 and @n9
and t1.ponum = t2.ponum
and t2.partnum = t3.partnum
and t3.layer =@n1
GO
CREATE procedure test
@n1 char(10),
@n2 char(10),
@n3 char(10),
@n4 char(10),
@n5 char(10),
@n6 char(10),
@n7 char(10),
@n8 datetime,
@n9 datetime,
@n10 int
as
select * --------这部分请将传入的参数带入查询的条件中
from table1 t1,table2 t2,table3 t3
where deldate between @n8 and @n9
and t1.ponum = t2.ponum
and t2.partnum = t3.partnum
and t3.layer =@n1
GO
追问
谢谢你的回答,我是想用php调用,如何实现。比如你写的这个存储过程。入参在call里怎么写?每个参数都是必须的吗?还有出参?
$n1 = " ";
$n2 = " ";
$n3= " ";.....
$sql = "CALL test ('$n1','$n2','$n3',.......')" ;
$link = mysql_connect("localhost", "root", "123456")
$result = mysql_query("db", $sql, $link);
while($row = mysql_fetch_assoc($result));
{
echo ‘..........查询的字段
}
追答
可以在执行CALL test ($n1,$n2,$n3,.......)之前对几个参数进行赋值,就像$n1 = " ";这就是入参,
$result = mysql_query("db", $sql, $link);这句执行完就会出参
参数是否必须要看你存储过程的内容里的定义,有时某个参数不影响存储过程的定义就可以不赋值
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询