create or replace procedure MAX_min_hist
as
sql_stmt varchar2(4000);
sql_stmt2 varchar2(4000);
sql_stmt3 varchar2(4000);
var_date_of_trade hist_data.date_of_trade%type;
sql_stmt4 varchar2(4000);
cursor c1 is SELECT date_of_trade FROM hist_data where date_of_trade>TO_DATE('2015-07-01','YYYY-MM-DD');
begin
open c1;
Loop
fetch c1 into var_date_of_trade;
sql_stmt3 := 'CREATE OR REPLACE VIEW V_HIST_DATA AS SELECT * FROM HIST_DATA WHERE DATE_OF_TRADE < ' || var_date_of_trade;
sql_stmt := 'create table MAX_min_hist_data as ( select * from (
SELECT
CODE,
((CLOSE_PRICE-"Worst")/nullif("Worst",0))*100 Upper_from_down,
(("Best"-CLOSE_PRICE)/nullif(CLOSE_PRICE,0))*100 Down_from_Best,
"Worst",
"Best",
Close_Price
from (
SELECT
DISTINCT
CODE,
MIN(close_price) OVER (PARTITION BY CODE) "Worst",
MAX(close_price) OVER (PARTITION BY CODE) "Best",
first_value(close_price) over (PARTITION BY CODE order by date_of_trade desc) CLOSE_PRICE
FROM V_HIST_DATA
)
)
)';
sql_stmt2 := ' drop table MAX_min_hist_data';
execute immediate sql_stmt3;
execute immediate sql_stmt2;
execute immediate sql_stmt;
end loop;
end;
/
exec MAX_min_hist
执行上述代码会给我以下错误 -
ORA-00933:SQL命令未正确结束 ORA-06512:在MAX_MIN_HIST&#34;,第37行 ORA-06512:第1行
DATE_OF_TRADE
位于&YYYY-MM-DD&#39;格式。
提前致谢
答案 0 :(得分:1)
替换此行:
sql_stmt3 := 'CREATE OR REPLACE VIEW V_HIST_DATA AS SELECT * FROM HIST_DATA WHERE DATE_OF_TRADE < ' || var_date_of_trade;
这一个:
sql_stmt3 :=
'CREATE OR REPLACE VIEW V_HIST_DATA AS '
|| 'SELECT * FROM HIST_DATA '
|| 'WHERE DATE_OF_TRADE < to_date( '''
|| to_char( var_date_of_trade, 'yyyy-mm-dd' )
|| ''', ''yyyy-mm-dd'' ) ';