declare v_const varchar2(50) := 'AS'; v_sql varchar2(5000); v_count number(5,0); cursor c_column is select distinct all_tab_columns.owner,all_tab_columns.table_name,all_tab_columns.column_name from all_tab_columns,all_tables where all_tab_columns.table_name = all_tables.table_name and all_tab_columns.data_type = 'VARCHAR2' and all_tab_columns.owner <> 'SYS' ; begin for v_column in c_column loop v_sql := 'select count(*) from '||v_column.owner||'.'||v_column.table_name||' where '||v_column.column_name||'='||v_const; 接待方案 execute immediate v_sql into v_count; if v_count > 0 then insert into asearch(owner_name,table_name,column_name,table_view) values (v_column.owner,v_column.table_name,v_column.column_name,'table'); end if; end loop; commit; end; /这段里面报错:第 1 行出现错误:ORA-00936: missing expression ORA-06512: at line 10
line 10也就是 :execute immediate v_sql into v_count; 那一行
很奇怪,这段程序之前用在搜索一个数值的时候是没有问题的,如下,只是做了极小的改动
SQL code?1234567891011121314151617 declarev_const number(11,0) := 12008; v_sql varchar2(5000); v_count number(11,0); cursor c_column is select distinct all_tab_columns.owner,all_tab_columns.table_name,all_tab_columns.column_name from all_tab_columns,all_tables where all_tab_columns.table_name = all_tables.table_name and all_tab_columns.data_type = 'NUMBER' and all_tab_columns.owner <> 'SYS' ; begin for v_column in c_column loop v_sql := 'select count(*) from '||v_column.owner||'.'||v_column.table_name||' where '||v_column.column_name||'='||v_const; execute immediate v_sql into v_count; if v_count > 0 then insert into asearch(owner_name,table_name,column_name,table_view) values (v_column.owner,v_column.table_name,v_column.column_name,'table'); end if; end loop; commit; end; /
程序的意思就是查找一个常量值,在哪些表的字段中出现过。前一段是搜索字符型(报错),后一段搜索数字型(成功) 但是现在就是遇到这个问题,求助大虾!!!!
字符串 得用单引号 括起来呀: 改成下面这样:
v_sql := 'select count(*) from ' || v_column.owner || '.' || v_column.table_name || ' where ' || v_column.column_name || '=''' || v_const || '''';
常量时需要加‘’,定义的时候加的不一样,你理解一下,所以更改如下: v_sql := 'select count(*) from '||v_column.owner||'.'||v_column.table_name||' where '||v_column.column_name||'='||''''||v_const||'''';
|