0

我在我的 web 应用程序中的 mysql 中有四个查询,我试图将它们转换为 oracle 查询。但是,当我尝试运行新查询时,日期时间字符串会中断。有人可以帮我弄清楚我做错了什么吗?

PostreSQL 查询:-

插入 o_stat_daily (businesspath,resid,day,value)
(select businesspath, int8(substring(businesspath from position(':' in businesspath) + 1 for position(']' in businesspath) - position(':' in businesspath) - 1)), date_trunc('day',creationdate) as d, count(*) as c from o_loggingtable where actionverb='launch' and actionobject='node' and businesspath != '' group by businesspath, d);

插入 o_stat_weekly (businesspath,resid,week,value)
(select businesspath, int8(substring(businesspath from position(':' in businesspath) + 1 for position(']' in businesspath) - position(':' in businesspath) - 1)), to_char(creationdate, 'IYYY') || '-' || to_char(creationdate, 'IW') as d, count(*) as c from o_loggingtable where actionverb='launch' and actionobject='node ' and businesspath != '' group by businesspath, d);

插入 o_stat_dayofweek (businesspath,resid,day,value)
(select businesspath, int8(substring(businesspath from position(':' in businesspath) + 1 for position(']' in businesspath) - position(':' in businesspath) - 1)), int8(to_char(creationdate, 'D')) as d, count(*) as c from o_loggingtable where actionverb='launch' and actionobject='node' and businesspath != '' group by businesspath, d );

插入 o_stat_hourofday (businesspath,resid,hour,value)
(select businesspath, int8(substring(businesspath from position(':' in businesspath) + 1 for position(']' in businesspath) - position(':' in businesspath) - 1)), int8(to_char(creationdate, 'HH24')) as d, count(*) as c from o_loggingtable where actionverb='launch' and actionobject='node' and businesspath != '' group by businesspath, d );

甲骨文查询:-

插入 o_stat_daily (businesspath,resid,day,value)
(select businesspath, convert(substr(businesspath, locate(':', businesspath) + 1, locate(']', businesspath) - locate(':', businesspath) - 1), int), convert(creationdate,date) d, count(*) c from o_loggingtable where actionverb='launch' and actionobject='node' and businesspath != '' group by businesspath, d);

插入 o_stat_weekly (businesspath,resid,week,value)
(select businesspath, convert(substr(businesspath, locate(':', businesspath) + 1, locate(']', businesspath) - locate(':', businesspath) - 1), int), year(creationdate)+ '-'+repeat('0',2-length(convert((dayofyear(creationdate)-dayofweek(creationdate))/7,varchar(7))))+ convert((dayofyear(creationdate)-dayofweek(creationdate))/7,varchar(7)) d, count(*) c from o_loggingtable where actionverb='launch' and actionobject='node' and businesspath != '' group by商业路径,d);

插入 o_stat_dayofweek (businesspath,resid,day,value)
(select businesspath, convert(substr(businesspath, locate(':', businesspath) + 1, locate(']', businesspath) - locate(':', businesspath) - 1), int), dayofweek(creationdate) d, count(*) c from o_loggingtable where actionverb='launch' and actionobject='node' and businesspath != '' group by businesspath, d);

插入 o_stat_hourofday (businesspath,resid,hour,value)
(select businesspath, convert(substr(businesspath, locate(':', businesspath) + 1, locate(']', businesspath) - locate(':', businesspath) - 1), int), hour(creationdate) d, count(*) c from o_loggingtable where actionverb='launch' and actionobject='node' and businesspath != '' group by businesspath, d);

4

2 回答 2

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函数,并且CONVERT在 oracle 中将一个字符集转换为另一个字符集,而不是将字符串转换为数字。LOCATE 也不是 Oracle 函数,您需要使用它INSTR来查找字符串中的字符。

阅读TO_CHAR(包括日期格式等)、TO_NUMBERINSTR

希望这对你有帮助!

于 2012-07-17T09:52:02.980 回答
0

我还添加了其余三个查询。他们都在工作。感谢奥利的帮助。

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'));
于 2012-07-18T01:11:36.470 回答