句子大小写 SQL:正确的标识符无效
Sentence Case SQL: RIGHT invalid Identifier
我尝试参考和使用我发现的以下示例:
http://sqlmag.com/t-sql/how-title-case-column-value
像这样:
V1:
SELECT DISTINCT upper(left(county,1))+lower(right(county,len(county)-1))
as county
FROM tablename
order by county
V2:
UPDATE tablename
SET county = UPPER(LEFT(county, 1)) + LOWER(RIGHT(county, LEN(county) - 1));
避免:
让 DISTINCT 填充相同但区分大小写的文本副本[我单独测试了 DISTINCT,它确实显示了副本]
我想做的是:
将文本显示为数据库中每个不同县值的句子
问题:
我面临的问题是 RIGHT
给我一个错误 Invalid identifier
有没有办法使用我的格式,但对 RIGHT
使用不同的值?
完整的 VB.net 代码块以填充下拉列表:
If Not County_List Is Nothing Then
Dim County As OleDbCommand = New OleDbCommand("SELECT DISTINCT upper(left(county,1))+lower(right(county,len(county)-1)) as county FROM tablename order by county", conn)
Dim OracleDataAdapterAds3 As OleDbDataAdapter = New OleDbDataAdapter
OracleDataAdapterAds3.SelectCommand = County
Dim DsAds3 As DataSet = New DataSet
DsAds3.Clear()
If Not (DsAds3 Is Nothing) Then
OracleDataAdapterAds3.Fill(DsAds3, "tablename")
County_List.DataSource = DsAds3
County_List.DataMember = "tablename"
County_List.DataBind()
Dim newListItem As ListItem
newListItem = New ListItem("", "")
County_List.Items.Insert(0, newListItem)
County_List.SelectedIndex = -1
End If
End If
看来您正在使用 Oracle。 Oracle 没有 LEFT()
和 RIGHT()
。相反,使用 SUBSTR()
:
SELECT DISTINCT upper(substr(county, 1, 1)) || lower(substr(county, 2)) as county
FROM tablename
ORDER BY county;
但是,您可能会发现 INITCAP()
(参见 documentation)更符合您的喜好:
select distinct initcap(county) as county
from tablename
order by county;
我尝试参考和使用我发现的以下示例:
http://sqlmag.com/t-sql/how-title-case-column-value
像这样:
V1:
SELECT DISTINCT upper(left(county,1))+lower(right(county,len(county)-1))
as county
FROM tablename
order by county
V2:
UPDATE tablename
SET county = UPPER(LEFT(county, 1)) + LOWER(RIGHT(county, LEN(county) - 1));
避免:
让 DISTINCT 填充相同但区分大小写的文本副本[我单独测试了 DISTINCT,它确实显示了副本]
我想做的是:
将文本显示为数据库中每个不同县值的句子
问题:
我面临的问题是 RIGHT
给我一个错误 Invalid identifier
有没有办法使用我的格式,但对 RIGHT
使用不同的值?
完整的 VB.net 代码块以填充下拉列表:
If Not County_List Is Nothing Then
Dim County As OleDbCommand = New OleDbCommand("SELECT DISTINCT upper(left(county,1))+lower(right(county,len(county)-1)) as county FROM tablename order by county", conn)
Dim OracleDataAdapterAds3 As OleDbDataAdapter = New OleDbDataAdapter
OracleDataAdapterAds3.SelectCommand = County
Dim DsAds3 As DataSet = New DataSet
DsAds3.Clear()
If Not (DsAds3 Is Nothing) Then
OracleDataAdapterAds3.Fill(DsAds3, "tablename")
County_List.DataSource = DsAds3
County_List.DataMember = "tablename"
County_List.DataBind()
Dim newListItem As ListItem
newListItem = New ListItem("", "")
County_List.Items.Insert(0, newListItem)
County_List.SelectedIndex = -1
End If
End If
看来您正在使用 Oracle。 Oracle 没有 LEFT()
和 RIGHT()
。相反,使用 SUBSTR()
:
SELECT DISTINCT upper(substr(county, 1, 1)) || lower(substr(county, 2)) as county
FROM tablename
ORDER BY county;
但是,您可能会发现 INITCAP()
(参见 documentation)更符合您的喜好:
select distinct initcap(county) as county
from tablename
order by county;