2012-08-07 69 views
1

我们有一个相当大的Oracle数据库,我们可以通过Microsoft Access和ODBC以只读访问进行连接。我们使用与幕后结构不匹配的前端系统,并且经常需要通过Microsoft Access查询系统。问题是我们没有提供关于结构的任何文件,并且结构需要认真关注。搜索我需要的字段非常耗时。Microsoft Access在已知值的表中找到字段

使用我们的前端,我可以查看我想要查询的值,并且知道关键字段,但是我需要找到包含已知值的字段。

如果我有一个记录,我知道字段“A”的值,并具有字段“X”的值,是否可以查询字段“X”?

前端显示

Student ID: 12345678 
Payments: 23456 

后端

TechID: 12345678 
???: 23456 

我可以查询 “???”

回答

2

您可以遍历表的集合,并为每个表迭代字段集合。

Open Database 
Get all Tables 
For Each Table 
    Get all Fields 
    For Each Field 
     If Field type is text ... and 
     If Field size is not TOO Long ... 
      Search for string 
      If found, write to a results bucket 
    Next 
Next 

这里是编目表(来源here

Public Function GenerateDataDictionary(aDataDictionaryTable As String) 
'***  Usage: GenerateDataDictionary("MyDataDictionaryTable") 
'*** Extracts the information about the tables for the data dictionary 
'*** and inserts it to a table named aDataDictionaryTable 

    Dim tdf As TableDef, fldCur As Field, colTdf As TableDefs 
    Dim rstDatadict As Recordset 
    Dim i As Integer, j As Integer, k As Integer 
    Set rstDatadict = CurrentDb.OpenRecordset(aDataDictionaryTable) 
    Set colTdf = CurrentDb.TableDefs 

    'Go through the database and get a tablename 
    For Each tdf In CurrentDb.TableDefs 
    'Do what you want with the table names here. 
    rstDatadict.AddNew 
    rstDatadict.Update 
rstDatadict.AddNew 
    rstDatadict![Table] = tdf.NAME 
    rstDatadict![Field] = "----------------------------" 
    rstDatadict![Display] = "----------------------------" 
    rstDatadict![Type] = "" 
    rstDatadict.Update 
    rstDatadict.AddNew 
    rstDatadict![Table] = "Table Description:" 
    For j = 0 To tdf.Properties.Count - 1 
      If tdf.Properties(j).NAME = "Description" Then 
       rstDatadict![Field] = tdf.Properties(j).Value 
      End If 
    Next j 

    rstDatadict.Update 
    rstDatadict.AddNew 
    rstDatadict.Update 

For i = 0 To tdf.Fields.Count - 1 
      Set fldCur = tdf.Fields(i)   
      rstDatadict.AddNew 
      rstDatadict![Table] = tdf.NAME 
      rstDatadict![Field] = fldCur.NAME 
      rstDatadict![Size] = fldCur.Size 

      Select Case fldCur.Type 
      Case 1 
       FieldDataType = "Yes/No" 
      Case 4 
       FieldDataType = "Number" 
      Case 8 
       FieldDataType = "Date" 
      Case 10 
       FieldDataType = "String" 
      Case 11 
       FieldDataType = "OLE Object" 
      Case 12 
       FieldDataType = "Memo" 
      Case Else ' Other values. 
       FieldDataType = fldCur.Type 
      End Select 

      rstDatadict![Type] = FieldDataType         
       For j = 0 To tdf.Fields(i).Properties.Count - 1 
        If fldCur.Properties(j).NAME = "Description" Then 
         rstDatadict![DESCRIPTION] = fldCur.Properties(j).Value 
        End If 

        If fldCur.Properties(j).NAME = "Caption" Then 
         rstDatadict![Display] = fldCur.Properties(j).Value 
        End If 

        If fldCur.Properties(j).NAME = "Rowsource" Then 
         rstDatadict![LookupSQL] = fldCur.Properties(j).Value 
        End If 
       Next j 

      rstDatadict.Update 

    Next i 
    Debug.Print " " & tdf.NAME 
    Next tdf 

End Function 

您可以通过现场名称的表格,其连接向表的表Catalog您发现在Access中的代码示例名。然后,您的搜索基于目录而不是原始集合。

这样我反向设计了MAS 90(带有JobOps加载项)的模式。没有地图,但我有一个只读的ODBC连接,我按照您的建议使用。采购会计师会给我一个独特的产品编号,我会通过这个综合的引擎来运行它。随着时间的推移,我成功地蒸馏了包括18k场至20桌和几百场的700张桌子。这使我们能够导出我们的数据。

+0

我追踪了新的链接,现在它应该可以工作。恭喜,我们不是盲人。 – Smandoli 2012-12-19 21:01:45

+1

谢谢,S.我打算以后再玩。在这里我喜欢用'OpenRecordset'的'dbAppendOnly'。这个选项似乎加快了行增加。再次感谢。 – HansUp 2012-12-19 21:21:28

1

您的问题的答案很简单。不,你不能那样做。

我可以想到两种解决方案。首先是将所有值手动连接在一起,然后查找包含该值的行。这是不完美的,但可能工作:

select * 
from (select t.*, ('|'""col1||'|'||col2+'|' . . .||'|') as allcols 
     from t 
    ) t 
where instr('|23456|', allcols) > 0 

这将找到在列中具有该值的任何行。可能足够接近你想要的东西。

其次是使用UNPIVOT做基本相同的事情。

我强烈建议您花一点时间来查找字段之间的映射,然后在Oracle中创建一个具有应用程序中所示字段名称的视图。这听起来似乎会在中期为您节省很多努力。

相关问题