我们是五月的花海 , 用青春拥抱|

兴想事成

园龄:12年10个月粉丝:25关注:97

SqlSugar 和 Oracle 结合在一起 ORA-00972 标识符过长

1.声明: 本人是 SqlSugar  忠实的粉丝;

2.有些坑跟Oracle 脱不开关系;

3.解决方案,肯定是有的,而且不止一种;

 

先讲述一下, 这个坑是怎么出来的. 

一般,我本人使用联表查询(比如 A,B), 结果集 都是单独建一个 Vo, 然后用 SelectAll()  映射,一步到位.

(A表 全名: NOTICE_TODO_ITEM_RUN 

B表 全名 :NOTICE_TODO_ITEM  ,部分字段 DBID,IDX, RUN_ACTION_TOTAL,RUN_ACTION_NEED)

同事有点想偷懒, 这样整.

public class A 

{

   public string 字段1;

   public string 字段2;

   public B  ItemB;

}

其中A,B 各表都有很多字段.

于是现在查询 为 

db.Queryable<A>() .LeftJoin<B>((a, b) => a.id== b.id).Select((a, b) => new A{ id= a.id.SelectAll(),ItemB=b}

这时报了一个错:  ORA-00972 标识符过长, 查了下,  定位问题为:  别名超过30个字符.

什么意思呢, 就是  SqlSugar   生成出来的 sql为 

SELECT a.*, "B"."DBID" AS "B.NOTICE_TODO_ITEM.DBID" , "B"."IDX" AS "B.NOTICE_TODO_ITEM.IDX" ,
"B"."CREATE_TIME" AS "B.NOTICE_TODO_ITEM.CREATE_TIME" , "B"."RUN_ACTION_TOTAL" AS "B.NOTICE_TODO_ITEM.RUN_ACTION_TOTAL" ,
"B"."RUN_ACTION_NEED" AS "B.NOTICE_TODO_ITEM.RUN_ACTION_NEED" ,
"B"."TITLE" AS "B.NOTICE_TODO_ITEM.TITLE" FROM "NOTICE_TODO_ITEM_RUN" a
Left JOIN "NOTICE_TODO_ITEM" b ON ( "A"."ITEM_DBID" = "B"."DBID" ) ORDER BY "A"."CREATE_TIME" DESC

 

其中 "B"."RUN_ACTION_TOTAL" AS "B.NOTICE_TODO_ITEM.RUN_ACTION_TOTAL"  别名 长度超过30个字符,oracle 不支持.

 

那现在就找解决办法:

1.该表,改字段, 让 表  和 字段 长度进行缩减;

   ==> 如果是新表,可以这样做,但如果是 已经上线的表,这样操作不太合适.

2.所有与B表相关的字段, 都全部列举,不用 简写的方式

比如 :

db.Queryable<A>() .LeftJoin<B>((a, b) => a.id== b.id).Select((a, b) => new A{ id= a.id.SelectAll(),ItemB=new B{ IDX=b.IDX, CREATE_TIME=b.CREATE_TIME... }}

这样如果B表字段太多,写起来有点小麻烦.

 

3. 既然是别名长度超过30个字符,那就想办法缩减别名

 

比如定义

  public int? RUN_ACTION_TOTAL{ get; set; } 改为 如下这种写法

 [SugarColumn(ColumnName = "RUN_ACTION_TOTAL")]

public int? TOTAL { get; set; }

 

生成的 sql为 B.NOTICE_TODO_ITEM.TOTAL 这样 一定程度上 满足了 30个字符的要求.

 

但是 如果真的有那种表名特别长的, 比如  >=27个长度的, B.[27].  这就30个字符了,后面完全没有改字段的余地了.

  所以如果项目没上线, 最好还是修改表名和字段名, 尽量简短.(写好注释和文档即可)

 

posted @   兴想事成  阅读(434)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 Good-bye My Loneliness ZARD
  2. 2 Say OK Vanessa Hudgens
  3. 3 All The Love In The World The Corrs
  4. 4 Adesso E Fortuna ~炎と永遠~ 加藤いづみ
Say OK - Vanessa Hudgens
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

作词 : BIRGISSON, ARNTHOR/KOTECHA, SAVAN

作曲 : Savan Kotecha/Arnthor Birgisson

Vanessa Hudgens - Say OK

Album: V

You are fine

You are fine

You are fine

You are fine

You are sweet

But I'm still a bit naive with my heart

When you're close I don't breathe

I can't find the words to speak

I feel sparks

But I don't wanna be into you

If you are not looking for true love, oh oh

No I don't wanna start seeing you

If I can't be your only one

So tell me when it's not alright

When it's not ok

Will you try to make me feel better?

Will you say alright? (say alright)

Will you say ok? (Say ok)

Will you stick with me through whatever?

Or run away

(Say that it's gonna be alright)

(That it's gonna be ok)

Say OK

When you call I don't know

If I should pick up the phone every time

I'm not like all my friends

Who keep calling up the boys, I'm so shy

But I don't wanna be into you

If you don't treat me the right way

See I can only start seeing you

If you can make my heart feel safe (feel safe)

When it's not alright

When it's not ok

Will you try to make me feel better?

Will you say alright? (say alright)

Will you say ok? (Say ok)

Will you stick with me through whatever?

Or run away

(Say that it's gonna be alright)

(That it's gonna be ok)

(Don't run away, don't run away)

Let me know if it's gonna be you

Boy, you've got some things to prove

Let me know that you'll keep me safe

I don't want you to run away so

Let me know that you'll call on time

Let me know that you won't be shy

Will you wipe my tears away

Will you hold me closer

When it's not alright

When it's not ok

Will you try to make me feel better

Will you say alright? (say alright)

Will you say ok? (Say ok)

Will you stick with me through whatever?

Or run away

(Say that it's gonna be alright)

(That it's gonna be ok)

Say OK

(Don't run away, don't run away)

(Say that it's gonna be alright)

(That it's gonna be ok)

(Don't run away)

Will you say OK

(Say that it's gonna be alright)

(That it's gonna be ok)

(Don't run away)

You are fine

You are fine