⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oracle webserver

📁 介绍了数据库方面的基础知识
💻
📖 第 1 页 / 共 2 页
字号:
参数排序 
参数缺省值 
多个HTML表格字段使用同一个名字 
过程重载 
从Web浏览器到Web Agent的参数获取 
 依赖使用REQUEST_METHOD 的不同, 参数由Web浏览器到Web Listener的传递有两种方法: 

QUERY_STRING 环境变量 -- 如果浏览器使用GET方法,Web Listener用此环 境变量传递参数给Web Agent。 
标准输入 -- 如果使用POST方法,Web Listener使用标准输入传递参数到Web Agent。 
从Web Listener到Web Agent的参数传递方法对于PL/SQL过程这个参数的实际消费者 
来说是透明的。这是Oracle Web Agent的一个重要特性:PL/SQL程序员不需要知道使 
用何种方法,不需要关心从环境变量QUERY_STRING还是标准输入进行解析。PL/SQL程 
序员因而精力集中在他们最精通的方面:开发从Oracle数据库提取数据的逻辑,基于 
从Oracle Web Agent传来的预解析的参数。 
  建议:可能的情况下,使用POST。GET方法用于链接和非表格URL。对于HTML表格, 
可以有个选择。因为GET方法使用操作系统环境变量,QUERY_STRING有长度限制。 

使用HTML表格传递参数 

 下例模拟前一节,除非它使用HTML表格使用POST REQUEST_METHOD。 
  

<FORM METHOD="POST" ACTION="http://www.nhl.com:8080/ows-bin/nhl/owa/hockey.pass">
Please type the name of the person you wish to search for:
<INPUT TYPE="text" NAME="person"><P>
To submit the query, press this button: 
<INPUT TYPE="submit" VALUE="Submit Query">. <P>
</FORM>
上面的表格使得Oracle Web Listener与前一个例子的行为一样,只是不再使用"person=Gretzky"填环境变量QUERY_STRING,Web Listener把"person=Gretzky"写到 
标准输出。这里当然假设了用户在表格的字段里输入了"Gretzky"。 
注意:HTML输入变量的名字,此处为"person",必须和与它相匹配的PL/SQL参数完全 
相同。 
  上述参数的接收的PL/SQL过程如下: 
  

create or replace
procedure hockey_pass (person in varchar2) is
   n_assists integer;
begin
   select num_assists into n_assists
      from hockey_stats
   where name=person;
   htp.print(person||' has '||to_char(n_assists)||' assists this      season');
end;
参数排序 
 总的来说, PL/SQL开发员不需要关心Oracle Web Agent以什么顺序从HTML表格或 
通过一个URL接收参数. 它仅在从一个表格字段传递多个值时才有关系。参见本节 
后面的"多个HTML表格字段使用相同的名字"。 

参数缺省值 

 如果PL/SQL开发员不能保证对于特定的PL/SQL过程参数必然有从Web浏览器传来的值 
的话,建议给此参数一个缺省值,例如: 

create or replace procedure showvals(a in varchar2 DEFAULT NULL,
                   b in varchar2 DEFAULT NULL) 
is 
begin 
   htp.print('a = '||a||htp.br);
   htp.print('b = '||b||htp.br); 
end;
如果Web Agent收到一个调用过程showvals的请求,没有给"a"的值,"b"的值为"Hello 
",如果过程定义中没有DEFAULT NULL子句,请求将得到如下错误信息: 
OWS-05111: Agent : no procedure matches this call
  OWA SERVICE: test_service 
  PROCEDURE: showvals 
 PARAMETERS: 
  =========== 
  B: 
   Hello
通过为参数设缺省值,上述请求被正常输出: 
a = <BR> 

b = Hello<BR>
对于最终用户它看起来象: 
a = 
b = Hello
多个HTML表格字段使用同一个名字 
有些情形下,人们想。为处理这种想用相同HTML字段即PL/SQL参数传递多个值的情 
况,可以用PL/SQL表创建值的数组。 

要用相同HTML字段传递多个值的一种情况是HTML表格的"SELECT"标记的使用。如果设 
参数SIZE为比1大的值,用户将能从同一个表格字段选择多个值。 
  另一种情况是人在单个表格字段选择一组相应的值: 

