如何将查询转换为PL / SQL

时间:2015-01-05 22:48:39

标签: oracle plsql

你能告诉我一个如何转换成存储过程的例子吗? (查询更大) 我只需要一个例子  如何转换C2

Select 
A1,B1,B2,B3,B4,B5,C1,C2
From (
Select    Distinct

          A.Fiseguro,
          Trunc(A.Fdfecsurt) A1,
          'SEGURO DE MOTO'   B1,
          'Q'                B2,  
          A.Fnprima          B3,
          A.Fccertificado    B4,
          To_Number(
            Sms.Fnsumaaseg
          )                  B5,
          'FISICA'           C1,
          Replace( Coalesce(
            Case When Regexp_Like(Trim(Substr(Sia.Saz_Adnrow, 25, 14)), '^\d') And Length(Trim(Substr(Sia.Saz_Adnrow, 25, 14)))<13 Then Trim(Substr(Sia.Saz_Adnrow, 25, 14)) Else Null End,
              Case When Regexp_Like(Trim(Mc.Fcrfc), '^\d') And Length(Trim(Mc.Fcrfc))<13 Then Trim(Mc.Fcrfc) Else Null End,
              Case When Regexp_Like(Trim(Sds2.Fcdocnumref), '^\d') And Length(Trim(Sds2.Fcdocnumref))<13 Then Trim(Sds2.Fcdocnumref) Else Null End,
              Case When Regexp_Like(Trim(Scl1.Fcdni), '^\d') And Length(Trim(Scl1.Fcdni))<13 Then Scl1.Fcdni Else Null End,
              Case When Regexp_Like(Trim(Scl1.Fcdocnumref), '^\d') And Length(Trim(Scl1.Fcdocnumref))<13 Then Trim(Scl1.Fcdocnumref) Else Null End,
              Case When Regexp_Like(Trim(Scl2.Fcrfc), '^\d') And Length(Trim(Scl2.Fcrfc))<13 Then Trim(Scl2.Fcrfc) Else Null End,
              Case When Regexp_Like(Trim(Scl2.Fcdn2), '^\d') And Length(Trim(Scl2.Fcdn2))<13 Then Trim(Scl2.Fcdn2) Else Null End,
              Case When Regexp_Like(Trim(Scl2.Fcdpi), '^\d') And Length(Trim(Scl2.Fcdpi))<13 Then Trim(Scl2.Fcdpi) Else Null End,
              'CF'
          ), '-')            C2,

From table A
  Left Join table Sms
        On Sms.Fipais = To_Char(A.Fipais)
        And Sms.Ficanal = To_Char(A.Ficanal)
        And Sms.Fisucursal = To_Char(A.Fisucursal)
        And Sms.Finopedido = To_Char(A.Finopedido)

1 个答案:

答案 0 :(得分:2)

如果您的查询是

,这将无法完全回答您的问题
SELECT x FROM t WHERE ID = 1;

然后存储过程返回x(假设ID是唯一索引):

CREATE OR REPLACE FUNCTION MY_STORED_PROC(i_id number)
RETURN x.t%TYPE
IS
  l_val x.t%TYPE;
BEGIN
  SELECT x
  INTO   l_val
  FORM   t
  WHERE  ID = i_id;
  return l_val;
END;