复制drop table if exists test; create table test ( id int not null,教何 name varchar(20) not null ); insert into test values(1,test1); insert into test values(1,test11); insert into test values(1,test111); insert into test values(2,test2); insert into test values(2,test22); drop function if exists getSpid; delimiter | CREATE function getSpid() RETURNS int RETURN @spid; | delimiter ; drop view if exists v_test; create view v_test as select * from test where id=getSpid(); -- 测试代码 -- 开启session 1 set @spid=1; select * from v_test; -- 开启session 2 set @spid=2; select * from v_test; 1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.