日期:2014-05-16 浏览次数:20935 次
Declare @sql varchar(8000) Set @sql = 'select ' Select @sql = @sql + Subject+',' from (select distinct Subject from cj) as cj Set @sql=SubString(@sql,1,len(@sql)-1) Select @sql = @sql+' from table3' Exec (@sql)
declare tsql varchar2(8000); begin tsql := ' select '; select (tsql || Subject || ',') into tsql from (select distinct Subject from cj) as cj; tsql := substr(tsql,1,Length(tsql)-1); tsql := tsql || ' from table3'; execute immediate tsql; end;
------解决方案--------------------
declare tsql varchar2(8000); begin tsql := ' select '; select (tsql || Subject || ',') into tsql from (select distinct Subject from cj) as cj; tsql := substr(tsql,1,Length(tsql)-1); tsql := tsql || ' from table3'; execute immediate tsql; end;