Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get real signature with %ROWTYPE

Tags:

oracle

plsql

How to get the real signature for a PLSQL procedure which uses %ROWTYPE arguments ?

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'. And there is no trace of this type in DBA_PLSQL_TYPES.

How can I get the declared type of this procedure under this form ?

GETSAMPLE  INPUT_SAMPLE IN  SAMPLES%ROWTYPE
like image 424
Chris Avatar asked Apr 14 '16 11:04

Chris


People also ask

What is the difference between %Rowtype and %type?

%TYPE : Used to declare a field with the same type as that of a specified table's column. %ROWTYPE: Used to declare a record with the same types as found in the specified table, view or cursor (= multiple columns).

What does %Rowtype mean?

The %ROWTYPE attribute is used to define a record with fields corresponding to all of the columns that are fetched from a cursor or cursor variable. Each field assumes the data type of its corresponding column. The %ROWTYPE attribute is prefixed by a cursor name or a cursor variable name.

How do you assign values to a Rowtype variable?

A row value can be assigned to a variable of type row by using a SELECT INTO statement, a VALUES INTO statement, or a FETCH INTO statement. The field values of the source row value must be assignable to the field values of the target row variable.

When should you use the %Rowtype attribute in creating a record variable?

%ROWTYPE attribute is used to declare the data type of a record variable based on a table's row structure. The %ROWTYPE attribute is used when you want to copy most or all of the columns in a table.


1 Answers

I can suggest to go other way round:

1) create object type with all attributes you need in your table

2) create object table of your TYPE

3) pass argument into you procedure of your TYPE

4) you can get type name from all_arguments

%rowtype and %type are pseudo-types dynamically resolved during compilation. So what would you expect to see in data_dictionary info in this case? There is no named record/type/object related to sample%rowtype.

like image 99
Rusty Avatar answered Sep 24 '22 22:09

Rusty