0

私の webapp の mysql には、oracle クエリに変換しようとしている 4 つのクエリがあります。ただし、新しいクエリを実行しようとすると、日時文字列が壊れます。誰かが私が間違っていることを理解するのを手伝ってくれますか?

PostreSQL クエリ:-

insert into o_stat_daily (businesspath,resid,day,value)
(select businesspath, int8(substring(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);

insert into o_stat_weekly (businesspath,resid,week,value)
(select businesspath, int8(substring(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);

insert into o_stat_dayofweek (businesspath,resid,day,value)
(select businesspath, int8(substring(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 );

insert into o_stat_hourofday (businesspath,resid,hour,value)
(select businesspath, int8(substring(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);

insert into 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);

insert into 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) に挿入します (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'));

HOUR参考までに、Oracleは関数を認識せず、OracleではCONVERT、文字列ではなく、ある文字セットを別の文字セットに変換します。INSTRLOCATEもOracle関数ではありません。代わりに、文字列内の文字を検索するために使用する必要があります。

TO_CHAR(日付形式などを含む)、TO_NUMBER、およびINSTRを確認してください。

これがお役に立てば幸いです。

于 2012-07-17T09:52:02.980 に答える
0

残りの 3 つのクエリも追加しました。それらのすべてが機能しています。助けてくれてありがとう。

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 に答える