PL/SQL Web编程初接触

----------------------页面封装包头-----------------------

create or replace package formattype
as
  function pagestart(title in varchar2) return varchar2;
  function introtext(text in varchar2) return varchar2;
  function pageend return varchar2;
end;

 

----------------------数据操作包头---------------------------

create or replace package show_package
as
  procedure showemplist;
end;

 

-------------------------页面封装包体--------------------------

create or replace package body formattype
as
  function pagestart(title in varchar2) return varchar2
  is
    retval varchar2(32767);
    begin
      retval := '<html xmlns="http:\/\/www.w3.org\/1999\/xhtml">'
        ||'<head>'
        ||'<title>'||title||'</title>'
        ||'</head>'
        ||''
        ||'<body bgcolor="#FFFFFF">'
        ||'<table width="550">'
        ||'<tr>'
          ||'<td>'||title||'</td>'
        ||'</tr>'
        ||'</table>'
        ||'<table width="550"><tr><td>';
      return retval;
   end;
   function introtext(text in varchar2) return varchar2
   is
    retval varchar2(32767);
    begin
      retval := '<font size="1">'||text||'</font>';
    return retval;
   end;
   function pageend return varchar2
   is
    retval varchar2(32767);
    begin
      retval := to_char(sysdate,'yyyy-mm-dd hh24:mi:ss')||'</td>'
        ||'</tr>'
        ||'</table>'
        ||'</body>'
        ||'</html>';
    return retval;
   end;
end;

 

--------------------------数据操作包体----------------------------------------

create or replace package body show_package
as
  procedure showemplist
  is
      cursor e_cur is select * from emp order by empno desc;
      r_emp emp%ROWTYPE;
    begin
      htp.p(formattype.pagestart('emp 信息一览表'));
      htp.p(formattype.introtext('显示所有信息'));
      htp.p('<table cellpadding="4">');
      htp.p(' <tr>');
      htp.p('      <th>编号</th>');
      htp.p('      <th>姓名</th>');
      htp.p('      <th>薪水</th>');
      htp.p(' </tr>');
      open e_cur;
      loop
        fetch e_cur into r_emp;
        exit when e_cur%notfound;
        htp.p(' <tr>');
        htp.p('      <td>'||r_emp.empno||'</td>');
        htp.p('      <td>'||r_emp.ename||'</td>');
        htp.p('      <td>'||r_emp.sal||'</td>');
        htp.p(' </tr>');
      end loop;
      close e_cur;
      htp.p('</table>');
      htp.p(formattype.pageend);
   end;
end;

--------------------------------------------------------------------------

 

配置好Http Server ,在浏览器中输入 http://www.<hostname>:<port>/<directoryAddress>/show_package.showemplist 就可以在页面中预览了

 

你可能感兴趣的:(sql,编程,Web,浏览器,SQL Server)