This is first code,no error
L_SQL := 'SELECT COUNT(1)
FROM TABLE A
WHERE COL1 = ''' || V_1 || ''' -- where col1 = '2021YEAR_REPORT'
AND COL2 LIKE ''%' || V_2 || ''' -- and col2 like '%202302'
AND COL3 = ''' ||
V_4 || '''';
This is second code,error PLS-00103
create or replace noneditionable procedure p1 is
v1 varchar2(10);
v_new number(10);
sql_1 varchar2(200);
begin
for i in 1..10 loop
begin
v1 := to_char( i);
end;
end loop;
sql_1 := 'select count(1) from table_1 a where a.col1 ='|| ''v1''; -- error
EXECUTE IMMEDIATE sql_1
into v_new;
end;
都是动态SQL的问题,第一个代码是正确的,但是我很迷惑其中'的使用,为什么会有那么多''',以后遇到这种情况应该怎么写代码,或者读别人的代码?为了研究如何使用',我写下第二段代码,他报错,这让我更加困惑,请帮我整理一下这个知识点,我会很感激