EFCore sql 中雙引號相關問題

2021-10-04 01:50:24 字數 1541 閱讀 8261

單引號:單引號是字串分隔符,用於定義字串字面值

雙引號:雙引號是引用識別符號分隔符,可用它來訪問從資料庫目錄以區分大小寫的方式建立的表,如果你是以區分大小寫的方式建立資料庫表,這個是必需的。雙引號還能引註引住關鍵字。

遇到的問題抓日誌得到執行報錯:

2020-03-17 21:35:33,618 [9 error]  ---- failed executing dbcommand (414ms) [parameters=, commandtype='text', commandtimeout='0']

select "s"."pid", "s"."abbr", "s"."address", "s"."batteries_in_stock", "s"."charger_count", "s"."city", "s"."close_time", "s"."company_pid", "s"."district_code", "s"."gmt_create", "s"."gmt_modified", "s"."latitude", "s"."longitude", "s"."manager", "s"."name", "s"."open_time", "s"."province", "s"."remark", "s"."station_no", "s"."status", "s"."tel", "s"."user_create", "s"."user_modified"

from "charging_station" "s"

where "s"."station_no" = n'48'oracle.manageddataaccess.client.oracleexception (0x80004005): ora-00942: 表或檢視不存在

其實這個問題還是雙引號在搞怪,當你去掉引號在pl/sql裡面執行時,什麼問題都沒有。加上後pl/sql 就報相同的異常

ora-00942: 表或檢視不存在。

解決方案如下(可供參考,希望有其他更好的辦法來解決這個問題,畢竟效能有損失)

首先表名和字段中有下劃線_ 和 表名和列名轉大寫處理方式

public static string tosnakecase(this string input)

var startunderscores = regex.match(input, @"^_+");

return startunderscores + regex.replace(input, @"([a-z0-9])([a-z])", "$1_$2").toupper();

}

然後在dbcontext 的子類中重寫 onmodelcreating 的方法時重新賦值表名和列名(檢視、索引等都可以這樣處理)

public class oracledbcontext : microsoft.entityframeworkcore.dbcontext

.....業務表dbset

protected override void onmodelcreating(modelbuilder modelbuilder)}}

}

shell中單引號 雙引號 反引號

一 單引號和雙引號 首先,單引號和雙引號,都是為了解決中間有空格的問題。因為空格在linux中時作為乙個很典型的分隔符,比如string1 this is astring,這樣執行就會報錯。為了避免這個問題,因此就產生了單引號和雙引號。他們的區別在於,單引號將剝奪其中的所有字元的特殊含義,而雙引號中...

Python中單引號和雙引號

python中可以用單引號 或者雙引號 表示字串,如 print hello world print hello world 輸出結果是一樣的,如下 如果字串中含有帶引號的字串呢?用另外一種引號即可。如 print i d much rather you not print i said do no...

shell中單引號,雙引號,變數

variable value variable value variable value url website1 c語言中文網 website2 c語言中文網 echo website1 echo website2 執行結果 c語言中文網 c語言中文網 以單引號 包圍變數的值時,單引號裡面是什麼就...