gpt4 book ai didi

oracle - 在 PL/SQL 中创建表?

转载 作者:行者123 更新时间:2023-12-04 17:26:04 24 4
gpt4 key购买 nike

我正在尝试在 PL/SQL 中创建一个表

我怎么能做到这一点?

不断得到

错误报告:

ORA-00933:“SQL 命令未正确结束”

这是我有错误的代码

DECLARE
station_id_ms1 NUMBER :=10347;
realtime_start DATE :=to_date('2012-01-01 00:00:00','YYYY-DD-MM HH24:MI:SS');
realtime_end DATE :=to_date('2012-07-01 00:00:00','YYYY-DD-MM HH24:MI:SS');
BEGIN
EXECUTE IMMEDIATE ('
CREATE TABLE new_table_name
AS
SELECT
((realtime - to_date(''01-JAN-1970'',''DD-MON-YYYY'')) * (86400)) AS realtime_ms1,
magnetic_ms_id,
ADC_value_pp_2_mgntc_fld_amp(ch2_value,ch2_gain_value,magnetic_ms_id,2) AS B_x_ms1,
ADC_value_pp_2_mgntc_fld_amp(ch1_value,ch1_gain_value,magnetic_ms_id,1) AS B_y_ms1,
real_nanosecs2*4/3*360/20e6 AS phase_x_ms1,
real_nanosecs1*4/3*360/20e6 AS phase_y_ms1
FROM
raw_mag
WHERE
magnetic_ms_id = '||station_id_ms1||'
AND realtime > '||realtime_start||'
AND realtime < '||realtime_end||'
AND ch1_tune_value = 0
AND realtime < pkg_timezone.change_timezone(gettime,''CET'',''UTC'')
');
END;

最佳答案

您应该在立即执行的 plsql-string 中进行字符到日期的转换。

您声明的日期将在串联中“反向转换”为 varchar2,并再次“重新转换”为日期以执行 create table 语句。在这两个转换中可能会发生“各种各样的事情”,因此您要确保在转换为日期时控制字符串的解释方式。

DECLARE
station_id_ms1 NUMBER :=10347;
realtime_start VARCHAR2(100) :='2012-01-01 00:00:00';
realtime_end VARCHAR2(100) :='2012-07-01 00:00:00';
BEGIN
EXECUTE IMMEDIATE ('
CREATE TABLE new_table_name
AS
SELECT
((realtime - to_date(''01-JAN-1970'',''DD-MON-YYYY'')) * (86400)) AS realtime_ms1,
magnetic_ms_id,
ADC_value_pp_2_mgntc_fld_amp(ch2_value,ch2_gain_value,magnetic_ms_id,2) AS B_x_ms1,
ADC_value_pp_2_mgntc_fld_amp(ch1_value,ch1_gain_value,magnetic_ms_id,1) AS B_y_ms1,
real_nanosecs2*4/3*360/20e6 AS phase_x_ms1,
real_nanosecs1*4/3*360/20e6 AS phase_y_ms1
FROM
raw_mag
WHERE
magnetic_ms_id = '||station_id_ms1||'
AND realtime > to_date(''' || realtime_start || ''', ''YYYY-DD-MM HH24:MI:SS'')
AND realtime < to_date(''' || realtime_end || ''', ''YYYY-DD-MM HH24:MI:SS'')
AND ch1_tune_value = 0
AND realtime < pkg_timezone.change_timezone(gettime,''CET'',''UTC'')
');
END;

关于oracle - 在 PL/SQL 中创建表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9587022/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com