merge into语法

作用:判断B表和A表是否满足ON中条件,如果满足则用B表去更新A表,如果不满足,则将B表数据插入A表

MERGE INTO [target-table] A USING [source-table sql] B ON([conditional expression] and [...]...)
WHEN MATCHED THEN
	[UPDATE sql]
WHEN NOT MATCHED THEN
	[INSERT sql]

例:

merge into TABLEA a using (select '{0}' as age,'{1}' as name,'{2}' as sex from dual) b
on (a.age=b.age) when matched then
update set a.name=b.name,a.sex=b.sex
when not matched then
insert(age,name,sex) values(b.age,b.name,b.sex)

虚拟表dual

此处b表dual为Oracle的虚拟表

dual 是一个实际存在的虚表,存在的目的不是为了保存数据,而是为了完善Oracle的查询语法规则

oracle保证dual里面永远只有一条记录

image-dual

获取GUID

在.ashx文件中获取guid

var uid = Guid.NewGuid().ToString()

在.cs文件中获取guid

sys_guid()

例:

select sys_guid() from  dual

获取当前时间

sysdate

验证时间是否过期

select * from (
               select a.*,ceil((sysdate - ltime)*24*60*60)seconds  from TABLEA a
               ) where seconds<7000

查询表中总数据条数

select count(*) from TABLE

多表查询 left join

left join 关键字从左表(table1)返回所有的行,即使右表(table2)中没有匹配。如果右表中没有匹配,则结果为 null

select * from table1 a
left join table2 b on a.name=b.name    >>>查找表table1和table2 

查询时格式化时间

select to_char(t,'yyyy-mm-dd hh24:mi:ss') time1  from table1

多值查询??where .. in ()

in 操作符允许在 WHERE 子句中规定多个值

select * from table1 where name in (name1,name2...)

例:

select * from table1 where name in (select name from table2)

模糊查询

select * from table1 where name like '%张%'    >>>查询表table1中name字段包含张字的所有

存入图片

public int InsertImg(string emp, byte[] signimg)
{
   string sql = string.Format(@"insert into table1(gid,emp,IMG,time1) values(sys_guid(),'{0}',:signimg,sysdate)",emp);
   OracleParameter[] pms = new OracleParameter[] { 
       new OracleParameter(":signimg", OracleType.Blob){Value=signimg}
   };
   int res = ora.ExecuteNonQuery(sql, CommandType.Text, pms);
   return res;
}

时间字段模糊查询

将Oracle中时间字段转化成字符串,然后进行字符串模糊查询

select * from TABLE  WHERE to_char(CREATE_TIME,'yyyy-MM-dd') like '2019-09-12'

C#实现图片上传并保存相对路径

C#实现图片上传并保存相对路径