TAILIEUCHUNG - Oracle SQL Plus The Definitive Guide- P28

Oracle SQL Plus The Definitive Guide- P28:Every day, computer professionals the world over wake up, travel to the office, sit down in front of a computer, and begin another day working with that database called Oracle. Programmers write queries and stored procedures. Database administrators monitor performance, make database changes, and perform other maintenance tasks. Operations people may need to back up or recover a database. | previous page page_244 next page Page 244 Simulating Branching by Adjusting the WHERE Clause. Suppose you are writing a script to delete all data from the project_hours table. Before you delete the data you want to ask the user to confirm the operation. You really want to write something like this ACCEPT s_delete_confirm PROMPT Delete project hours data Y N IF s_delete_confirm Y THEN DELETE FROM project_hours END IF Of course you can t do that SQL Plus has no IF statement remember However you can add a WHERE clause to the DELETE statement that will have the same effect. Here s an example SET VERIFY OFF ACCEPT s_delete_confirm PROMPT Delete project hours data Y N DELETE FROM project_hours WHERE UPPER sdeleteconfirm Y When you execute the script the DELETE will always be executed. However if the user answers with an N the WHERE clause will always evaluate to FALSE and no rows will be deleted. Verification is set off only to prevent SQL Plus from echoing the line of the WHERE clause that references the substitution variable. The UPPER function is used in this case in order to allow the user s response to be case-insensitive. Here s how it looks when a user runs this script and doesn t confirm the delete SQL @delete_hours Delete project hours data Y N n 0 rows deleted. If you wanted to you could even write an additional query to give the user an error message if the response to the prompt was not a Y or an N. Adding these lines immediately after the ACCEPT statement would do that for you SET HEADING OFF SET PAGESIZE 0 SET FEEDBACK OFF SELECT You must answer with a Y or N. FROM DUAL WHERE UPPER s_delete_confirm NOT IN y N OR s_delete_confirm IS NULL previous page page_244 next page previous page page_245 next page Page 245 SET FEEDBACK ON SET PAGESIZE1 SET HEADING ON To make the results of this query look like an error message both headings and pagination are turned off. Feedback is also turned off to avoid giving the 1 row selected message to the user. After the .

TỪ KHÓA LIÊN QUAN
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.