我在Oracle中有包含以下各列的表;
ID NIC NTN MBL NAME
---------------------------------------
1 1234512 ABC
2 321 XYZ
3 5421 POI
4 541245 624
我需要在选择查询中显示这样
ID NIC/NTN/MBL NAME
1 1234512 ABC
2 321 XYZ
3 5421 POI
4 541245 // taking first value
我正试图与
SELECT
A.ID,
"CNIC/NTN/MBL"
A.NAME,
A.REASON
B.NAME
FROM TABLEA A
INNER JOIN TABLEB B ON A.R_ID = B.R_ID
UNPIVOT INCLUDE NULLS
(
CNIC/NTN/MBL FOR cols IN (A.NIC, A.NTN, A.MBL)
)
但是不能做。
答案 0 :(得分:3)
使用COALESCE
:
SELECT
ID,
COALESCE(NIC, NTN, MBL) AS "NIC/NTN/MBL",
NAME
FROM yourTable;
这应该起作用,因为在上面对COALESCE
的调用中,我从左到右列出了三列,并且会保留 first 非NULL
的值。 / p>
答案 1 :(得分:2)
您需要COALESCE函数(该函数简单地返回指定输入中的第一个非空值,从左到右读取),如下所示:
if (extras != null) {
final int position = extras.getInt("position");
sparkButton1.setEventListener(new SparkEventListener() {
@Override
public void onEvent(ImageView button, boolean buttonState) {
if (position == 0) {
Toast.makeText(PlayVideo.this, "welcome", Toast.LENGTH_LONG).show();
} else if (position == 1) {
Toast.makeText(PlayVideo.this, "exit", Toast.LENGTH_LONG).show();
}
}