Home > database >  Oracle in the select statement
Oracle in the select statement

Time:09-24

Function: if the table 2 a look-up table is empty, otherwise the query table 1
If the exists (select 0 from table2)
Select * from table 1
The else
Select * from table 2
Such statements are not achieve them, how to write in oracle

CodePudding user response:

Declare v_count int.
The begin
Select count (*) into v_count from t1;

If v_count & gt; 0 then
Statements 1
The else
Statements 2
end;
end;

CodePudding user response:

Declare v_count int.
The begin
Select count (*) into v_count from t1;

If v_count & gt; 0 then
Statements 1
The else
Statements 2
end if;
end;

CodePudding user response:

refer to the second floor wmxcn2000 response:
declare v_count int.
The begin
Select count (*) into v_count from t1;

If v_count & gt; 0 then
Statements 1
The else
Statements 2
end if;
end;
agree, the original poster is empty, you want to make sure of table 2 can be used for instance ID count count mode (it is better to must not be empty fields), after the search if count=0 means that is empty, is not greater than 0 is empty

CodePudding user response:

Function: if the table 2 a look-up table is empty, otherwise the lookup table 1?????? It is not a look-up table??

Estimate is to realize the function: if the table 2 a look-up table is empty, otherwise the lookup table 2

Use stored procedures can realize

First to define a variable
CNT int variables -- plastic CNT
- then the query table 2 is empty
Select count (*) into the from CNT table2
- the last according to the result of the above query which query table
If cnt> 0 then
Select * form table2
The else
Select * form table1
Tell you that train of thought, specific code change according to your program

CodePudding user response:

Declare v_count int.
The begin
Select count (*) into v_count from t1;

If v_count & gt; 0 then
Select * from table 1
The else
Select * from table 2
end if;
end;

CodePudding user response:

reference 5 floor qq_37252813 reply:
end;
ORACLE seems can not directly use the select of seemingly in block must be into

CodePudding user response:

This can be directly found out

 
Select * from DEPT2
The UNION
Select * from DEPT WHERE 0=(select COUNT (*) from DEPT2)

CodePudding user response:

The
reference 7 floor gaojiagang response:
this can be directly found out

 
Select * from DEPT2
The UNION
Select * from DEPT WHERE 0=(select COUNT (*) from DEPT2)
young man

CodePudding user response:

refer to the eighth floor qq_28538637 response:
Quote: refer to 7th floor gaojiagang response:

This can be directly found out

 
Select * from DEPT2
The UNION
Select * from DEPT WHERE 0=(select COUNT (*) from DEPT2)
young man

Table structure not different, if the table structure is the same, is no problem,

CodePudding user response:

This post writes very carefully
http://blog.csdn.net/hollboy/article/details/7550171

CodePudding user response:

 http://bbs.csdn.net/topics/392138410#new_post

CodePudding user response:

 
DECLARE
V_tmp NUMBER:=0;
V_result NUMBER;
The BEGIN
SELECT COUNT (*) INTO v_tmp FROM student;
IF v_tmp & lt;=0 THEN
Dbms_output. Put_line (' an execute table2);
The ELSE
Dbms_output. Put_line (' an execute table1);
END IF;
END;

CodePudding user response:

 
Words, while Oracle not if the exists (... )
But I can you can write

Declare v_count int.
The begin
Select count (*) into v_count from t1;

If v_count & gt; 0 then
Select * from table 1
The else
Select * from table 2
end if;
end;


  • Related