Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PL/SQL中创建函数表需要帮助吗_Sql_Oracle_Function - Fatal编程技术网

在PL/SQL中创建函数表需要帮助吗

在PL/SQL中创建函数表需要帮助吗,sql,oracle,function,Sql,Oracle,Function,这里需要帮助,我已经创建了一个函数表 SELECT * FROM TABLE (getsubs_api_v2(639377700080)); 但使用这个脚本,我只能输出一行数据,所以我尝试在表内使用子查询,但它返回 ORA-01427: single-row subquery returns more than one row 01427. 00000 - "single-row subquery returns more than one row" *Cause: *Action:

这里需要帮助,我已经创建了一个函数表

SELECT *
FROM TABLE (getsubs_api_v2(639377700080));
但使用这个脚本,我只能输出一行数据,所以我尝试在表内使用子查询,但它返回

ORA-01427: single-row subquery returns more than one row
01427. 00000 -  "single-row subquery returns more than one row"
*Cause:   
*Action:
我的实验查询如下:

SELECT * FROM TABLE   (SELECT getsubs_api_v2(SUBSTR(name, 2,
LENGTH(name)-1))   FROM pin.service_alias_list_t@brm_prod   WHERE
rec_id                         = 1   AND SUBSTR(name, 2,
LENGTH(name)-1) IN ('639377700080', '639373000273', '639373700013',
'639373700020', '639373700038')   );
你能帮我增强这个脚本吗

如果您需要函数getsubs\u api\u v2,请参见下面的内容

CREATE OR REPLACE FUNCTION getsubs_api_v2(mobtel number) RETURN t_tf_tab PIPELINED AS
  l_tab  t_tf_tab := t_tf_tab();
    soap_request  VARCHAR2(30000);
    soap_respond  CLOB;
    http_req      utl_http.req;
    http_resp     utl_http.resp;
    resp          XMLType;
    soap_err      exception;
    v_code        VARCHAR2(200);
    v_msg         VARCHAR2(1800);
    v_len number;
    v_txt Varchar2(32767);
  BEGIN
    --UTL_HTTP.SET_PROXY(p_proxy);
    -- Define the SOAP request according the the definition of the web service being called
    soap_request:= '<?xml version = "1.0" encoding = "UTF-8"?>'||
                   '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'||
                   '    <soap:Body xmlns:ns1="http://xmlns.oracle.com/SBLMVNE/MVNERetrieveSubscriberDetail/MVNERetrieveSubscriberDetailProcess">'||
                   '        <ns1:retrieveSubscriberDetailRequest>'||
                   '            <ns1:header>'||
                   '                <ns1:InterfaceName></ns1:InterfaceName>'||
                   '                <ns1:InterfaceId></ns1:InterfaceId>'||
                   '                <ns1:CorrelationId></ns1:CorrelationId>'||
                   '            </ns1:header>'||
                   '            <ns1:mvno></ns1:mvno>'||
                   '            <ns1:searchCriteriaType>MSISDN</ns1:searchCriteriaType>'||
                   '            <ns1:searchCriteriaValue>'||mobtel||'</ns1:searchCriteriaValue>'||
                   '        </ns1:retrieveSubscriberDetailRequest>'||
                   '    </soap:Body>'||
                   '</soap:Envelope>';
    http_req:= utl_http.begin_request
              ( 'http://192.168.0.1:8001/soa-infra/services/Dash/MVNERetrieveSubscriberDetail!1.0*soa_7e28c041-0e10-4cd0-b956-5ba9f6d5e56d/mvneretrievesubscriberdetailprocess_client_ep?wsdl'
              , 'POST'
              , 'HTTP/1.1'
              );
    utl_http.set_header(http_req, 'Content-Type', 'text/xml');
    utl_http.set_header(http_req, 'Content-Length', length(soap_request));
    utl_http.set_header(http_req, 'Download', ''); -- header requirements of particular web service
    utl_http.write_text(http_req, soap_request);
    http_resp:= utl_http.get_response(http_req);
    utl_http.get_header_by_name(http_resp, 'Content-Length', v_len, 1); -- Obtain the length of the response
    FOR i in 1..CEIL(v_len/32767) -- obtain response in 32K blocks just in case it is greater than 32K
    LOOP
        utl_http.read_text(http_resp, v_txt, case when i < CEIL(v_len/32767) then 32767 else mod(v_len,32767) end);
        soap_respond := soap_respond || v_txt; -- build up CLOB
    END LOOP;
    utl_http.end_response(http_resp);
    resp:= XMLType.createXML(soap_respond); -- Convert CLOB to XMLTYPE

    for y in (
    with test_mike as (select resp xml_data from dual)
    select x.*, x1.*, x2.*, x3.* from test_mike t,
  xmltable(xmlnamespaces('http://xmlns.oracle.com/SBLMVNE/MVNERetrieveSubscriberDetail/MVNERetrieveSubscriberDetailProcess' as "ns3",
  'http://schemas.xmlsoap.org/soap/envelope/' as "ns1", 'http://www.w3.org/2005/08/addressing' as "ns2"),
          'ns1:Envelope/ns1:Body/ns3:retrieveSubscriberDetailResponse/ns3:subscribers/ns3:Subscriber'
          passing t.xml_data
          columns subs_id number path 'ns3:subscriberId',
                  service_num number path 'ns3:serviceNo1',
                  duo_num number path 'ns3:serviceNo2',
                  iccid varchar2(30) path 'ns3:serviceNo4',
                  creation_date varchar2(30) path 'ns3:creationDt',
                  subs_status xmltype path 'ns3:subscriberStatus',
                  cos xmltype path 'ns3:cos',
                  wallets xmltype path 'ns3:wallets/ns3:wallet') x,
  xmltable(xmlnamespaces('http://xmlns.oracle.com/SBLMVNE/MVNERetrieveSubscriberDetail/MVNERetrieveSubscriberDetailProcess' as "ns1"),
          'ns1:subscriberStatus'
          passing x.subs_status
          columns mvne_status number path 'ns1:Status',
                  status_date varchar2(30) path 'ns1:statusDt',
                  expiration_date varchar2(30) path 'ns1:statusExpiryDt') x1,
  xmltable(xmlnamespaces('http://xmlns.oracle.com/SBLMVNE/MVNERetrieveSubscriberDetail/MVNERetrieveSubscriberDetailProcess' as "ns1"),
          'ns1:cos'
          passing x.cos
          columns cos_id number path 'ns1:Id',
                  cos_name varchar2(10) path 'ns1:Name') x2,
  xmltable(xmlnamespaces('http://xmlns.oracle.com/SBLMVNE/MVNERetrieveSubscriberDetail/MVNERetrieveSubscriberDetailProcess' as "ns1"),
          'ns1:wallet'
          passing x.wallets
          columns wallet_id number path 'ns1:Id',
                  wallet_name varchar2(20) path 'ns1:Name',
                  wallet_type varchar2(20) path 'ns1:Type',
                  wallet_balance number path 'ns1:Balance',
                  wallet_currency varchar2(10) path 'ns1:currency',
                  wallet_expdt varchar2(30) path 'ns1:expiryDt') x3) loop
    --l_tab.extend;
    pipe row(t_tf_row(y.subs_id, y.service_num, y.duo_num,y.iccid,y.creation_date,y.mvne_status,y.status_date,y.expiration_date,y.cos_id,y.cos_name,y.wallet_id,y.wallet_name,y.wallet_type,y.wallet_balance,y.wallet_currency,y.wallet_expdt));
    end loop;
    return;
  END;
但这一次,我得到了一个错误:

ORA-06553: PLS-306: wrong number or types of arguments in call to 'GETSUBS_API_V2'
06553. 00000 -  "PLS-%s: %s"
*Cause:    
*Action:
Error at Line: 3 Column: 4

从此行中删除第二个选择:

SELECT * FROM TABLE   (SELECT getsubs_api_v2(SUBSTR(name, 2,
只是:

请参阅文档中的示例,说明如何调用流水线函数:

示例13-10如何将函数结果从一个函数传递到另一个函数 另一个

从表格FCURSOR中选择*或从表格G中选择*


正如您在本例中看到的,表和流水线函数名f之间没有任何SELECT子句。

从此行中删除第二个SELECT:

SELECT * FROM TABLE   (SELECT getsubs_api_v2(SUBSTR(name, 2,
只是:

请参阅文档中的示例,说明如何调用流水线函数:

示例13-10如何将函数结果从一个函数传递到另一个函数 另一个

从表格FCURSOR中选择*或从表格G中选择*

正如您在本例中看到的,在表和流水线函数名f之间没有任何SELECT子句。

a的表语法需要传递一个集合表达式;可以是子查询,但:

集合表达式可以是子查询、列、函数或集合构造函数。无论其形式如何,它都必须返回一个集合值,即类型为嵌套表或varray的值

您使用的子查询返回多个流水线函数结果,但不是作为集合。您可能会使用multiset将所有函数结果放入一个集合中,但这会很冗长,不必要

您需要将实际表与使用实际表中的值的表集合表达式交叉联接:

SELECT t.*
FROM pin.service_alias_list_t@brm_prod salt
CROSS JOIN TABLE (getsubs_api_v2(SUBSTR(salt.name, 2, LENGTH(salt.name )-1))) t
WHERE salt.rec_id = 1
AND SUBSTR(salt.name, 2, LENGTH(salt.name)-1) IN ('639373000273','639377700080');
我给了你的真实表一个别名salt,给了表集合表达式一个别名t,这样你就可以区分它们了。现在将为实际表中的每一行调用函数

将字符串传递到函数中会导致隐式转换,这是不理想的;一个显式的to_数字会更好,只要Oracle不尝试为in列表中没有的子字符串以及无法转换的子字符串计算该数字;这是不应该的

具有虚拟功能的快速演示:

create function pipe_demo(p_string varchar2, p_quantity number)
return sys.odcivarchar2list pipelined as
begin
  for i in 1..p_quantity loop
    pipe row (p_string);
  end loop;
  return;
end;
/
和表:

create table demo_table(string varchar2(20), quantity number);
insert into demo_table (string, quantity) values ('First string', 3);
insert into demo_table (string, quantity) values ('Second string', 2);
insert into demo_table (string, quantity) values ('Third string', 4);
和等效查询:

select t.column_value
from demo_table dt
cross join table(pipe_demo(dt.string, dt.quantity)) t;

COLUMN_VALUE       
--------------------
First string        
First string        
First string        
Second string       
Second string       
Third string        
Third string        
Third string        
Third string        

 9 rows selected 
a的表语法需要传递一个集合表达式;可以是子查询,但:

集合表达式可以是子查询、列、函数或集合构造函数。无论其形式如何,它都必须返回一个集合值,即类型为嵌套表或varray的值

您使用的子查询返回多个流水线函数结果,但不是作为集合。您可能会使用multiset将所有函数结果放入一个集合中,但这会很冗长,不必要

您需要将实际表与使用实际表中的值的表集合表达式交叉联接:

SELECT t.*
FROM pin.service_alias_list_t@brm_prod salt
CROSS JOIN TABLE (getsubs_api_v2(SUBSTR(salt.name, 2, LENGTH(salt.name )-1))) t
WHERE salt.rec_id = 1
AND SUBSTR(salt.name, 2, LENGTH(salt.name)-1) IN ('639373000273','639377700080');
我给了你的真实表一个别名salt,给了表集合表达式一个别名t,这样你就可以区分它们了。现在将为实际表中的每一行调用函数

将字符串传递到函数中会导致隐式转换,这是不理想的;一个显式的to_数字会更好,只要Oracle不尝试为in列表中没有的子字符串以及无法转换的子字符串计算该数字;这是不应该的

具有虚拟功能的快速演示:

create function pipe_demo(p_string varchar2, p_quantity number)
return sys.odcivarchar2list pipelined as
begin
  for i in 1..p_quantity loop
    pipe row (p_string);
  end loop;
  return;
end;
/
和表:

create table demo_table(string varchar2(20), quantity number);
insert into demo_table (string, quantity) values ('First string', 3);
insert into demo_table (string, quantity) values ('Second string', 2);
insert into demo_table (string, quantity) values ('Third string', 4);
和等效查询:

select t.column_value
from demo_table dt
cross join table(pipe_demo(dt.string, dt.quantity)) t;

COLUMN_VALUE       
--------------------
First string        
First string        
First string        
Second string       
Second string       
Third string        
Third string        
Third string        
Third string        

 9 rows selected 

好的,我已经修改了我的查询SELECT*从表getsubs\u api\u v2cursorselect SUBSTRname,2,LENGTHname-1从pin.service\u alias\u列表中_t@brm_prod其中rec_id=1,SUBSTRname,2,LENGTHname-1位于“639373000273”和“639377700080”中;但这一次,我得到了一个错误:ORA-06553:PLS-306:调用'GETSUBS_API_V2'06553时参数的数量或类型错误。00000-请-%s:%s*原因:*操作:第3行第4列出错函数有一个数字类型的参数,因此很可能传递的字符串无法转换为数字。声明一个数字变量,例如NBR,并将SUBSTRname,2,LENGTHname-1移到新行的函数调用之外:NBR:=to_number SUBSTRname,2,LENGTHname-1;,然后将这个变量传递给函数调用:getsubs\u api\u v2 nbr….好的,所以我修改了我的查询SELECT*来自表getsubs\u api\u v2cursorselect SUBSTRname,2,LENGTHname-1来自pin.service\u alias\u列表_t@brm_prod其中rec_id=1,SUBSTRname,2,LENGTHname-1位于“639373000273”和“639377700080”中;但这一次,我得到了一个错误:ORA-06553:PLS-306:调用'GETSUBS_API_V2'06553时参数的数量或类型错误。00000-请-%s:%s*原因:*操作:第3行第4列出错函数有一个参数NUMB ER类型,因此最有可能传递的字符串无法转换为数字。声明一个数字变量,例如NBR,并将SUBSTRname,2,LENGTHname-1移到新行的函数调用之外:NBR:=to_number SUBSTRname,2,LENGTHname-1;,然后将此变量传递给函数调用:getsubs\u api\u v2 nbr。。。。