-- QUERY_FORM prints an HTML page with all the columns for the   
-- specified table.  Invoke the procedure from a Web Browser with
-- a URL like:
http://yourhost:port_num/service_name/owa/query_form?the_table=emp

create or replace procedure query_form(the_table in varchar2) is  
   cursor cols is 
   select column_name   
       from user_tab_columns 
   where table_name = upper(the_table); 
begin
   htp.htmlOpen; 
   htp.headOpen; 
   htp.htitle('Query the '||the_table||' table!'); 
   htp.headClose; 
   htp.bodyOpen; 
   -- Use owa_util.get_owa_service path to automatically retrieve 
   htp.formOpen(owa_util.get_owa_service_path||'do_query');
   -- Put in the table as a hidden field to pass on to do_query   
   htp.formHidden('the_table', the_table);
   -- Put in a dummy value, as we cannot DEFAULT NULL a PL/SQL table. 
htp.formHidden('COLS', 'dummy'); 
   for crec in cols loop
      -- Create a checkbox for each column. The form field name   
      -- will be COLS and the value will be the given column name.
      -- Will need to use a PL/SQL table to retrieve a set of 
      -- values like this. Can use the owa_util.ident_arr type    
      -- since the columns are identifiers.
      htp.formCheckbox('COLS',crec.column_name); 
      htp.print(crec.column_name); 
      htp.nl; 
   end loop; 
   -- Pass a NULL field name for the Submit field; that way, a 
   -- name/value pair is  not sent in.  Wouldn't want to do this  
   -- if there were multiple submit buttons.
   htp.formSubmit(NULL, 'Execute Query');    
   htp.formClose; 
   htp.bodyClose; 
   htp.htmlClose; 
end;
调用此过程将带来如下的一个页面: 
  
此例中,用户已经选择了查询EMPNO,ENAME,JOB,和SAL列 : 

这里是处理此表格提交的过程: 

-- DO_QUERY executes the query on the specified columns and 
-- tables.The OWA_UTIL.IDENT_ARR datatype is defined as: 
--  -- type ident_arr is table of varchar2(30) index by binary_integer
--
create or replace procedure do_query(the_table in varchar2,
 cols in owa_util.ident_arr) is

   column_list varchar2(32000); 
   col_counter integer;
   ignore      boolean;
begin 
-- For PL/SQL tables, have to just loop through until you hit 
-- no_data_found. Start the counter at 2 since we put in 
-- a dummy hidden field. 
   col_counter := 2; 
   loop 
      -- build a comma-delimited list of columns 
      column_list := column_list||cols(col_counter)||','; 
      col_counter := col_counter + 1; 
   end loop; 
exception 
   when no_data_found 
   then 
       -- strip out the last trailing comma 
       column_list := substr(column_list,1,length(column_list)-1); 
        -- print the table - assumes HTML table support 
       ignore := owa_util.tablePrint(the_table, 'BORDER',               
                                                        OWA_UTIL.HTML_TABLE,
 column_list); 
end;
选择按钮"Execute Query"后,用户将见到: 
 
使用隐藏的站位变量作为第一个值是个好想法,如果你不能保证至少一个值被提交到 
PL/SQL表的话。其原因是不能为PL/SQL表设缺省值。并且,调用这个仅一个参数(the_table)的过程将导致Web Agent产生一个错误。 

注意:Web Agent只可以传递基本类型为VARCHAR2的参数到PL/SQL表。这有个限制, 
PL/SQL类型VARCHAR2作为最大的PL/SQL数据类型,最大长度限制为32767字节。值在 
存储过程里被显式地转换到NUMBER, DATE,或LONG。(使用TO_NUMBER或TO_DATE-LONG 
不需转换)。 
  

过程重载
PL/SQL允许开发员重载在PL/SQL包中的过程和函数(但不能是独立的函数和过程)。 
create or replace package overload is 
     procedure proc1(charval in varchar2); 
     procedure proc1(numval  in number); 
end; 
 
create or replace package body overload is 
     procedure proc1(charval in varchar2) is 
     begin 
        htp.print('The character value is '||charval); 
     end; 
 
     procedure proc1(numval  in number); 
        htp.print('The number value is '||numval); 
     end; 
end;
此机制可以被Web Agent利用,但要求重载的过程的数据类型不能有相同的参数名。 
例如: 
  
create or replace package overload is 
     procedure proc1(val in varchar2); 
     procedure proc1(val in number); 
end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -