我在webapp中的mysql中有四个查询,我试图将其转换为oracle查询。但是,当我尝试运行新查询时,日期时间字符串中断。有人可以帮我弄清楚我做错了吗?
PostGreSql查询: -
插入o_stat_daily (businesspath,渣油,日,值)
(选择businesspath, int8(substring(businesspath from position(':' in businesspath)+ 1 for position(']' businesspath) - position(':' in businesspath) - 1)), date_trunc(' day',creationdate)为d, 将(*)计为c 来自o_loggingtable,其中actionverb =' launch'和actionobject ='节点'和businesspath!='' group by businesspath,d);插入o_stat_weekly (businesspath,渣油,本周的值)
(选择businesspath, int8(substring(businesspath from position(':' in businesspath)+ 1 for position(']' businesspath) - position(':' in businesspath) - 1)), to_char(creationdate,' IYYY')|| ' - ' || to_char(creationdate,' IW')为d, 将(*)计为c 来自o_loggingtable,其中actionverb =' launch'和actionobject ='节点'和businesspath!='' group by businesspath,d);插入o_stat_dayofweek (businesspath,渣油,日,值)
(选择businesspath, int8(substring(businesspath from position(':' in businesspath)+ 1 for position(']' businesspath) - position(':' in businesspath) - 1)), int8(to_char(creationdate,' D'))为d, 将(*)计为c 来自o_loggingtable,其中actionverb =' launch'和actionobject ='节点'和businesspath!='' group by businesspath,d);插入o_stat_hourofday (businesspath,渣油,小时,值)
(选择businesspath, int8(substring(businesspath from position(':' in businesspath)+ 1 for position(']' businesspath) - position(':' in businesspath) - 1)), int8(to_char(creationdate,' HH24'))为d, 将(*)计为c 来自o_loggingtable,其中actionverb =' launch'和actionobject ='节点'和businesspath!='' group by businesspath,d);
Oracle查询: -
插入o_stat_daily (businesspath,渣油,日,值)
(选择businesspath, convert(subspath(businesspath,locate(':',businesspath)+ 1,找到(']',businesspath) - 找到(':', businesspath) - 1),int), 转换(creationdate,date)d, count(*)c 来自o_loggingtable,其中actionverb =' launch'和actionobject ='节点'和businesspath!='' group by businesspath,d);插入o_stat_weekly (businesspath,渣油,本周的值)
(选择businesspath, convert(subspath(businesspath,locate(':',businesspath)+ 1,找到(']',businesspath) - 找到(':', businesspath) - 1),int), 年(creationdate)+' - ' +重复(' 0',2-length(转换((dayofyear(creationdate)-dayofweek(creationdate))/ 7,varchar(7) )))+转换((DAYOFYEAR(creationdate)-dayofweek(creationdate))/ 7,VARCHAR(7)) d, count(*)c 来自o_loggingtable,其中actionverb =' launch'和actionobject ='节点'和businesspath!='' group by businesspath,d);插入o_stat_dayofweek (businesspath,渣油,日,值)
(选择businesspath, convert(subspath(businesspath,locate(':',businesspath)+ 1,找到(']',businesspath) - 找到(':', businesspath) - 1),int), dayofweek(creationdate)d, count(*)c 来自o_loggingtable,其中actionverb =' launch'和actionobject ='节点'和businesspath!='' group by businesspath,d);插入o_stat_hourofday (businesspath,渣油,小时,值)
(选择businesspath, convert(subspath(businesspath,locate(':',businesspath)+ 1,找到(']',businesspath) - 找到(':', businesspath) - 1),int), 小时(creationdate)d, count(*)c 来自o_loggingtable,其中actionverb =' launch'和actionobject ='节点'和businesspath!='' group by businesspath,d);
答案 0 :(得分:0)
我没有重写你的所有查询,而是采用了最后一个查询。
oracle查询应该是这样的:
INSERT INTO o_stat_hourofday (
businesspath,
resid,
hour,
VALUE
)
SELECT businesspath,
TO_NUMBER (
SUBSTR (
businesspath,
INSTR(businesspath, ':') + 1,
INSTR(businesspath, ']') - INSTR(businesspath, ':') - 1
)
),
TO_NUMBER(TO_CHAR(creationdate, 'HH24')) d,
COUNT (*) c
FROM o_loggingtable
WHERE actionverb = 'launch'
AND actionobject = 'node'
AND businesspath IS NOT NULL
GROUP BY businesspath,
TO_NUMBER (
SUBSTR (
businesspath,
INSTR(businesspath, ':') + 1,
INSTR(businesspath, ']') - INSTR(businesspath, ':') - 1
)
),
TO_NUMBER(TO_CHAR(creationdate, 'HH24'));
仅供参考,Oracle无法识别HOUR
函数,而oracle中的CONVERT
将一个字符集转换为另一个字符集,而不是字符串转换为数字。 LOCATE也不是Oracle函数,您需要使用INSTR
来查找字符串中的字符。
阅读TO_CHAR(包括日期格式等),TO_NUMBER和INSTR。
希望这能帮到你!
答案 1 :(得分:0)
我还对其余三个查询进行了调查。他们都在工作。感谢Ollie的帮助。
INSERT INTO o_stat_daily (
businesspath,
resid,
DAY,
VALUE
)
SELECT businesspath,
TO_NUMBER (
SUBSTR (
businesspath,
INSTR(businesspath, ':') + 1,
INSTR(businesspath, ']') - INSTR(businesspath, ':') - 1
)
),
to_date(creationdate)
d,
COUNT (*) c
FROM o_loggingtable
WHERE actionverb = 'launch'
AND actionobject = 'node'
AND businesspath IS NOT NULL
GROUP BY businesspath,
TO_NUMBER (
SUBSTR (
businesspath,
INSTR(businesspath, ':') + 1,
INSTR(businesspath, ']') - INSTR(businesspath, ':') - 1
)
),
to_date(creationdate);
INSERT INTO o_stat_weekly (
businesspath,
resid,
WEEK,
VALUE
)
SELECT businesspath,
TO_NUMBER (
SUBSTR (
businesspath,
INSTR(businesspath, ':') + 1,
INSTR(businesspath, ']') - INSTR(businesspath, ':') - 1
)
),
to_char(creationdate, 'IYYY') || '-' || to_char(creationdate, 'IW')
d,
COUNT (*) c
FROM o_loggingtable
WHERE actionverb = 'launch'
AND actionobject = 'node'
AND businesspath IS NOT NULL
GROUP BY businesspath,
TO_NUMBER (
SUBSTR (
businesspath,
INSTR(businesspath, ':') + 1,
INSTR(businesspath, ']') - INSTR(businesspath, ':') - 1
)
),
to_char(creationdate, 'IYYY') || '-' || to_char(creationdate, 'IW') ;
INSERT INTO o_stat_dayofweek (
businesspath,
resid,
day,
VALUE
)
SELECT businesspath,
TO_NUMBER (
SUBSTR (
businesspath,
INSTR(businesspath, ':') + 1,
INSTR(businesspath, ']') - INSTR(businesspath, ':') - 1
)
),
TO_NUMBER(TO_CHAR(creationdate, 'D')) d,
COUNT (*) c
FROM o_loggingtable
WHERE actionverb = 'launch'
AND actionobject = 'node'
AND businesspath IS NOT NULL
GROUP BY businesspath,
TO_NUMBER (
SUBSTR (
businesspath,
INSTR(businesspath, ':') + 1,
INSTR(businesspath, ']') - INSTR(businesspath, ':') - 1
)
),
TO_NUMBER(TO_CHAR(creationdate, 'D'));