Plsql 使用PL/SQL从表中选择所有内容

Plsql 使用PL/SQL从表中选择所有内容,plsql,Plsql,所以在我的作业中,我必须从特定表中选择所有内容并输出。我们得到的示例代码是: declare current_bldg_code varchar2(5); cursor location_cursor is select room from location where bldg_code = current_bldg_code; current_room location.room%type; begin curr

所以在我的作业中,我必须从特定表中选择所有内容并输出。我们得到的示例代码是:

declare
    current_bldg_code varchar2(5);
    cursor location_cursor is
        select room
        from location
        where bldg_code = current_bldg_code;
    current_room location.room%type;
begin
    current_bldg_code := 'LIB';
    open location_cursor;
    loop
        fetch location_cursor into current_room;
        exit when location_cursor%notfound;
        dbms_output.put_line(
            'The current room is ' || 
             current_bldg_code || ' ' || 
            current_room
    );
    end loop;
    close location_cursor;
end;
/
现在,我提出了我自己的版本,以摆脱我们正在使用的表,我没有得到任何数据。这就是我所拥有的:

已解决:

declare
    c_first varchar2(30000);
    c_last varchar2(30000);
    c_mi char(10000);
    c_address varchar2(30000);
    c_dphone varchar2(10000);
    cursor customer_cursor is
        select c_first, c_mi, c_last, c_address, c_dphone
        from customer;
begin
    open customer_cursor;
    dbms_output.put_line('Clearwater Traders Mailing List');
    loop
        fetch customer_cursor into c_first, c_last, c_mi, c_address, c_dphone;
        exit when customer_cursor%notfound;
        dbms_output.put_line(c_first || ' ' || c_last || ' ' || c_mi || ' ' || c_address || ' ' || c_dphone);
    end loop;
    close customer_cursor;
end;
/

我建议在游标中使用ROWTYPE变量:

declare
    c_customer customer%ROWTYPE;
    cursor customer_cursor is
        select *
        from customer;
begin
    open customer_cursor;
    dbms_output.put_line('Clearwater Traders Mailing List');
    loop
        fetch customer_cursor into c_customer;
        exit when customer_cursor%notfound;
        dbms_output.put_line(c_customer.first || ' ' || c_customer.last || ' ' || c_customer.mi || ' ' || c_customer.address || ' ' || c_customer.dphone);
    end loop;
    close customer_cursor;
end;

WHERE
子句中的所有
当前变量都是
NULL
,因此它不能匹配任何内容。您没有初始化这些变量。你真的想要一个
其中的
吗?注意,在这个例子中,变量被初始化:
current_bldg_code:=“LIB”
老实说,我不知道我在做什么。我应该从customer表中选择以下变量。我知道如何在常规sql中实现这一点,但无法在带有游标的pl/sql中实现这一点。但是,是的,我没有要做的具体搜索。我应该从表中提取所有内容,所以你的意思是,我可以先声明c_,等等,去掉where子句,然后输出我选择的内容?