Ngoài đầu ra văn bản thuần túy, giao diện dòng lệnh SQL*Plus cho phép bạn tạo một trang web hoàn chỉnh hoặc đầu ra HTML có thể được nhúng vào một trang web. Bạn có thể sử dụng SQLPLUS -MARKUP "HTML ON" hoặc SET MARKUP HTML ON SPOOL ON để tạo các trang HTML hoàn chỉnh được đóng gói tự động bằng thẻ và
Theo mặc định, dữ liệu được truy xuất bằng MARKUP HTML ON được xuất ra ở dạng HTML, mặc dù bạn có thể tùy ý chuyển hướng xuất sang HTML
tag so that it displays in a web browser exactly as it appears in SQL*Plus. See the SQLPLUS MARKUP Options and the SET MARKUP command for more information about these commands.SQLPLUS -MARKUP "HTML ON" is useful when embedding SQL*Plus in program scripts. On starting, it outputs the HTML and BODY tags before executing any commands. All subsequent output is in HTML until SQL*Plus terminates.
The -SILENT and -RESTRICT command-line options may be effectively used with -MARKUP to suppress the display of SQL*Plus prompt and banner information, and to restrict the use of some commands.
SET MARKUP HTML ON SPOOL ON generates an HTML page for each subsequently spooled file. The HTML tags in a spool file are closed when SPOOL OFF is executed or SQL*Plus exits.
You can use SET MARKUP HTML ON SPOOL OFF to generate HTML output suitable for embedding in an existing web page. HTML output generated this way has no or tags.
Creating Reports
During a SQL*Plus session, use the SET MARKUP command interactively to write HTML to a spool file. You can view the output in a web browser.
SET MARKUP HTML ON SPOOL ON only specifies that SQL*Plus output will be HTML encoded, it does not create or begin writing to an output file. You must use the SQL*Plus SPOOL command to start generation of a spool file. This file then has HTML tags including and .
When creating a HTML file, it is important and convenient to specify a .html or .htm file extension which are standard file extensions for HTML files. This enables you to easily identify the type of your output files, and also enables web browsers to identify and correctly display your HTML files. If no extension is specified, the default SQL*Plus file extension is used.
You use SPOOL OFF or EXIT to append final HTML tags to the spool file and then close it. If you enter another SPOOL filename command, the current spool file is closed as for SPOOL OFF or EXIT, and a new HTML spool file with the specified name is created.
You can use the SET MARKUP command to enable or disable HTML output as required.
Example 7-1 Creating a Report Interactively
You can create HTML output in an interactive SQL*Plus session using the SET MARKUP command. You can include an embedded style sheet, or any other valid text in the HTML tag. Open a SQL*Plus session and enter the following:
SET MARKUP HTML ON SPOOL ON PREFORMAT OFF ENTMAP ON - HEAD "Department Report - " - BODY "TEXT='#FF00Ff'" - TABLE "WIDTH='90%' BORDER='5'"Bạn sử dụng lệnh COLUMN để kiểm soát đầu ra của cột. Các lệnh COLUMN sau đây tạo tên tiêu đề mới cho đầu ra truy vấn SQL. Lệnh đầu tiên cũng tắt ánh xạ thực thể cho cột DEPARTMENT_NAME để cho phép các siêu liên kết HTML được tạo chính xác trong cột này của dữ liệu đầu ra
COLUMN DEPARTMENT_NAME HEADING 'DEPARTMENT' ENTMAP OFF COLUMN CITY HEADING 'CITY'SET MARKUP HTML ON SPOOL ON cho phép SQL*Plus ghi HTML vào tệp bộ đệm. Lệnh SPOOL sau kích hoạt việc ghi các thẻ và vào tệp được đặt tên
SPOOL report.htmlSau lệnh SPOOL, bất kỳ thứ gì được nhập hoặc hiển thị trên đầu ra tiêu chuẩn đều được ghi vào tệp ống đệm, báo cáo. html
Nhập một truy vấn SQL
SELECT ''||DEPARTMENT_NAME||'' DEPARTMENT_NAME, CITY FROM EMP_DETAILS_VIEW WHERE SALARY>12000;Nhập lệnh SPOOL OFF
SPOOL OFFCác thẻ và được thêm vào tệp cuộn, báo cáo. html, trước khi đóng
Đầu ra từ báo cáo. sql là một tập tin, báo cáo. html, có thể được tải vào trình duyệt web. mở báo cáo. html trong trình duyệt web của bạn. Nó sẽ xuất hiện một cái gì đó như sau
'||DEPARTMENT_NAME ||'' DEPARTMENT_NAME, CITY
2 FROM EMP_DETAILS_VIEW
3* WHERE SALARY>12000
DEPARTMENTCITY Executive Seattle Executive Seattle Executive Seattle Sales Oxford Sales Oxford Marketing Toronto 6 rows selected.
SQL> spool off
Ví dụ 7-2 Tạo Báo cáo bằng Lệnh SQLPLUS
Nhập lệnh sau tại dấu nhắc của hệ điều hành
SQLPLUS -S -M "HTML ON TABLE 'BORDER="2"'" HR@Ora10g @depart.sql>depart.html
khởi hành từ đâu. sql chứa
SELECT DEPARTMENT_NAME, CITY FROM EMP_DETAILS_VIEW WHERE SALARY>12000; EXIT
Ví dụ này bắt đầu SQL*Plus với người dùng "HR", nhắc nhập mật khẩu HR, đặt HTML BẬT, đặt thuộc tính BORDER cho BẢNG và chạy tập lệnh khởi hành. sql. Đầu ra từ khởi hành. sql là một trang web, trong trường hợp này, đã được chuyển hướng đến tệp khởi hành. html bằng lệnh chuyển hướng hệ điều hành ">" [có thể khác trên hệ điều hành của bạn]. Nó có thể được gửi tới trình duyệt web nếu SQL*Plus được gọi trong tập lệnh CGI của máy chủ web. Xem để biết thông tin về cách gọi SQL*Plus từ tập lệnh CGI
Khởi động trình duyệt web của bạn và nhập URL thích hợp để mở khởi hành. html
Mô tả của bộ phận minh họa. gif
Lệnh SQLPLUS trong ví dụ này chứa ba lớp dấu ngoặc kép lồng nhau. Từ trong ra ngoài, đây là