创建并使用标量函数--如果存在(选择sysobjects中的名称从中选择名称='get_salary_by_deptno')则删除函数get_salary_by_deptno,创建函数get_salary_by_deptno(@v_dept_no整数)返回整数作为起始处tdeclare @v_sum整数tselect @v_sum=sum(sal) from emp ttt where deptno = @v_dept_no tif @@error0 begin ttttreturn -1 --其中返回-1表示函数出错了end treturn @v_sum end --使用函数print dbo.get_salary_by_deptno(10)