Create procedure sp_ConvProc2View
      ( @procName varchar(80),
        @viewName varchar(80))
as
-- -------------------------------------------------------------
-- Procedure name: sp_ConvProc2View 
-- Sp Author : Eli Leiba
-- Date 11-2005
-- Description : created a view with same result as the sp
--  the view can be SELECTed FROM
-- ------------------------------------------------------------
begin 

  declare @TSQLStmt varchar(500)
  set nocount off

  -- create the CREATE VIEW tSQL statement.


  -- An OPENROWSET operator is used on the local server (. means local) 
  -- using SQLOLEDB provider along with a trusted connection (windows authentication)
  --  SET FMTONLY off ensures that the results will be output (not just the metaData) 
  -- the EXEC storedProcedure finishes the OPENROWSET parameter.

  set @TSQLStmt = 'CREATE VIEW ' + @viewName + ' AS SELECT * FROM '   + 
    'OPENROWSET ( ' + '''' + 'SQLOLEDB' + '''' + ','   + 
    '''' +  'SERVER=.;Trusted_Connection=yes' + '''' + ',' + 
    '''' + 'SET FMTONLY OFF EXEC ' + @procName + '''' + ')'
    
  -- now , we dynamically execute the statement
  exec (@TSQLStmt)

  set nocount on 
end 
go


exec sp_ConvProc2View @procName = 'sp_who',
        @viewName ='v$Session'


exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure

select * from v$session
![](http://i2.51cto.com/images/blog/201805/17/21ede5991cacfa4acb0dd9473edb45c6.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)