Skip to Main Content
  • Questions
  • Creating view with size 40K on remote DB using DBMS_SQL.PARSE

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Dinker.

Asked: April 17, 2014 - 7:05 pm UTC

Last updated: April 23, 2014 - 10:36 pm UTC

Version: 11.2.0

Viewed 10K+ times! This question is

You Asked

Hi Tom,
This is my first post here. First of all let me thank you for all the help i got from your site over the years. :)
Now the issue, I am trying to create a view from local DB (11.2.0.3) into remote DB (10.2.0.4).
my code worked for smaller size views till now having size less then 32K. it is failing for a view with 39K+ characters.
I googled and found that i can use following variation of parse, but it gives me error:PLS-00306: wrong number or types of arguments in call to 'PARSE'

DBMS_SQL.PARSE (
c IN INTEGER,
statement IN VARCHAR2A,
lb IN INTEGER,
ub IN INTEGER,
lfflg IN BOOLEAN,
language_flag IN INTEGER);

 DECLARE 
 l_var number; 
 l_in_cursor   NUMBER;
 l_stmt        VARCHAR2(32000);
 g_db_link varchar2(100) := '@ABC.xyz.com';
 l_sql         CLOB;
 l_split_stmt DBMS_SQL.VARCHAR2A;  
       
 BEGIN 
   l_stmt     := 'SELECT DBMS_SQL.OPEN_CURSOR'||g_db_link||' FROM DUAL';

   EXECUTE IMMEDIATE l_stmt INTO l_in_cursor;
    l_var :=l_in_cursor; 
    
    SELECT a.query
    into L_SQL
    FROM test_hlb01_qry a
    where program_log_dtls_seq_no=11;
        
if length(L_SQL)> 25000 then
    l_split_stmt(1):= substr(l_sql,1,instr(l_sql, ',', 10000));
    l_split_stmt(2):= substr(l_sql,instr(l_sql, ',', 10000)+1,instr(l_sql, ',', 20000));
    l_split_stmt(3):= substr(l_sql,instr(l_sql, ',', 20000)+1,instr(l_sql, ',', 30000));
    l_split_stmt(4):= substr(l_sql,instr(l_sql, ',', 30000)+1,instr(l_sql, ',', 40000));
    DBMS_SQL.PARSE@ABC.xyz.com (l_var,l_split_stmt,1,2,TRUE, dbms_sql.native); 
else
    DBMS_SQL.PARSE@ABC.xyz.com (l_var,L_SQL, dbms_sql.native); 
end if;

 DBMS_SQL.CLOSE_CURSOR@ABC.xyz.com(l_var); 
 END;
 /


here else part worked fine till now. the if part is what i added to handle bigger view creating which is failing.

Please Help.!!

and Tom said...

you would have to use the remote type as well

l_split_stmt DBMS_SQL.VARCHAR2A;

that uses the "local" type, which is not the same as the "remote type".

but you won't be able to use the remote type, since the db link is not known at compile time. Or is it, I don't know why you are using execute immediate to get the cursor - but then statically reference abc.xyz.com later....


but, in any case, what you would be able to do is build a block of code similar to:


declare
    l_cursor number;
    l_data   dbms_sql.varchar2a;
begin
    l_cursor := dbms_sql.open_cursor;
    l_data(1) := :bv1;
    l_data(2) := :bv2;
    l_data(3) := :bv3;
    ..... if the max statement you want to support is 320k, do that 10 times..... for example ...
    dbms_sql.parse( .... );
    dbms_sql.close_cursor(l_cursor);
end;





so, that is the sql statement you want to parse at the remote site. parse that remotely, bind to it (binding NULL if there isn't anything to be added at the end - just bind 10 strings) and then execute it.


Rating

  (4 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Thanks for help

Dinker Joshi, April 24, 2014 - 3:23 pm UTC

Thanks Tom.
following change in Declare:
l_split_stmt DBMS_SQL.VARCHAR2A@ABC.xyz.com;

and little correction in substr solved the problem.

l_split_stmt(1):= substr(l_sql,1,instr(l_sql, ',', 10000));
l_split_stmt(2):= substr(l_sql,instr(l_sql, ',', 10000)+1,instr(l_sql, ',', 20000)-instr(l_sql, ',', 10000));
l_split_stmt(3):= substr(l_sql,instr(l_sql, ',', 20000)+1,instr(l_sql, ',', 30000)-instr(l_sql, ',', 20000));
l_split_stmt(4):= substr(l_sql,instr(l_sql, ',', 30000)+1);

Clarification

Dinker Joshi, April 24, 2014 - 3:32 pm UTC

Actually I sent you simplyfied pl/sql block wiht the portion of code which was failing and your respose of using remote type was to the point. In actual code i am generating this pl/sql block dynamically and parsing in local DB which in turn parse the view in remote DB.

NY chamane

nomathemba yvonne chamane, July 02, 2014 - 2:09 pm UTC

I'm a disable but I I have a big problem I didn't. Find my disable grant for this month

same experience level

A reader, October 10, 2014 - 3:39 pm UTC

I have same experience as you. I started working in 1992 and on oracle 6 on 1993

More to Explore

CLOB/BLOB/etc

Complete documentation on Securefiles and Large Objects here