Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle Procedure

create or replace function gen.sample_func(owner varchar2) return varchar2 
    as 
     data_t varchar2(10); 
      cursor cur is   select  data_type  from  SYS.DBA_TAB_COLUMNS;
      begin  
        open cur;
          dbms_output.put_line('Done'); 
        close cur; 
        return data_t;  
    end sample_func;

On compiling the above function i get the following error

Warning: compiled but with compilation errors
Errors for FUNCTION sample_func

LINE/COL                                                                        
--------------------------------------------------------------------------------
ERROR                                                                           
--------------------------------------------------------------------------------
4/8                                                                             
PLS-00201: identifier 'DBA_TAB_COLUMNS' must be declared                        

4/8                                                                             
PL/SQL: Item ignored                                                            

7/15                                                                            
PLS-00320: the declaration of the type of this expression is incomplete or malfo
rmed                                                                            

7/8                                                                             
PL/SQL: Statement ignored                                                       

I'm not getting this error when i execute the select statement alone in the cursor. Please help me to resolve this issue.

like image 474
Vivek Avatar asked Aug 30 '26 13:08

Vivek


1 Answers

Your user needs to be granted SELECT ON DBA_TAB_COLUMNS.

Note that granting through a role will not work - it needs to be a direct grant to the user for you to create a function/procedure.

like image 177
cagcowboy Avatar answered Sep 01 '26 06:09

cagcowboy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!