Plsql 如何在游标循环中使用Trunc(mydate)
我是PL/SQL新手,今天正在研究cursor,在这个场景中,我需要根据日期+金额+客户id+txn\u tpye获取重复的事务类型。一旦我得到了副本,我就必须使用另一个游标或普通循环,使用select列values date+amount+cust_id+txn_tpye作为where子句 在此之前,当我试图打印mydate值getting error时,我只是尝试打印它们,以确定是否获取了值。请求你们的帮助Plsql 如何在游标循环中使用Trunc(mydate),plsql,oracle-sqldeveloper,plsqldeveloper,Plsql,Oracle Sqldeveloper,Plsqldeveloper,我是PL/SQL新手,今天正在研究cursor,在这个场景中,我需要根据日期+金额+客户id+txn\u tpye获取重复的事务类型。一旦我得到了副本,我就必须使用另一个游标或普通循环,使用select列values date+amount+cust_id+txn_tpye作为where子句 在此之前,当我试图打印mydate值getting error时,我只是尝试打印它们,以确定是否获取了值。请求你们的帮助 SET SERVEROUTPUT ON declare CURSOR dup_
SET SERVEROUTPUT ON
declare
CURSOR dup_check
IS
SELECT cust_id,amount,trunc(mydate),transaction_type,COUNT(1)
FROM table_X WHERE trunc(mydate)>='10-OCT-2015'
GROUP BY cust_id,amount,trunc(mydate),transaction_type
HAVING COUNT(1)>1 ;
BEGIN
FOR UP_REC IN dup_check
LOOP
DBMS_OUTPUT.put_line(UP_REC.cust_id||' '||UP_REC.amount||UP_REC.trnasaction_type||**trunc(mydate))**;
END LOOP;
END;
**PLS-00302: component 'mydate' must be declared**
为truncmydate字段添加别名,如下所示,并将UP_REC.mydate放入dbms_输出中
SET SERVEROUTPUT ON
declare
CURSOR dup_check
IS
SELECT cust_id,
amount,
trunc(mydate) mydate, /* add an alias here */
transaction_type,
COUNT(1)
FROM table_X WHERE trunc(mydate) >= '10-OCT-2015'
GROUP BY cust_id,amount,trunc(mydate),transaction_type HAVING COUNT(1)>1 ;
BEGIN
FOR UP_REC IN dup_check
LOOP
DBMS_OUTPUT.put_line(UP_REC.cust_id||' '||UP_REC.amount||UP_REC.trnasaction_type||UP_REC.mydate));
END LOOP;
END;
你好,纳伦德拉,谢谢你提供的信息。伟大的成功了。简单的事情使生活更容易。