webMethods Learner

Icon

Reading, understanding, and trying to write it down

Accessing dblink using Dynamic SQL

As I had mentioned in my previous post. After I install oracle 8i machine on my XP Professional succesfully, I should create database link in my 8i and create store procedure using dynamic SQL. I need dynamic SQL because I need to build a database gateway that collect data from many resource of database machine. So, technically the database link is represented as variable i/o in the store procedure.

Here, the example code that contain dynamic sql to query specific data from table x in database link name y:

ds_numrows NUMBER; --as global variable
ds_cursor_id NUMBER; --as global variable
queryString := 'SELECT x.attr1, x.attr2 from x@y';
ds_cursor_id := DBMS_SQL.open_cursor;
DBMS_SQL.parse (ds_cursor_id, queryString, DBMS_SQL.v7);
DBMS_SQL.define_column (ds_cursor_id, 1, queryString, 1024);
ds_numrows := DBMS_SQL.EXECUTE (ds_cursor_id);
LOOP
IF DBMS_SQL.fetch_rows (ds_cursor_id) = 0
THEN
EXIT;
END IF;
DBMS_SQL.column_value (ds_cursor_id, 1, queryString );
END LOOP;
DBMS_SQL.close_cursor (ds_cursor_id);
COMMIT;

Advertisement

Filed under: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 

January 2009
M T W T F S S
« Dec    
 1234
567891011
12131415161718
19202122232425
262728293031  
Follow

Get every new post delivered to your Inbox.