我正在使用SQL ORACLE DATABASE并创建一个表,而不是进入表空间并使用htf将表转换为html formate。
create table first_table (id number, data varchar2(25));
insert into first_table values(101, 'numberone')
insert into first_table values(202, 'numbertwo')
create table second_table (no number, data varchar2(25));
insert into second_table values(05369277635, 'phoneone')
insert into second_table values(06362190876, 'phonetwo')
DECLARE
v_html VARCHAR2(32767);
s_html VARCHAR2(32767);
BEGIN
v_html := v_html || HTF.TABLEOPEN('border="1px"');
v_html := v_html || HTF.TABLEROWOPEN;
v_html := v_html || HTF.TABLEHEADER('ID.DATA');
v_html := v_html || HTF.TABLEROWCLOSE;
s_html := s_html || HTF.TABLEOPEN('border="1px"');
s_html := s_html || HTF.TABLEROWOPEN;
s_html := s_html || HTF.TABLEHEADER('NUMBER.DATA');
s_html := s_html || HTF.TABLEROWCLOSE;
FOR i IN (SELECT * FROM first_table) LOOP
v_html := v_html || HTF.TABLEROWOPEN;
v_html := v_html || HTF.TABLEDATA(i.id||'.'||i.data);
v_html := v_html || HTF.TABLEROWCLOSE;
END LOOP;
FOR i IN (SELECT * FROM second_table) LOOP
s_html := s_html || HTF.TABLEROWOPEN;
s_html := s_html || HTF.TABLEDATA(i.no||'.'||i.data);
s_html := s_html || HTF.TABLEROWCLOSE;
END LOOP;
v_html := v_html || HTF.TABLECLOSE;
s_html := s_html || HTF.TABLECLOsE;
DBMS_OUTPUT.PUT_LINE(v_html);
DBMS_OUTPUT.PUT_LINE(s_html);
end;
我使用此代码并得到类似结果;
ID.DATA
101.numberone
202.numbertwo
NUMBER.DATA
5369277635.phoneone
6362190876.phonetwo
但是我想看到类似的样子
ID.DATA
101.numberone
NUMBER.DATA
5369277635.phoneone
ID.DATA
202.numbertwo
NUMBER.DATA
6362190876.phonetwo
每一列是否可能分开?
答案 0 :(得分:0)
那些表真的不相关吗?我假设-在现实生活中-它们之间应该有联系。如果是这样,您将使用嵌套的FOR循环,例如:
FOR i IN (SELECT * FROM first_table)
LOOP
v_html := v_html || HTF.TABLEROWOPEN;
v_html := v_html || HTF.TABLEDATA (i.ID || '.' || i.DATA);
v_html := v_html || HTF.TABLEROWCLOSE;
FOR j IN (SELECT *
FROM second_table s
WHERE s.ID = i.ID --> you'd add such a condition, to join those tables
)
LOOP
s_html := s_html || HTF.TABLEROWOPEN;
s_html := s_html || HTF.TABLEDATA (j.NO || '.' || j.DATA);
s_html := s_html || HTF.TABLEROWCLOSE;
END LOOP;
END LOOP;