If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Informix > how to change execution context in the SPL procedure

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-17-11, 10:42
phan phan is offline
Registered User
 
Join Date: Feb 2011
Posts: 5
how to change execution context in the SPL procedure

Hi,

I am new to Informix. I just want to change the execution context in the SPL by:

Database myDBName;

however, it gave me an error:

Illegal SQL statement in stored procedure


Does anybody know how to change the execution context so that I do not need to prefix all object by "myDBName:" ?

Any help will be appreciated.

thanks,
Paul
Reply With Quote
  #2 (permalink)  
Old 03-11-11, 15:38
InformixWilli InformixWilli is offline
Registered User
 
Join Date: Sep 2010
Location: Germany, Brunswick
Posts: 52
In 11.50 is thats not possible: "...you cannot close the current database or connect to a new database within an SPL routine."

SQL Statements Valid in SPL Statement Blocks

You must create the stored procedure in the right database or you write "<db>:<tabname>" or you try something like that:

Code:
create procedure test (db char(50)) returning int;
  define x int;
                   
  prepare xsql from 'select count(*) from '||db||':customer';
  declare xcur cursor for xsql;
  OPEN xcur;
  FETCH xcur into x;
  CLOSE xcur;
  FREE xcur;
  FREE xsql;
  
  return x;
end procedure;

execute procedure test("stores_demo");
execute procedure test("stores_demo_big");
Result:
Code:
(expression)

          28

(expression)

      458752
__________________
WilhelmW
IBM Certified Database Associate

wilhelmw.de - www.isr.de
Reply With Quote
  #3 (permalink)  
Old 03-15-11, 10:46
phan phan is offline
Registered User
 
Join Date: Feb 2011
Posts: 5
thanks. That is really helpful.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On