我可以创建“逻辑文件”吗?在AS400中使用sql?

发布于 2024-10-15 08:28:07 字数 122 浏览 3 评论 0原文

我需要创建 as400“逻辑文件”。

我的应用程序使用 jdbc 连接到数据库。

是否可以用sql语句创建“逻辑文件”?

如果是的话,我希望能提供一份示例声明。

谢谢

I need to create as400 "logical files".

my app connects to the db with jdbc.

Is it possible to create "logical files" with sql statements ?

If yes I would appreciate a sample statement.

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

红玫瑰 2024-10-22 08:28:07

我建议使用绿屏 STRSQL 命令中的 CREATE INDEX SQL 命令。然后就可以提示了。下面是 CREATE INDEX 的示例,它可以让我更快地查询 16 GB 文件。对于此示例,物理文件是数据库监视器运行一周的结果:

CREATE INDEX QGPL.QZG0000016_QUERYJOB ON QGPL.QZG0000016
(QQJNUM ASC, QQUSER ASC, QQJOB ASC, QQUCNT ASC, QQRID ASC, QQI5 ASC)

索引本身需要很长时间才能创建,但基于索引的后续查询非常快。

如果您需要连接多个表,请提前计划。了解将用于连接表的字段并针对连接的表创建索引。您将获得所需的性能提升。例如,让我们创建一个查询来显示客户订购的商品:

SELECT ORDETAIL.ITEM_NAME, ORDETAIL.QUANTITY, ORHEADER.SHIPDATE
FROM ORHEADER
INNER JOIN ORDETAIL ON ORDETAIL.ORDERID = ORHEADER.ORDERID
WHERE ORHEADER.CUST_NUM = 123456

您将创建以下索引(如果它们尚不存在):

CREATE INDEX DATALIB.ORHEADER_BY_CUSTOMER ON DATALIB.ORHEADER (CUST_NUM ASC, ORDERID)
CREATE INDEX DATALIB.ORDETAIL_BY_ORDER ON DATALIB.ORDETAIL (ORDERID)

如果您需要创建一个逻辑文件选择/省略条件,那么您需要创建一个视图。不过,视图不是索引,并且您不能像使用带有 select/omits 的键控逻辑那样混合索引和视图。为此,DDS 规范仍然是最好的。

I suggest making use of the CREATE INDEX SQL command from the green-screen STRSQL command. Then you can prompt it. Here is an example of CREATE INDEX that let me query a 16 gigabyte file much faster. For this example, the physical file was the results of a database monitor than ran for a week:

CREATE INDEX QGPL.QZG0000016_QUERYJOB ON QGPL.QZG0000016
(QQJNUM ASC, QQUSER ASC, QQJOB ASC, QQUCNT ASC, QQRID ASC, QQI5 ASC)

The index itself took a long time to create, but subsequent queries based on the index were very fast.

If you need to join multiple tables, plan ahead. Know the fields you will use to join the tables and create indexes against the joined tables. You'll get the performance increase you're looking for. For an example, let's make up a query to show the items ordered by a customer:

SELECT ORDETAIL.ITEM_NAME, ORDETAIL.QUANTITY, ORHEADER.SHIPDATE
FROM ORHEADER
INNER JOIN ORDETAIL ON ORDETAIL.ORDERID = ORHEADER.ORDERID
WHERE ORHEADER.CUST_NUM = 123456

You would make the following indexes, if they didn't already exist:

CREATE INDEX DATALIB.ORHEADER_BY_CUSTOMER ON DATALIB.ORHEADER (CUST_NUM ASC, ORDERID)
CREATE INDEX DATALIB.ORDETAIL_BY_ORDER ON DATALIB.ORDETAIL (ORDERID)

If you need to create a logical file select/omit criteria, then you need to create a view. A view is not an index, though, and you can't mix an index and a view like you can with a keyed logical with select/omits. For that, a DDS spec is still the best.

仅此而已 2024-10-22 08:28:07

如果您尝试根据您的视图进行排序,这将有所帮助,但如果您遇到性能问题,这不会真正有帮助。

数据示例basetable

A 
B 
C 
A 
A 
A 

查询:

create view myview1  as                   
select lib                                
from(                                     
  SELECT rank() over(order by lib), lib   
FROM basetable) a   

来自myview1的数据示例

A 
A 
A 
A 
B 
C 

This will help if you are trying to an order by on your view, but will not really help if you have a performance issue.

Sample of data basetable:

A 
B 
C 
A 
A 
A 

Query:

create view myview1  as                   
select lib                                
from(                                     
  SELECT rank() over(order by lib), lib   
FROM basetable) a   

Sample of data from myview1

A 
A 
A 
A 
B 
C 
山人契 2024-10-22 08:28:07

为了达到大致相同的效果,我在 AS/400 DB2 中的所有表上创建了数据库视图,将更容易理解的名称映射到物理名称。我不认为视图是逻辑文件,但我只是所说的 AS/400 的用户,并且对它的了解与与数据交互所需的一样多。

To achieve much of the same effect, I've created database views over all the tables in an AS/400 DB2, mapping more understandable names to the physical ones. I don't think views are logical files, but I'm just a user of said AS/400 and know exactly as much about it as needed to interact with the data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文