473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Dynamic Sql

75
I have written code in Dbms_sql form
Can anybody tell me how to use dynamic sql for below code ,..

If possible please rewriie below code in dynamic sql form and resend it

Thanks in advance ,,,,


Expand|Select|Wrap|Line Numbers
  1.  
  2. create or replace function  utlfile_gen ( p_query     in VARCHAR2,
  3.                                           p_separator in VARCHAR2 default '~',
  4.                                           p_dir       in VARCHAR2,
  5.                                           p_filename  in VARCHAR2 )
  6. return number
  7. AUTHID CURRENT_USER
  8. is
  9.     l_output        utl_file.file_type;
  10.     l_theCursor     integer default dbms_sql.open_cursor;
  11.     l_columnValue   varchar2(2000);
  12.     l_status        integer;
  13.     l_colCnt        number default 0;
  14.     l_separator     varchar2(10) default '';
  15.     l_cnt           number default 0;
  16.     l_sql varchar2(1000);
  17. begin
  18.     l_output := utl_file.fopen( p_dir, p_filename, 'w' );
  19.  
  20.     dbms_sql.parse(  l_theCursor,  p_query, dbms_sql.native );
  21.  
  22.     for i in 1 .. 1000 loop
  23.         BEGIN 
  24.  
  25.  
  26.             dbms_sql.define_column( l_theCursor, i,l_columnValue, 2000 );
  27.             l_colCnt := i;
  28.         exception
  29.             when others then
  30.                 if ( sqlcode = -1007 ) then exit;
  31.                 else
  32.                     raise;
  33.                 end if;
  34.         end;
  35.     end loop;
  36.  
  37.     dbms_sql.define_column( l_theCursor, 1, l_columnValue,2000 );
  38.  
  39.     l_status := dbms_sql.execute(l_theCursor);
  40.  
  41.     loop
  42.         exit when ( dbms_sql.fetch_rows(l_theCursor) <= 0 );
  43.         l_separator := '';
  44.         for i in 1 .. l_colCnt loop
  45.             dbms_sql.column_value( l_theCursor, i,l_columnValue );
  46.             utl_file.put( l_output, l_separator ||l_columnValue );
  47.             l_separator := p_separator;
  48.         end loop;
  49.         utl_file.new_line( l_output );
  50.         l_cnt := l_cnt+1;
  51.     end loop;
  52.     dbms_sql.close_cursor(l_theCursor);
  53.  
  54.     utl_file.fclose( l_output );
  55.     return l_cnt;
  56. end utlfile_gen;
  57.  
Oct 8 '08 #1
5 2184
orajit
75
Can anybody rewrite the above code in execute immediate format..

Thanks
Oct 8 '08 #2
debasisdas
8,127 Expert 4TB
you simply need to frame the syntax at runtime and execute that using EXECUTE IMMEDIATE.

No need to use the old DBMS package.
Oct 8 '08 #3
orajit
75
can u please send me the updated code . Thanks in advance
Oct 8 '08 #4
orajit
75
Hi Debasis,

Can u please replace the dbms_sql to Execute immediate and resend to me,

I am using oracle 10g. dbms_sql is old way of writting the code and it has been replace by execute immediate, Thats why I wanted to use the
execute immediate into my code,

Can u please rewrite the code into execute immediate and send it to me

Thanks for ur help ..
Oct 8 '08 #5
amitpatel66
2,367 Expert 2GB
Hi Debasis,

Can u please replace the dbms_sql to Execute immediate and resend to me,

I am using oracle 10g. dbms_sql is old way of writting the code and it has been replace by execute immediate, Thats why I wanted to use the
execute immediate into my code,

Can u please rewrite the code into execute immediate and send it to me

Thanks for ur help ..

Why dont you give a try and let us know in case of any issues??
Oct 18 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Roel Wuyts | last post by:
CALL FOR CONTRIBUTIONS International Workshop on Revival of Dynamic Languages http://pico.vub.ac.be/~wdmeuter/RDL04/index.html (at OOPSLA2004, Vancouver, British Columbia, Canada, October...
1
by: Guinness Mann | last post by:
When you guys talk about "dynamic SQL," to what exactly are you referring? Is dynamic SQL anything that isn't a stored procedure? Specifically, I use ASP.NET to communicate with my SQL Server...
6
by: Materialised | last post by:
Hi Everyone, I apologise if this is covered in the FAQ, I did look, but nothing actually stood out to me as being relative to my subject. I want to create a 2 dimensional array, a 'array of...
3
by: Stephen Gennard | last post by:
Hello, I having a problem dynamically invoking a static method that takes a reference to a SByte*. If I do it directly it works just fine. Anyone any ideas why? I have include a example...
7
by: serge | last post by:
How can I run a single SP by asking multiple sales question either by using the logical operator AND for all the questions; or using the logical operator OR for all the questions. So it's always...
0
by: Pascal Costanza | last post by:
Dynamic Languages Day @ Vrije Universiteit Brussel ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Monday, February 13, 2006, VUB Campus Etterbeek The VUB (Programming Technology Lab,...
7
by: Mike Livenspargar | last post by:
We have an application converted from v1.1 Framework to v2.0. The executable references a class library which in turn has a web reference. The web reference 'URL Behavior' is set to dynamic. We...
1
by: Peterwkc | last post by:
Hello all expert, i have two program which make me desperate bu after i have noticed the forum, my future is become brightness back. By the way, my problem is like this i the first program was...
5
by: bearophileHUGS | last post by:
I often use Python to write small programs, in the range of 50-500 lines of code. For example to process some bioinformatics data, perform some data munging, to apply a randomized optimization...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.