我有一个表,其中包含一些数据,例如 id、Name 、Forid
现在我想获取单个变量中的所有名称,像这样 a,b,c
但它的 forid 是匹配的
例如:-
Id Name forid
1 a 1
2 b 1
3 c 2
当 forid 为 1 时 sp 将返回 a,b
如果有sql函数就可以了,但是如何实现这个请指导我
最佳答案
使用类似的东西。这是 Oracle 中的过程,但在 SQL Server 中我认为您不需要更多更改
create or replace PROCEDURE p (x in number) AS
z table_name.Column_name%TYPE;
result varchar(100):='';
cursor take is select Name from TABLE_NAME where for_id=x;
begin
open take;
loop
fetch take into z;
result:= result|| z;
exit when take%notfound;
end loop;
close take;
dbms_output.put_line(result);
END p;
关于mysql - 如何在 SToredpeocedure 中创建循环并创建 , 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27619574/