通过plsql过程显示表数据

时间:2017-08-14 22:50:14

标签: plsql

我试图通过这个plsql代码显示表信息但是当它执行该过程时它只显示过程成功。不是输出。请帮助。

CREATE OR REPLACE PROCEDURE CarInfo
AS

V_serial                CAR.serial%TYPE;
V_Cid                   CAR.cid%TYPE;
V_make                  CAR.make%TYPE ;
V_model                 CAR.model%TYPE;
V_cyear                 CAR.cyear%TYPE;
V_color                 CAR.color%TYPE;
V_trim                  CAR.trim%TYPE;
V_enginetype            CAR.enginetype%TYPE;
V_purchinv              CAR.purchinv%TYPE;
V_purchdate             CAR.purchdate%TYPE;
V_purchfrom             CAR.purchfrom%TYPE;
V_purchcost             CAR.purchcost%TYPE;
V_freightcost           CAR.freightcost%TYPE;
V_totalcost             CAR.totalcost%TYPE;
V_listprice             CAR.listprice%TYPE;

BEGIN 
SELECT  serial, cid, make, model, cyear, color, trim, enginetype, purchinv, purchdate, purchfrom , purchcost, freightcost, 
        totalcost, listprice
    INTO  V_serial, V_cid, V_make, V_model, V_cyear, V_color, V_trim, V_enginetype, V_purchinv, V_purchdate, V_purchfrom , V_purchcost, V_freightcost, 
        V_totalcost, V_listprice 
    FROM CAR
    where cid is null;

Exception
 WHEN NO_DATA_FOUND THEN
    dbms_output.put_line('No Data Found')  ;

DBMS_OUTPUT.PUT_LINE(V_serial||' ' || V_cid||' ' ||V_make||' ' ||V_model||' ' ||V_cyear||' ' ||V_color||' ' ||V_trim||' ' ||V_enginetype||' ' ||V_purchinv||' ' ||V_purchdate||' ' ||V_purchfrom ||' ' ||V_purchcost||' ' ||V_freightcost||' ' ||
        V_totalcost||' ' ||V_listprice);
END;

2 个答案:

答案 0 :(得分:0)

简而言之,我会按照以下方式编写您的程序:

CREATE OR REPLACE PROCEDURE CarInfo
AS
l_result_clob clob;

BEGIN 
  SELECT serial   ||' ' || cid      ||' ' ||make      ||' ' ||model      ||' ' ||cyear||' ' ||
         color    ||' ' ||trim      ||' ' ||enginetype||' ' ||purchinv   ||' ' ||
         purchdate||' ' ||purchfrom ||' ' ||purchcost ||' ' ||freightcost||' ' ||totalcost||' ' ||listprice
    INTO l_result_clob 
    FROM CAR
   where cid is null;

  DBMS_OUTPUT.PUT_LINE(l_result_clob);

Exception
 WHEN NO_DATA_FOUND THEN
    dbms_output.put_line('No Data Found')  ;
 WHEN OTHERS THEN
    dbms_output.put_line('SQLCODE: ' || SQLCODE)  ;

END CarInfo;

当然,如果SELECT语句中的所有列实际上都可以转换为character / clob,因为Oracle会隐式转换它们,以便进行连接。

干杯

答案 1 :(得分:0)

这应该在你的异常块

之前写出来
DBMS_OUTPUT.PUT_LINE(V_serial||' ' || V_cid||' ' ||V_make||' ' ||V_model||' ' ||V_cyear||' ' ||V_color||' ' ||V_trim||' ' ||V_enginetype||' ' ||V_purchinv||' ' ||V_purchdate||' ' ||V_purchfrom ||' ' ||V_purchcost||' ' ||V_freightcost||' ' || V_totalcost||' ' ||V_listprice);