oracle拼接字符串
在Oracle中,可以使用||
运算符或CONCAT
函数来拼接字符串。
使用||
运算符:
SELECT 'Hello, ' || 'World!' AS concatenated_string FROM dual;
使用CONCAT
函数:
SELECT CONCAT('Hello, ', 'World!') AS concatenated_string FROM dual;
orcle查询重复数据
在Oracle数据库中,查询重复数据通常意味着你想找出那些在特定列或列组合中有重复值的行。以下是一个示例SQL查询,它找出在your_table
表中duplicate_column
列上有重复值的所有行:
SELECT duplicate_column, COUNT(*)
FROM your_table
GROUP BY duplicate_column
HAVING COUNT(*) > 1;
如果你想获取重复数据的所有列信息,可以使用以下查询:
SELECT *
FROM your_table
WHERE duplicate_column IN (
SELECT duplicate_column
FROM your_table
GROUP BY duplicate_column
HAVING COUNT(*) > 1
);
如果你想获取重复数据的所有列信息,并且希望保留重复数据中的一个记录,其余的标记为重复,可以使用以下查询:
SELECT a.*, 'Duplicate' as duplicate_flag
FROM your_table a
WHERE a.rowid = (
SELECT min(b.rowid)
FROM your_table b
WHERE a.duplicate_column = b.duplicate_column
GROUP BY b.duplicate_column
HAVING COUNT(*) > 1
)
UNION ALL
SELECT a.*, 'Duplicate' as duplicate_flag
FROM your_table a
JOIN (
SELECT duplicate_column
FROM your_table
GROUP BY duplicate_column
HAVING COUNT(*) > 1
) b ON a.duplicate_column = b.duplicate_column
AND a.rowid <> (SELECT min(c.rowid) FROM your_table c WHERE c.duplicate_column = b.duplicate_column);
举个栗子
select xjh || '@' || xxdm,count(*)
from stu_info
group by xjh || '@' || xxdm
having count(*) > 1