获取查询的每个结果后使用

时间:2014-07-17 12:22:30

标签: oracle plsql

我试图获取查询的每个结果然后打印输出并使用结果进行其他查询。我试图用光标制作它。但是当我尝试打印查询结果时,它会告诉我:

PLS-00306: wrong number or types of arguments in call to 'PUT_LINE'

我的代码是:

DECLARE
-- Store the SELECT query in a cursor
  CURSOR l_cur IS select memname from emuser.DEF_TABLES@controlm t, emuser.DEF_JOB@controlm j where (t.TABLE_ID = j.TABLE_ID) and t.sched_table = 'DWHRAC_DIARIOS2_DC2'; 
--Create a variable that will hold each result from the cursor
  l_cur_rec l_cur%ROWTYPE;
BEGIN
  -- Open the Cursor so that we may retrieve results
  OPEN l_cur;  
  LOOP
    -- Get a result from the SELECT query and store it in the variable
    FETCH l_cur INTO l_cur_rec;
    -- EXIT the loop if there are no more results
    EXIT WHEN l_cur%NOTFOUND;
    -- INSERT INTO another table that has the same structure as your results
              DBMS_OUTPUT.PUT_LINE( l_cur_rec);

  END LOOP;
  -- Close the cursor to release the memory
  CLOSE l_cur;
END;
你能帮帮我吗? 感谢

1 个答案:

答案 0 :(得分:1)

DBMS_OUTPUT.PUT_LINE接受一个字符串作为参数,但这里传递的是l_cur%ROWTYPE类型的变量,这是不允许的。您应该将呼叫更改为PUT_LINE以指定要打印的列的名称,例如:

DBMS_OUTPUT.PUT_LINE(l_cur_rec.MEMNAME);

分享并享受。

相关问题