Oracle joint query. A table corresponds to the foreign keys of four tables.

Source: Internet
Author: User

Select y. *, z. Z_NAME, j. JS_NAME from t_yonghu y, t_zhan z, t_juese j where y. fk_z_id = z. z_id and y. fk_js_id = j. js_id


Select y. *, z. Z_NAME from t_yonghu y, t_zhan z where y. fk_z_id = z. z_id
Union
Select y. *, B. BZ_NAME from t_yonghu y, t_banzu B where y. fk_bz_id = B. bz_id
Union
Select y. *, j. JS_NAME from t_yonghu y, t_juese j where y. fk_js_id = j. js_id
Union
Select y. *, bu. BM_NAME from t_yonghu y, t_bumen bu where y. fk_bm_id = bu. bm_id


String SQL = "select yh_id, yh_username, yh_mima, values (fk_z_id) z_name, fk_bz_id, fk_js_id, fk_bm_id, yh_name from (select rownum r, t1. * from t_yonght1 where rownum <: y_to) t2 where t2.r>: y_from ";
Final query function:
Create or replace FUNCTION Get_BM_name_BY_ID
(
Zid in number
)
RETURN nvarchar2
Zname nvarchar2 (100 );
BEGIN
Select t. bm_name into zname from t_bumen t where t. bm_ID = zid;
RETURN zname;
END Get_BM_name_BY_ID;


Create or replace FUNCTION Get_BZ_name_BY_ID
(
Zid in number
)
RETURN nvarchar2
Zname nvarchar2 (100 );
BEGIN
Select t. bz_name into zname from t_banzu t where t. BZ_ID = zid;
RETURN zname;
END Get_BZ_name_BY_ID;


Create or replace FUNCTION Get_JS_name_BY_ID
(
Zid in number
)
RETURN nvarchar2
Zname nvarchar2 (100 );
BEGIN
Select t. js_name into zname from T_juese t where t. js_ID = zid;
RETURN zname;
END Get_JS_name_BY_ID;


Create or replace FUNCTION Get_Z_name_BY_ID
(
Zid in number
)
RETURN nvarchar2
Zname nvarchar2 (100 );
BEGIN
Select t. Z_name into zname from T_zhan t where t. Z_ID = zid;
RETURN zname;
END Get_Z_name_BY_ID;


Final query statement:
Select YH_ID, YH_USERNAME, YH_MIMA, Get_Z_NAME_BY_ID (t. FK_Z_ID) Z_name, Get_BZ_name_BY_ID (t. FK_bz_ID) bz_name, Get_BM_name_BY_ID (t. FK_BM_ID) js_name, Get_JS_name_BY_ID (t. FK_JS_ID) js_name, YH_NAME from t_yonghu t

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.