120 likes | 341 Views
PSP. Oracle Application Server. Configurations. Database Access Descriptor (DAD) Username: scott Password: tiger Connect String: localhost:1521:orc Create a Procedure Go to url: http://localhost/pls/simpledad/<procname>. Example. CREATE OR REPLACE PROCEDURE myhello AS BEGIN
E N D
PSP Oracle Application Server
Configurations • Database Access Descriptor (DAD) • Username: scott • Password: tiger • Connect String: localhost:1521:orc • Create a Procedure • Go to url: • http://localhost/pls/simpledad/<procname>
Example CREATE OR REPLACE PROCEDURE myhello AS BEGIN htp.print('<HTML> <HEAD> <TITLE>My First Page</TITLE> </HEAD> <BODY BGCOLOR="white"> <H1>Hello, Web!</H1> </BODY> </HTML>'); END;
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;
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)
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 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; END;
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 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
Table 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;
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 the input form • To send parameter use the address: • http://url/empprint2?p_deptno=30 • Html form: <form action="empprint2" method=get> <input type=text name="p_deptno"> <input type=submit value="find"> </form>