How do you use TOraMetaData to get a list of tables?

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
1222tmiller
Posts: 4
Joined: Mon 14 Apr 2008 21:52

How do you use TOraMetaData to get a list of tables?

Post by 1222tmiller » Mon 22 Aug 2011 02:50

I want to get a list of all tables for a specific schema. It is clear in the documentation how to set the component and activate it, but doesn't explain how to actually get to the information.

Once I have a list of tables, I will need to retrieve the columns for a specific table. Again I get on how to add a restriction, but once active, how I get to the column information?

I am developing an adhoc query tool. Thanks.

jfudickar
Posts: 202
Joined: Fri 10 Mar 2006 13:03
Location: Oberursel / Germany

Post by jfudickar » Mon 22 Aug 2011 09:41

What about

Code: Select all

SELECT * FROM ALL_TABLES WHERE OWNER = :OWNER'
and

Code: Select all

SELECT * FROM ALL_TAB_COLUMNS WHERE TABLE_OWNER = :OWNER AND TABLE_NAME = :TABLE_NAME
Regards
Jens

1222tmiller
Posts: 4
Joined: Mon 14 Apr 2008 21:52

Post by 1222tmiller » Mon 22 Aug 2011 12:34

jfudickar wrote:What about

Code: Select all

SELECT * FROM ALL_TABLES WHERE OWNER = :OWNER'
and

Code: Select all

SELECT * FROM ALL_TAB_COLUMNS WHERE TABLE_OWNER = :OWNER AND TABLE_NAME = :TABLE_NAME
Regards
Jens
Sure I can do it that way, but then what is the MetaData component for?

AndreyZ

Post by AndreyZ » Wed 24 Aug 2011 09:13

To obtain the list of tables and the list of columns using the TOraMetaData component, you can use the following code:

Code: Select all

procedure TForm1.BitBtn1Click(Sender: TObject);
var
  strTables, strColumns: TStringList;
begin
  strTables := nil;
  strColumns := nil;
  try
    // obtaining the list of tables
    OraMetaData1.MetaDataKind := 'Tables';
    OraMetaData1.Restrictions.Values['TABLE_SCHEMA'] := '"schemaname"';
    OraMetaData1.Open;
    strTables := TStringList.Create;
    while not OraMetaData1.Eof do begin
      strTables.Add(OraMetaData1.FieldByName('TABLE_NAME').AsString);
      OraMetaData1.Next;
    end;
    OraMetaData1.Close;
    // obtaining the list of columns
    OraMetaData1.MetaDataKind := 'Columns';
    OraMetaData1.Restrictions.Values['TABLE_SCHEMA'] := '"schemaname"';
    OraMetaData1.Restrictions.Values['TABLE_NAME'] := '"tablename"';
    OraMetaData1.Open;
    strColumns := TStringList.Create;
    while not OraMetaData1.Eof do begin
      strColumns.Add(OraMetaData1.FieldByName('COLUMN_NAME').AsString);
      OraMetaData1.Next;
    end;
  finally
    if Assigned(strColumns) then
      FreeAndNil(strColumns);
    if Assigned(strTables) then
      FreeAndNil(strTables);
  end;
end;

Post Reply