最近做一个项目,经常需要用到多表查询,通过需要分页等,于是经常会碰到

ORA-00918: column ambiguously defined错误应对方法,意思是说,某一列定义模糊,于是

经过了很多方面的测试,总算能解决,尤其是在涉及到tablename.*,这里的*很容易出现这样的错误。

需要仔细的研究下面的2个sql语句:

select v1.*,(v1.data-v2.data) as rate, v3.*, (v3.data-v4.data) as rate2

from (

select rownum as rn, a.* from (

select ayearmon, DATA, DATA-100 as rate

from test

where isvalid=1 and code='3503'

and region = '000000'

order by ayearmon desc

) a) v1,

(

select (rownum-1) as rn1, b.* from (

select ayearmon, DATA

from test

where isvalid=1 and code='3503'

and region = '000000'

order by ayearmon desc

) b) v2,

( select rownum as rn, c.* from (

select ayearmon, DATA, DATA-100 as rate

from test

where isvalid=1 and code='3502'

and region = '000000'

order by ayearmon desc

) c) v3,

(

select (rownum-1) as rn1, d.* from (

select ayearmon, DATA

from test

where isvalid=1 and code='3502'

and region = '000000'

order by ayearmon desc

) d) v4

where v1.rn = v2.rn1 and v3.rn = v4.rn1 and v1.rn = v3.rn

and v1.rn >= 1 and v1.rn <= 10

select * from (

select v1.*, CASE WHEN substr(v1.ayearmon, 5, 2) = '02' THEN v1.DATA ELSE (v1.DATA - v2.DATA)  END  as dy

from (

select rownum as rn, a.* from (

select ayearmon, DATA

from v_yy_MAC201

where isvalid=1 and code='10011001' and length(ayearmon) = 6

and timetype='b0301' and region = '000000'

order by ayearmon desc

) a) v1,

(

select (rownum-1) as rn1, b.* from (

select ayearmon, DATA

from v_yy_MAC201

where isvalid=1 and code='10011001' and length(ayearmon) = 6

and timetype='b0301' and region = '000000'

order by ayearmon desc

) b) v2 where v1.rn = v2.rn1

)

where rn >= 1 and rn <= 50

通过上面的2个sql,能不能发现什么规律呢?

有空继续讨论。

ORA-00918: column ambiguously defined错误应对方法相关推荐

  1. Oracle “column ambiguously defined ” 错误

    在Oracle中执行查询,有时候会报错"column ambiguously defined ",中文意思是字段定义模糊.报错如下图: 这个错误通常是由于FROM的两个表中都有某个 ...

  2. 02 ORA系列:ORA-00918 未明确定义列 column ambiguously defined

    如果希望对常见的Oracle异常ORA报错解决方案有系统的了解,请看<ORACLE系列异常总结ORA>. ORA-00918 未明确定义列 column ambiguously defin ...

  3. ORA-00918: column ambiguously defined解决之道

    最近做一个项目,经常需要用到多表查询(Hibernate),通过需要分页等,于是经常会碰到 ORA-00918: column ambiguously defined错误. 该报错翻译过来:某一列定义 ...

  4. 关于 ORA-00918: column ambiguously defined 的错误

    ORA-00918: column ambiguously defined 检索多表的项目 然后用 AS 起的别名 但是用 group by 分组的 时候 是不能够用别名来分组的 写上表明和项目名 就 ...

  5. [Hibernate]column ambiguously defined异常

    使用Hibernate的NativeSQL写了一个查询语句,但是后台报了SQL语法错误,具体报错如下: [2012-08-08 12:55:00] ERROR -> ORA-00918: col ...

  6. django进入admin报错ORA-00918:column ambiguously defined

    运行创建好的django项目,以"http://127.0.0.1"访问,成功显示小火箭页面,但当访问"http://127.0.0.1/admin"时报错,错 ...

  7. 解决 Oracle column ambiguously defined 的问题

    1.案例1: select * from( select aa2.workorder,aa2.*,bb.* from (select  distinct t.workorder,t.client,t. ...

  8. Oracle 查询SQL语句报 ORA-00918: column ambiguously defined(Navicat中)

    原有的SQL语句是: SELECT* FROM(SELECTi.ID,i.NAME,i.code,i.num,i.state,i.unit,i.TYPE,i.addtime,i.TIME,i.user ...

  9. Error: PL/SQL: ORA-00918: column ambiguously defined

    java面试题网站:www.javaoffers.com 这里错误通常是  在 select1 语句中出现了相同的字段名,而在其他select2语句中引用到了 select1语句中的相同的字段,此时 ...

最新文章

  1. AAAI 2021全部大奖出炉!华人霸屏!北航、华科校友获最佳论文,华南理工获杰出论文
  2. #招聘# C++高级攻城师一枚
  3. WCF如何通过契约加编码方式调用
  4. git教程——简单总结
  5. oracle 分组排序后取第一条_关于oracle中位图索引的探讨:概念、原理、优缺点...
  6. 计算机一级繁体字转换,繁体字转换器
  7. 软件工程(吕云翔第二版)部分知识点
  8. 怎么添加桌面计算机快捷键,怎么添加桌面快捷方式图标,教你怎么添加桌面快捷方式图标...
  9. office2016、office365和office其它版本JH
  10. 【高等代数】行列式的定义和性质
  11. 高等组合学笔记(三): 间隔排列,投票问题,圈集排列组合与生成函数简介
  12. python爬虫入门——QQ音乐歌手照片及歌曲列表爬取
  13. 驱动开发指南 第八章 汇编LED灯实验
  14. Pytorch:NLP 迁移学习、NLP中的标准数据集、NLP中的常用预训练模型、加载和使用预训练模型、huggingface的transfomers微调脚本文件
  15. java 调excel 的宏_Microsoft Excel宏来运行Java程序
  16. ImageNet Large Scale Visual Recognition Competition (ILSVRC)-ImageNet数据集标签名称中英文对照
  17. 这些国外支付方式,你都听过或用过吗?
  18. 小白入门NAS—快速搭建私有云教程系列(一)
  19. 基础补充——什么是陷波器?作用是什么?
  20. 软件工程的经验分享(来自一位前辈的经验)

热门文章

  1. 紧急提醒!东胜区109国道跨包茂高速立交桥将封闭施工!请绕行!
  2. 世界杯观看感受以及回忆...(大伙可在评论区讨论)
  3. 微信小程序-wx:for 循环列表
  4. 原生JS添加样式 内联important
  5. string转LPCSTR\LPCWSTR示例
  6. 星选大师卡来袭!一起感受学习的快乐
  7. 乐鑫Esp32学习之旅28 安信可 ESP32-Cam 摄像头开发板二次开发 C SDK编程,实现MQTT远程拍照传输到私有服务器。(附带源码)
  8. 数据恢复软件EasyRecovery永久版 百度云下载和使用
  9. 划分微服务边界的5个特征
  10. unsupported format string passed to Tensor.__format__