如何使用PL/SQL在过程/函数中使用两个列创建索引
我想创建串联两个列的索引,使用此查询:
declare
t_name varchar(100) := upper('test');
table_space varchar(100) := 'users';
begin
execute immediate
'create index ' || upper('trx_cst_indx') || ' ON ' || t_name || '(' || trx_date||'_'||customer_id || ') local unusable';
end;
运行该查询会给我这个错误:
PLS-00201: identifier 'TRX_DATE' must be declared
ORA-06550: line 5, column 16:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
然后,我对这样的列名使用单引号:
declare
t_name varchar(100) := upper('test_etl');
table_space varchar(100) := 'users';
begin
execute immediate
'create index ' || upper('trx_cst_indx') || ' ON ' || t_name || '(' || 'trx_date'||'_'||'customer_id' || ') local unusable';
end;
运行上述查询时,我收到此错误:
Error report - ORA-00904: "TRX_DATE_CUSTOMER_ID": invalid identifier
ORA-06512: at line 5
00904. 00000 - "%s: invalid identifier"
*Cause:
我不知道这些查询有什么问题。 您能否指导我如何在此模式下使用两个列来创建索引?
任何帮助都非常感谢。
I want to create index of concatenating two columns, using this query:
declare
t_name varchar(100) := upper('test');
table_space varchar(100) := 'users';
begin
execute immediate
'create index ' || upper('trx_cst_indx') || ' ON ' || t_name || '(' || trx_date||'_'||customer_id || ') local unusable';
end;
Running that query gives me this error:
PLS-00201: identifier 'TRX_DATE' must be declared
ORA-06550: line 5, column 16:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
Then I use single quotation for the column names like this:
declare
t_name varchar(100) := upper('test_etl');
table_space varchar(100) := 'users';
begin
execute immediate
'create index ' || upper('trx_cst_indx') || ' ON ' || t_name || '(' || 'trx_date'||'_'||'customer_id' || ') local unusable';
end;
While running the above query, I receive this error:
Error report - ORA-00904: "TRX_DATE_CUSTOMER_ID": invalid identifier
ORA-06512: at line 5
00904. 00000 - "%s: invalid identifier"
*Cause:
I don't know what is wrong with these queries.
Would you please guide me how to create index with concatenating two columns in this mode?
Any help is really appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试以下操作:
Try this: