TAILIEUCHUNG - beginning microsofl sql server 2008 programming phần 7

Chương 12: Thủ tục lưu trữ Bạn có thể kiểm tra tràn số học một cách dễ dàng bằng cách đặt bất kỳ số lượng lớn trong bất cứ điều gì lớn hơn khoảng 13 sẽ làm việc cho ví dụ này. Kiểm tra giới hạn đệ quy cấp 32-sửa đổi một chút để sproc của chúng tôi. | Chapter 12 Stored Procedures You can test the arithmetic overflow easily by putting any large number in anything bigger than about 13 will work for this example. Testing the 32-level recursion limit takes a little bit more modification to our sproc. This time we ll determine the triangular of the number. This is very similar to finding the factorial except that we use addition rather than multiplication. Therefore 5 triangular is just 15 5 4 3 2 1 . Let s create a new sproc to test this one out it will look just like the factorial sproc with only a few small changes CREATE PROC spTriangular @ValueIn int @ValueOut int OUTPUT AS DECLARE @InWorking int DECLARE @OutWorking int IF @ValueIn 1 BEGIN SELECT @InWorking @ValueIn - 1 EXEC spTriangular @InWorking @OutWorking OUTPUT SELECT @ValueOut @ValueIn @OutWorking END ELSE BEGIN SELECT @ValueOut 1 END RETURN GO As you can see there weren t that many changes to be made. Similarly we only need to change our sproc call and the PRINT text for our test script DECLARE @WorkingOut int DECLARE @WorkingIn int SELECT @WorkingIn 5 EXEC spTriangular @WorkingIn @WorkingOut OUTPUT PRINT CAST @WorkingIn AS varchar Triangular is CAST @WorkingOut AS varchar Running this with an @ValueIn of 5 gets our expected 15 5 Triangular is 15 However if you try to run it with an @ValueIn of more than 32 you get an error Msg 217 Level 16 State 1 Procedure spTriangular Line 10 Maximum stored procedure function trigger or view nesting level exceeded limit 32 . 401 Chapter 12 Stored Procedures I d love to say there s some great workaround to this but unless you can somehow segment your recursive calls run it 32 levels deep then come all the way back out of the call stack then run down it again you re pretty much out of luck. Just keep in mind that most recursive functions can be rewritten to be a more standard looping construct which doesn t have any hard limit. Be sure you can t use a loop before you force yourself into recursion. Debugging Long ago and

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.