简体   繁体   English

如何使用%ROWTYPE获得真正的签名

[英]How to get real signature with %ROWTYPE

How to get the real signature for a PLSQL procedure which uses %ROWTYPE arguments ? 如何获得使用%ROWTYPE参数的PLSQL过程的真实签名?

For example : 例如 :

clear screen;
prompt > Table creation to support %ROWTYPE
create table samples (
  id number,
  code varchar2(15),
  lib varchar2(200) );

prompt > Package witch use %ROWTYPE
create or replace package use_samples as
  procedure getSample(input_sample samples%ROWTYPE);
end use_samples;
/
prompt > Package BODY witch use %ROWTYPE
create or replace package body use_samples as
  procedure getSample(input_sample IN samples%ROWTYPE) is
    ex samples%ROWTYPE;
  begin
    select * into ex from samples where samples.code = input_sample.code;
  end getSample;
end use_samples;
/

prompt > Proc arguments by ALL_ARGUMENTS
set pagesize 50000
set linesize 2000
set verify off
CLEAR COLUMNS;
COLUMN object_name HEADING "PROC" FORMAT A30 JUSTIFY LEFT;
COLUMN argument_name HEADING "ARGUMENT_NAME" FORMAT A30 JUSTIFY LEFT;

select object_name, argument_name, in_out, data_level, position, data_type
from all_arguments
where owner = USER
and package_name = 'USE_SAMPLES'
and object_name = 'GETSAMPLE';

prompt >> Argument 'INPUT_SAMPLE' is shown as 'PL/SQL RECORD' without any link to 'samples%ROWTYPE'

prompt > PLSQL types declared
select *
from DBA_PLSQL_TYPES
where owner = USER
and package_name = 'USE_SAMPLES';

prompt >> There is no declared type because we use directly a %ROWTYPE argument


prompt > Clean up  
drop package use_samples;
drop table samples;

gives : 给出:

> Table creation to support %ROWTYPE

Table SAMPLES created.

> Package witch use %ROWTYPE

Package USE_SAMPLES compiled

> Package BODY witch use %ROWTYPE

Package body USE_SAMPLES compiled
> Proc arguments by ALL_ARGUMENTS
columns cleared

PROC                           ARGUMENT_NAME                  IN_OUT    DATA_LEVEL   POSITION DATA_TYPE                    
------------------------------ ------------------------------ --------- ---------- ---------- ------------------------------
GETSAMPLE                      INPUT_SAMPLE                   IN                 0          1 PL/SQL RECORD                 
GETSAMPLE                      ID                             IN                 1          1 NUMBER                        
GETSAMPLE                      CODE                           IN                 1          2 VARCHAR2                      
GETSAMPLE                      LIB                            IN                 1          3 VARCHAR2                      

>> Argument 'INPUT_SAMPLE' is shown as 'PL/SQL RECORD' without any link to 'samples%ROWTYPE'
> PLSQL types declared
no rows selected


>> There is no declared type because we use directly a %ROWTYPE argument
> Clean up

Package USE_SAMPLES dropped.


Table SAMPLES dropped.

So with ALL_ARGUMENTS, 'INPUT_SAMPLE' is shown as 'PL/SQL RECORD' without any link to 'samples%ROWTYPE'. 因此,对于ALL_ARGUMENTS,'INPUT_SAMPLE'显示为'PL / SQL RECORD',没有任何指向'samples%ROWTYPE'的链接。 And there is no trace of this type in DBA_PLSQL_TYPES. 并且DBA_PLSQL_TYPES中没有此类型的跟踪。

How can I get the declared type of this procedure under this form ? 如何在此表单下获取此过程的声明类型?

GETSAMPLE  INPUT_SAMPLE IN  SAMPLES%ROWTYPE

I have searched in dictionary and found nothing. 我在字典中搜索过,一无所获。 If there is no info (I don't know), you can use something like: 如果没有信息(我不知道),您可以使用以下内容:

SELECT b.object_name,b.argument_name, REGEXP_SUBSTR (UPPER (text),'([^{ ,(;}]+)%ROWTYPE') tadaaa
  FROM user_source a
       JOIN (SELECT package_name, object_name, argument_name, in_out, data_level, position, data_type
               FROM user_arguments x
              WHERE data_type = 'PL/SQL RECORD' AND package_name = 'USE_SAMPLES' AND object_name = 'GETSAMPLE' ) b
          ON a.name = b.package_name
 WHERE a.TYPE = 'PACKAGE BODY' 
   AND UPPER (text) LIKE '%\%ROWTYPE%' ESCAPE '\'
   AND UPPER (text) LIKE '%'||UPPER(ARGUMENT_NAME)||'%'    

:) Let some guru in regex check my regex expression. :)让正则表达式中的一些大师检查我的正则表达式。 Actually the argument name have to be in regex too. 实际上,参数名称也必须在正则表达式中。

I can suggest to go other way round: 我可以建议其他方式:

1) create object type with all attributes you need in your table 1)使用表中所需的所有属性创建对象类型

2) create object table of your TYPE 2)创建TYPE的对象表

3) pass argument into you procedure of your TYPE 3)将参数传递给TYPE的程序

4) you can get type name from all_arguments 4)您可以从all_arguments获取类型名称

%rowtype and %type are pseudo-types dynamically resolved during compilation. %rowtype%type是在编译期间动态解析的伪类型。 So what would you expect to see in data_dictionary info in this case? 那么在这种情况下,您希望在data_dictionary信息中看到什么? There is no named record/type/object related to sample%rowtype. 没有与样本%rowtype相关的命名记录/类型/对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM