Download presentation
Presentation is loading. Please wait.
Published byShon McDaniel Modified over 9 years ago
1
PSP Oracle Application Server
2
Configurations Database Access Descriptor (DAD) –Username: scott –Password: tiger –Connect String: localhost:1521:orc Create a Procedure Go to url: –http://localhost/pls/simpledad/ Database Access Descriptor (DAD) –Username: scott –Password: tiger –Connect String: localhost:1521:orc Create a Procedure Go to url: –http://localhost/pls/simpledad/
3
Example CREATE OR REPLACE PROCEDURE myhello AS BEGIN htp.print(' My First Page Hello, Web! '); END; CREATE OR REPLACE PROCEDURE myhello AS BEGIN htp.print(' My First Page Hello, Web! '); END;
4
Example 2 CREATE OR REPLACE PROCEDURE myhello AS BEGIN htp.htmlOpen; htp.headOpen; htp.title('My First Page'); htp.headClose; htp.bodyOpen( cattributes => 'BGCOLOR="white"'); htp.header(1, 'Hello, Web!'); htp.bodyClose; htp.htmlClose; END; CREATE OR REPLACE PROCEDURE myhello AS BEGIN htp.htmlOpen; htp.headOpen; htp.title('My First Page'); htp.headClose; htp.bodyOpen( cattributes => 'BGCOLOR="white"'); htp.header(1, 'Hello, Web!'); htp.bodyClose; htp.htmlClose; END;
5
Reference http://otn.oracle.co.kr/docs/oracle78/was3x/was301/cart/carttoc.htm htp and htf packages htp – hypertext procedures Htf – hypertext functions (returns varchar2) http://otn.oracle.co.kr/docs/oracle78/was3x/was301/cart/carttoc.htm htp and htf packages htp – hypertext procedures Htf – hypertext functions (returns varchar2)
6
Reuse code Create procedures to reuse code: CREATE OR REPLACE PACKAGE hutil AS PROCEDURE hOpen( p_title IN VARCHAR2 DEFAULT NULL,p_bgcolor IN VARCHAR2 DEFAULT '"white"' ); PROCEDURE hClose; END; Create procedures to reuse code: CREATE OR REPLACE PACKAGE hutil AS PROCEDURE hOpen( p_title IN VARCHAR2 DEFAULT NULL,p_bgcolor IN VARCHAR2 DEFAULT '"white"' ); PROCEDURE hClose; END;
7
CREATE OR REPLACE PACKAGE BODY hutil AS PROCEDURE hOpen( p_title in varchar2,p_bgcolor in varchar2 ) IS BEGIN htp.htmlOpen; htp.headOpen; htp.title( p_title ); htp.headClose; htp.bodyOpen( cattributes=> 'BGCOLOR=' || p_bgcolor ); END; PROCEDURE hClose IS BEGIN htp.bodyClose; htp.htmlClose; END; CREATE OR REPLACE PACKAGE BODY hutil AS PROCEDURE hOpen( p_title in varchar2,p_bgcolor in varchar2 ) IS BEGIN htp.htmlOpen; htp.headOpen; htp.title( p_title ); htp.headClose; htp.bodyOpen( cattributes=> 'BGCOLOR=' || p_bgcolor ); END; PROCEDURE hClose IS BEGIN htp.bodyClose; htp.htmlClose; END;
8
Use hutil CREATE OR REPLACE PROCEDURE myhello3 AS BEGIN hutil.hOpen('My First Page'); htp.header(1, 'Hello, Web!'); hutil.hClose; END; CREATE OR REPLACE PROCEDURE myhello3 AS BEGIN hutil.hOpen('My First Page'); htp.header(1, 'Hello, Web!'); hutil.hClose; END;
9
CREATE OR REPLACE PROCEDURE show_max_sal as maxSal scott.emp.sal%TYPE; cursor salCur IS SELECT MAX(sal) FROM scott.emp; noEmp exception; BEGIN hutil.hOpen( 'Salary Max'); OPEN salCur; FETCH salCur INTO maxSal; if salCur%NOTFOUND then raise noEmp; end if; CLOSE salCur; htp.print('The highest salary is: ' || maxSal); hutil.hClose; EXCEPTION WHEN noEmp THEN htp.print('Warning: There are no employees.'); hutil.hClose; END; CREATE OR REPLACE PROCEDURE show_max_sal as maxSal scott.emp.sal%TYPE; cursor salCur IS SELECT MAX(sal) FROM scott.emp; noEmp exception; BEGIN hutil.hOpen( 'Salary Max'); OPEN salCur; FETCH salCur INTO maxSal; if salCur%NOTFOUND then raise noEmp; end if; CLOSE salCur; htp.print('The highest salary is: ' || maxSal); hutil.hClose; EXCEPTION WHEN noEmp THEN htp.print('Warning: There are no employees.'); hutil.hClose; END; Display database data
10
CREATE OR REPLACE PROCEDURE empPrint AS BEGIN hutil.hOpen('Employees'); htp.tableOpen('BORDER'); htp.tableRowOpen; htp.tableHeader('Emp#'); htp.tableHeader('Name'); htp.tableHeader('Sal'); htp.tableRowClose; FOR theEmp IN (SELECT empno, ename, sal FROM scott.emp ORDER BY empno) LOOP htp.tableRowOpen; htp.tableData( theEmp.empno ); htp.tableData( theEmp.ename ); htp.tableData( theEmp.sal ); htp.tableRowClose; END LOOP; htp.tableClose; hutil.hClose; END; CREATE OR REPLACE PROCEDURE empPrint AS BEGIN hutil.hOpen('Employees'); htp.tableOpen('BORDER'); htp.tableRowOpen; htp.tableHeader('Emp#'); htp.tableHeader('Name'); htp.tableHeader('Sal'); htp.tableRowClose; FOR theEmp IN (SELECT empno, ename, sal FROM scott.emp ORDER BY empno) LOOP htp.tableRowOpen; htp.tableData( theEmp.empno ); htp.tableData( theEmp.ename ); htp.tableData( theEmp.sal ); htp.tableRowClose; END LOOP; htp.tableClose; hutil.hClose; END; Table
11
Dynamic Result CREATE OR REPLACE PROCEDURE empPrint2( p_deptno IN VARCHAR2 DEFAULT '%' ) AS BEGIN hutil.hOpen('Employees'); htp.tableOpen('BORDER'); FOR theEmp IN (SELECT empno, ename, sal FROM scott.emp WHERE deptno like p_deptno ORDER BY empno ) LOOP htp.tableRowOpen; htp.tableData( theEmp.empno ); htp.tableData(theEmp.ename ); htp.tableData(theEmp.sal ); htp.tableRowClose; END LOOP; htp.tableClose; hutil.hClose; END; CREATE OR REPLACE PROCEDURE empPrint2( p_deptno IN VARCHAR2 DEFAULT '%' ) AS BEGIN hutil.hOpen('Employees'); htp.tableOpen('BORDER'); FOR theEmp IN (SELECT empno, ename, sal FROM scott.emp WHERE deptno like p_deptno ORDER BY empno ) LOOP htp.tableRowOpen; htp.tableData( theEmp.empno ); htp.tableData(theEmp.ename ); htp.tableData(theEmp.sal ); htp.tableRowClose; END LOOP; htp.tableClose; hutil.hClose; END;
12
Create the input form To send parameter use the address: –http://url/empprint2?p_deptno=30 Html form: To send parameter use the address: –http://url/empprint2?p_deptno=30 Html form:
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.