1.多个like
写oracle sql时有时候会有 and (字段 like ‘匹配串1’or 字段 like ‘匹配串2’or ...)这样的情况出现,下面提供一个简洁点的解决方案--
and REGEXP_LIKE(字段名, '(匹配串1|匹配串2|...)') //全模糊匹配
and REGEXP_LIKE(字段名, '^(匹配串1|匹配串2|...)') ";//右模糊匹配
and REGEXP_LIKE(字段名, '(匹配串1|匹配串2|...)$') ";//左模糊匹配
----原出处转自:oracle 字段like多个条件(or关系)_kenry121212的博客-CSDN博客
2 SSRS
2.1:CASE WHEN:值判断
(case when count(distinct b.rcard) > a.PLANQTY then a.PLANQTY else count(distinct b.rcard) end) cct,
将日期转变为:yyyy/mm/dd格式
to_date(min(b.shiftday), 'YYYY-MM-DD') minxxdate,
3.有时候前端一个字段会传入多个值,如何查询
SELECT COLUMN_VALUE
FROM TABLE(split(:itemname, ','))
当检测到字符串含有‘,’时,就分割出一个元素,并使其为一个table中的列值。SELECT COLUMN_VALUE 可以检索出刚才自己分割的列值。
例:
select *from tabname a where (a.billno in (select COLUMN_VALUE from table(split(:bilno,','))))
4.写一个function,实现根据指定长度添加字符串
例如:abcdefg 2 _ 变成: ab_cd_ef_g
FUNCTION GET_Str_by_length(p_var_in VARCHAR2, --原始字符串
p_spl_in VARCHAR2, --分隔符
p_step_in Number --间隔长度
) RETURN VARCHAR2 IS
V_PROC_NAME VARCHAR2(80) := 'GET_Str_by_length';
n_length number(18);
n_count number(18);
v_temp VARCHAR2(4800);
v_string VARCHAR2(4088);
BEGIN
n_count := 0;
v_temp := '';
v_string := p_var_in;
select ceil(length(v_string) / p_step_in) into n_length from dual;
for n_count in 1 .. n_length Loop
if length(v_string) > p_step_in Then
v_temp := v_temp || substr(v_string, 0, p_step_in) ||
p_spl_in;
v_string := substr(v_string,
p_step_in + 1,
length(p_var_in));
else
v_temp := v_temp || substr(v_string, 0, p_step_in);
end if;
end loop;
5.想要实现分页的同时实现排序
注:有时候要排列的某一列A是字符类型,需要加个to_number转换成数字类型。
SELECT *
FROM (
SELECT column1, column2, ..., ROW_NUMBER() OVER (ORDER BY column1 ASC, column2 DESC) AS rn
FROM your_table
)
WHERE rn > (2 - 1) * 30
AND rn <= 2 * 30;
6.把一个列中的数据拆分。比如某一行某一列的数据是aa;bb,拆成两行
select regexp_substr(aa.dt, '[^;]+', 1, level) dt
from talbeA
connect By regexp_substr(aa.dt, '[^;]+', 1, level) is not Null
7.PLSQL误提交后,查询某个时间点之前的数据
select *
from tblitembarcode as of timestamp to_timestamp('2023-08-23 13:30:00', 'yyyy-mm-dd hh24:mi:ss')where ...
这是Oracle数据库的语法,用于指定查询的时间点。在这个例子中,to_timestamp('2023-08-23 13:30:00', 'yyyy-mm-dd hh24:mi:ss')
表示将字符串'2023-08-23 13:30:00'转换为时间戳格式。查询将返回在指定时间点之前(包括该时间点)的数据。