Specify and use multiple libraries in ODBC connection string

后端 未结 3 1406
清酒与你
清酒与你 2020-12-18 11:33

My odbc connection string for connecting to DB2i looks like this:

Driver={Client Access ODBC Driver (32-bit)};system=xx.xx.xx.xx;dbq=LIB1 LIB2 LIB3 LIB

3条回答
  •  不思量自难忘°
    2020-12-18 11:51

    As stated above, Schema/library list is used to resolve functions/procedure names, not tables.

    Let assume you need to read data from lib1.tab1 and lib2.tab2;

    Here my personal workarounds (from easy to complex):

    a) ask the db admin to have - for each table you need to use - the corresponding schema name, then do "select * from lib1.tab1 join lib2.tab2 on [...]" ;-) b) ask the db admin to create on schema "MyAlias" several alias (create alias) for each table you want to use. Then do "set current schema=MyAlias" followed by all the SQL statement you need e.g. "select * from tab1 join tab2". Since you’re querying myalias.tab1 which is an alias pointing to table lib1.tab1 it should work.

    c) Complex: create your own SQL function that returns the corresponding schema_name for a table (e.g. myfunct('TAB1'). This could be done reading system view “qsys2.systables” where table_name=’TAB1’ and returning TABLE_SCHEMA column, which is a varchar(128). Once you got it, build up a dynamically prepared using the variable you just obtained. E.g. "set mylib = myfunct('TAB1'). "set mystmt = 'select * from '||table_schema || ‘.tab1’ …”

    Prepare mystmt and then execute mystmt.

    I did something similar in VBA using ado ibmdrda and it worked.

    hope this helps.

    f.

提交回复
热议问题