首先使用SQL的记录和以前的记录

发布于 2025-01-25 19:51:14 字数 464 浏览 3 评论 0原文

我有一个文件需要将数据插入看起来像这样的表中:

“在此处输入图像说明”

我需要将每个记录与DTL开始的每条记录与以DT2开头的记录开头。

在Informatica中,Soultion看起来像这样:

​/I.SSTATIC.NET/RRQQQ.PNG“ ALT =”在此处输入图像描述“>

文件仅像一列一样加载。

I have a file from which I need to insert data into table that looks like this:

enter image description here

I need to concatenate every record that starts with DTL with the record that starts with DT2 behind it.

In Informatica that soultion looks like this:

enter image description here

enter image description here

The file is loaded like one column only.

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

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

发布评论

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

评论(3

待"谢繁草 2025-02-01 19:51:14

对于上一行结果,也可以使用滞后 -

with data_cte as 
(SELECT column1 from values
 ('ABCfs'),
 ('DT2ad'),
 ('DTLskf'),
 ('DT2etv'),
 ('DTLbrf'),
 ('DT2tf'),
 ('ABCbr'),
 ('DT2g6'),
 ('DTLdh'),
 ('DT2jw')
 ), c_p_cte as
 (
 select substr(column1,1,3) column1,lag(substr(column1,1,3)) 
over (order by null) column2 from data_cte 
 )
 select case 
 when column1='DTL' and column2='DT2' then column1||column2
 else column1
 end col_val
 from c_p_cte;

在上述查询中,结果为 -

COL_VAL
-------
ABC
DT2
DTLDT2
DT2
DTLDT2
DT2
ABC
DT2
DTLDT2
DT2

For previous row result, LAG can also be used -

with data_cte as 
(SELECT column1 from values
 ('ABCfs'),
 ('DT2ad'),
 ('DTLskf'),
 ('DT2etv'),
 ('DTLbrf'),
 ('DT2tf'),
 ('ABCbr'),
 ('DT2g6'),
 ('DTLdh'),
 ('DT2jw')
 ), c_p_cte as
 (
 select substr(column1,1,3) column1,lag(substr(column1,1,3)) 
over (order by null) column2 from data_cte 
 )
 select case 
 when column1='DTL' and column2='DT2' then column1||column2
 else column1
 end col_val
 from c_p_cte;

With above query, it results as -

COL_VAL
-------
ABC
DT2
DTLDT2
DT2
DTLDT2
DT2
ABC
DT2
DTLDT2
DT2
一生独一 2025-02-01 19:51:14

尝试这样的东西:

with 
t_rownum as 
(SELECT data_string,
 ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) AS rownum
FROM TEMP_TABLE),
t_dtl as (select * from t_rownum where SUBSTRING(DATA_STRING,1,3)='DTL'),
t_dt2 as (select * from t_rownum where SUBSTRING(DATA_STRING,1,3)='DT2'),
t_dtl_2 as (select 
t_dtl.data_string || t_dt2.data_string as data_string
from t_dtl inner join t_dt2 on t_dtl.rownum=t_dt2.rownum-1)
SELECT
DATA_STRING
FROM t_dtl_2 WHERE SUBSTRING(DATA_STRING,1,3)='DTL'
and SUBSTRING(DATA_STRING,255,3)='DT2'
;

Try with something like this:

with 
t_rownum as 
(SELECT data_string,
 ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) AS rownum
FROM TEMP_TABLE),
t_dtl as (select * from t_rownum where SUBSTRING(DATA_STRING,1,3)='DTL'),
t_dt2 as (select * from t_rownum where SUBSTRING(DATA_STRING,1,3)='DT2'),
t_dtl_2 as (select 
t_dtl.data_string || t_dt2.data_string as data_string
from t_dtl inner join t_dt2 on t_dtl.rownum=t_dt2.rownum-1)
SELECT
DATA_STRING
FROM t_dtl_2 WHERE SUBSTRING(DATA_STRING,1,3)='DTL'
and SUBSTRING(DATA_STRING,255,3)='DT2'
;
木落 2025-02-01 19:51:14

整行数据似乎被读为一个record_detail端口(将其视为列)。因此,该单个端口被加载到目标数据库中的单列中。

为了将单独的列加​​载,您需要将文件读取为划界。在这种情况下,使用管道(|)作为定界符。

现在,您提到您需要“串联每个记录” - 对我的理解,这意味着将所有行的所有列串联。这正是那里发生的事情。

Whole row of data seems to be read into one RECORD_DETAIL port (think of that as a column). Hence, this single port is loaded into single column in your target DB.

In order to have separate columns loaded, you need to read the file as a delimited one. In this case using pipe (|) as the delimiter.

Now, you mention you need to "concatenate every record that" - to my understanding this would mean concatenating all columns of all rows. And this is exactly what happens there.

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