2015-01-26 270 views
0

我是新來的Sybase,我需要創建一個存儲過程來收集空間,基本上將這些成一個程序:如何創建Sybase存儲過程

create proc sp_maint 
    @dbname varchar(30), @segname varchar(30), 
    @devname varchar(30), @devsize int, 
    @freesize int, @free_percentage int 
as declare @sizeinpg float, 
+1

你能更具體什麼不起作用? – 2015-01-26 21:26:41

+0

我使用的語法是錯誤的 – user2962992 2015-01-26 21:45:33

+0

現在,你只給了我們一小段代碼,而不是完整的proc。很難說只是你的變量你做錯了什麼......你打算在某個時候從系統表中選擇這些數據嗎? – 2015-01-27 16:41:10

回答

0
create proc sp_maint 
    @dbname varchar(30), 
    @segname varchar(30), 
    @devname varchar(30), 
    @devsize int, 
    @freesize int, 
    @free_percentage int 
as 
declare @sizeinpg float, 
     @perc  float, 
     @segbit int, 
     @seg  int, 
     @pagefl float 
BEGIN 
/* for all segments */ 
    select @seg = segment 
    from syssegments 
    where name = @segname 
select DATE=convert(char(8),getdate(),1), 
     DB_NAME=db, 
     SEGMENT_NAME=seg, 
     Allocated_Space=convert(int,(round(size,0))), 
     Free_Space=convert(int,round(MBfree,0)), 
     Free_Percent=convert(int,(round(((MBfree/size)*100),1))), 
/* get rid of blanks */ 
    select @dbname = ltrim(rtrim(@dbname)) 
    select @segname = ltrim(rtrim(@segname)) 
**strong text**