Cfquery插入意外的记录数

时间:2015-06-16 01:56:48

标签: oracle coldfusion coldfusion-9

我需要使用cfquery获取recordcount查询的insert into select

在使用简单查询进行测试时,我无法获得所需的结果。

我总是将记录数量设为1。

代码

<cfquery name="Q_Test" datasource="DATABASE" result="queryresult">
        INSERT INTO GS_TEMP
            SELECT TRUNC (SYSDATE - ROWNUM) dt
              FROM DUAL CONNECT BY ROWNUM < 366
</cfquery>

<cfdump var="#queryresult#">

输出: Insert Query

这是预期的吗?

1 个答案:

答案 0 :(得分:1)

如果您想获得行数,那么您可以这样做:

<强>的Oracle

CREATE PROCEDURE create_dates_for_prev_year(
  out_num_rows NUMBER
)
AS
BEGIN
  INSERT INTO GS_TEMP
  SELECT TRUNC(SYSDATE) - LEVEL
  FROM DUAL
  CONNECT BY TRUNC(SYSDATE) - LEVEL >= TRUNC(SYSDATE) - INTERVAL '1' YEAR;

  out_num_rows := SQL%ROWCOUNT;
END create_dates_for_prev_year;
/

<强>的ColdFusion

<cfscript>
  sp = new StoredProc( dataSource = "DATABASE" );
  sp.setProcedure( "create_dates_for_prev_year" );
  sp.addParam( cfsqltype="CF_SQL_INTEGER", type="out", variable="numRows" );
  numRows = sp.execute.getProcOutVariables().numRows;

  writeDump( numRows );
</cfscript>

(未测试上述代码,但应该大部分都是正确的)