English 中文(简体)
2. 具有相同图象的多表,问询设计战略?
原标题:Multi tables with same schema, query design strategy?

我有一个信标设计的Oracle数据库:许多表格都有相同的图象。 它们从一个庞大的桌子中重新 pieces,并随着时间的推移,将设立新的桌子。 当然,我没有获准进入庞大的桌子,只有小桌。 我如何有效地质疑这些表格?

很多人预先表示感谢。

问题回答

AFAIK,如果是你所说的的话,就没有办法对多个不同的表格使用一份单一的发言稿。 你们是否可以认为,所有表格都有联盟?

你们可以发挥编织职能,积极制定从所有相关表格中选取的LQ声明。

--Create tables.  They can be created at any time, but they have
--to follow some sort of naming convention
create table temp1(test1 number, test2 varchar2(100));
create table temp2(test1 number, test2 varchar2(100));
create table temp3(test1 number, test2 varchar2(100));


--Create a package that will return one result at a time from all the tables.
create or replace package query_tables is
  type output_rectype is record
  (
    test1 number
    ,test2 varchar2(100)
  );
  type output_rectype_table is table of output_rectype;
  function query return output_rectype_table pipelined;
end query_tables;
/


create or replace package body query_tables is
  function query return output_rectype_table pipelined is
    sql_statement varchar2(32767);
    output output_rectype;
    my_cursor sys_refcursor;
  begin
    --Build a select statment that combines all relevant tables
    for tables in (select table_name from user_tables where table_name like  TEMP% ) loop
      sql_statement := sql_statement ||  select * from  ||tables.table_name||  union all  ;
    end loop;
    --Remove the last  union all 
    sql_statement := substr(sql_statement, 1, length(sql_statement) - 11);

    --Get one result at a time and return it
    open my_cursor for sql_statement;
    loop
      fetch my_cursor into output;
      exit when my_cursor%notfound;
      pipe row(output);
    end loop;
  end;
end query_tables;
/


--Insert some test data
insert into temp1 values(1,  asdf );
insert into temp2 values(2,  fgds );
insert into temp3 values(3,  rewq );


--Display the results from all tables with one query
select * from table(query_tables.query);




相关问题
what is wrong with this mysql code

$db_user="root"; $db_host="localhost"; $db_password="root"; $db_name = "fayer"; $conn = mysqli_connect($db_host,$db_user,$db_password,$db_name) or die ("couldn t connect to server"); // perform query ...

Users asking for denormalized database

I am in the early stages of developing a database-driven system and the largest part of the system revolves around an inheritance type of relationship. There is a parent entity with about 10 columns ...

Easiest way to deal with sample data in Java web apps?

I m writing a Java web app in my free time to learn more about development. I m using the Stripes framework and eventually intend to use hibernate and MySQL For the moment, whilst creating the pages ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

How can I know if such value exists in database? (ADO.NET)

For example, I have a table, and there is a column named Tags . I want to know if value programming exists in this column. How can I do this in ADO.NET? I did this: OleDbCommand cmd = new ...

Convert date to string upon saving a doctrine record

I m trying to migrate one of my PHP projects to Doctrine. I ve never used it before so there are a few things I don t understand. In my current code, I have a class similar to this: class ...

热门标签