且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 PL/SQL 从表中检索数据

更新时间:2022-12-04 20:26:36

IN SQL 如果要从表、视图等中检索数据,则需要使用 SELECT 语句.在您的匿名块中,您没有使用选择,而是在循环空变量.所以你需要像这样在你的代码中添加选择(你也可以用声明的游标来做,但在这种情况下,我在 FOR 上做了它):

IN SQL if you want to retrieve data from a table, view, etc. You need to use the SELECT statement. In your anonymous block you aren't using the select, and you're looping the empty variables. So you need to add the select in your code like this (You can do it with a declared cursor too, but in this case i made it in line on the FOR):

set serveroutput on;
begin
dbms_output.put_line('Department Details are :');
for c in (select department_id, department_name, location_id from department) loop
  dbms_output.put_line(c.department_id|| ', ' || c.department_name|| ', ' || 
  c.location_id);
end loop;
commit;
end;

由于您使用的是游标,因此根本不需要声明和使用变量.

Since you are using a cursor, there is no need to declare and use variables at all.