CREATE PROC pr_error
@empNo INT,
@empName VARCHAR(10),
@job VARCHAR(10) = '사원',
@manager INT = 1008,
@hireDate DATE = '2015/04/12',
@salary INT = 200,
@commission INT = NULL,
@deptNo INT = 20
AS
DECLARE @err INT;
INSERT employee
VALUES(@empNo, @empName, @job, @manager, @hireDate, @salary, @commission,@deptNo);
SELECT @err = @@Error;
IF @err !=0
BEGIN
PRINT '입력시 오류 발생'
END;
RETURN @err;
DECLARE @returnError INT;
EXEC @returnError = pr_error 1002, '강장동';
IF (@returnError !=0)
SELECT @returnError
번호가 출력 안되고 있음
CREATE PROC pr_error_catch
@empNo INT,
@empName VARCHAR(10),
@job VARCHAR(10) = '사원',
@manager INT = 1008,
@hireDate DATE = '2015/04/12',
@salary INT = 200,
@commission INT = NULL,
@deptNo INT = 20
AS
DECLARE @err INT;
BEGIN TRY
INSERT employee
VALUES(@empNo, @empName, @job, @manager, @hireDate, @salary, @commission,@deptNo);
END TRY
BEGIN CATCH
SELECT error_number()
SELECT error_message()
END CATCH
EXEC pr_error_catch 1002, '김동주';
BEGIN TRY
를 통해 예외처리를 할 수 있
EXEC SP_HELPTEXT pr_error;
SUBSTRING("문자열", "시작위치", "길이")``` : 지정한 위치에서 지정한 문자열 길이만큼 자를 때 사용
CREATE PROC pr_enc WITH ENCRYPTION
AS
SELECT SUBSTRING(empName, 1, 1) + '**' AS 성명,
hiredate, deptNo
FROM employee;
EXEC pr_enc;
EXEC SP_HELPTEXT pr_enc;
강의: ms sql 2014 제대로 배우기 2