数据库查询语句

文章对比了HQL与SQL的区别,指出在Hibernate中推荐使用HQL,因为它更面向对象且利于数据库移植。同时,文章详细列举了Oracle数据库的HQL查询示例和SQL查询、添加列的操作。对于Neo4j图数据库,文章提供了查询、删除、更新、新增和路径过滤等操作的语句示例,还包括数据库的导入导出方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

oracle数据库搜索语句

一、hql与sql的区别:
 1、首先 hql 是面向对象查询,sql 是面向数据库表查询。
 2、hql 区分大小写,sql 不区分大小写。
 3、在语法上
  hql :from 后面跟的 类名+类对象, where 后用对象的属性做条件。
   增删改直接调用封装好的save()、delete()、update()方法。
  sql: from 后面跟的是表名,where 后 用表中字段做条件查询。
 4、hql中 select * 可以省略。
二、在Hibernate中推荐使用hql语句,不建议直接使用sql。
原因:
 1、sql不是以面对对象的方式操作数据库,这是Hibernate不提倡的。
 2、如果编写了某种数据库特有的函数或语法,那么在更换数据库时肯定要修改源码重新编译。
三、Hibernate把hql编译成sql语句传送到数据库进行查询。
 在执行效率方面,不考虑其它的影响, 一般sql 效率要高于 hql ,如果考虑 缓存,关联映射,语句的质量就要看具体情况,不过sql 的功能是比hql大。
四、hql语句
1、查询语句
"from ModelRelation t where t.fromId='"+modelInfo.getInnerId()+"' or t.toId='"+modelInfo.getInnerId()+"' "
                    + "or t.relationId='"+modelInfo.getInnerId()+"'";
五、sql语句
1、查询语句                    
select * from KBE_PT_FOLDER m where m.classId='KBEUIPortaritFolder'
2、表添加列数据                    
#在A表中添加字段B,数据类型 varchar(20),不为空
ALTER TABLE A(表名) ADD B(字段名) varchar(20) NOT NULL;

neo4j图数据库搜索语句
1、查询语句
MATCH (n) where id(n)=%s return n
利用节点label查询
match (n) where (n:`a` or n:`b` ) return count(n)
match (n) where any(label in labels(n) WHERE label in ['a', 'b']) return n
利用关系label(id)查询不需要在match后定义
match (n) where any(label in labels(n) WHERE label in ['a', 'b']) return n
2、删除语句
删除节点以及周围连接的关系
MATCH (n) ,d=(n)-[x]-() where id(x)=%s 或者 type(x)=''DETACH DELETE n
删除节点(周围存在连接的关系会报错,只适合单独节点)
MATCH (n) where id(n)=%s  DELETE n    
3、更新语句    
match(n:) set n.new_property = n.old_property 
4、新增语句    
CREATE (n1:FaceBookProfile1{type:“”})-[r:LIKES{type:“”}]->(n2:FaceBookProfile2{type:“”}) 
5、创建关系
MATCH (a:LabeofNode1), (b:LabeofNode2) WHERE a.name = "nameofnode1" AND b.name = " nameofnode2" CREATE (a)-[: Relation]-> (b) RETURN a, b
6、模糊搜索
match (a) where a.CaseType contains "案例" or a.ExampleName contains "案例" return a
7、路径查询
match (n),(p),(r), d=(n)-[ProcessPlanToOperation]-(p) where id(n)=14  and id(p)=21  return d
8、路径过滤
路径不包含x节点的路径过滤
match (n),(p),(r),(x), d=(n)-[]-()-[]-(p) where NONE(m IN nodes(d) where m=x) and id(n)=6 and id(p)=8 and id(x)=7   return d

路径不包含x和y节点的路径过滤
match (n),(p),(r),(x),(y), d=(n)-[]-()-[]-(p) where NONE(m IN nodes(d) where m=x or m=y) and id(n)=6 and id(p)=8 and id(x)=7 and id(y)=35     return d

路径包含x节点的路径过滤
match (n),(p),(r),(x),(y), d=(n)-[*..2]-(p) where x IN nodes(d) and id(n)=6 and id(p)=8 and id(x)=9 and id(y)=35     return d

路径包含x节点或者y节点的路径过滤
match (n),(p),(r),(x),(y), d=(n)-[*..2]-(p) where  (y IN nodes(d) or x IN nodes(d)) and id(n)=6 and id(p)=8 and id(x)=9 and id(y)=35     return d

路径中包含x节点但不包含y节点的路径过滤
match (n),(p),(r),(x),(y), d=(n)-[*..2]-(p) where NONE(m IN nodes(d) where m=y) and ( x IN nodes(d)) and id(n)=6 and id(p)=8 and id(x)=9 and id(y)=35    return d

路径中包含部分路径((r)-[:SolutionToProcessPlan| ProcessPlanToHeatOP]-(y))的路径过滤
match (n),(p),(r),(x),(y), d=(n)-[*..2]-(r)-[:SolutionToProcessPlan| ProcessPlanToHeatOP]-(y)-[*..2]-(p) where  id(n)=3 and id(p)=37 and id(r)=8 and id(y)=34   return d

9、数据库导入导出
terminal中进入
cd bin         //进入bin文件序列下
neo4j-admin dump --to=D:/daochu.db     //导出文件
neo4j-admin load --from=D:/daochu.db --force     //导入文件
    

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值