简体   繁体   中英

How to combine two pl/sql select statement

I am having 3 select statement with same tables but with different columns and I want to give result in single set of result if I give input as 1 then it should run 1st select statement if I give 2 input it should run 2nd select statement. And I am sorry I can't copy my code here as it is too big and security purposes of my office work so can any one please suggest the ways to do it.and I am new to plsql so it's very difficult for me to find on google

what I understand you need to create two select depend to specific condition: You will play on param1 and param2 value like that:

CREATE OR REPLACE PROCEDURE my_sp (param1 VARCHAR2, param2 VARCHAR2)
IS
BEGIN
    IF param1 IS NULL AND param2 IS NOT NULL THEN
        SELECT ...
        INTO ... -- Assumed
        FROM ...
        WHERE my_column = p_DrumNo;
    ELSE
        SELECT ...
        INTO ... -- Assumed
        FROM ...
        WHERE ORDER_ID IN (SELECT ORDER_ID FROM ORDERDELIVERY);
    END;
END;

Notice: the attribute that I used on this example is a random example , don't forget to change it by your attributes .

I hope that can help you to resolve your issue.

Use a union , here is a single row example of pulling different columns:

with t as (
    select 1 ID, 'Hello World' col1, 50 col2, 'abc' col3, 'col4' col4 from dual
)
select ID
    , Col4
from t
where 1 = 1 --Replace left side 1 with var here

union all

select col2
    , col3
from t
where 1 = 2 --Replace left side 1 with var here

You'll need to adjust your data types to match for each column order, and they'll have to have the same number of columns, but anything with less columns than your largest query can just have a bunch of select null, null, null where you don't need data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM