如何从一个表中获取数据到一个特定的id搜索plsql的在线?

时间:2017-02-27 15:27:07

标签: html sql plsql toad

我有一个程序,用户输入"学生ID"搜索并查看该个人的详细信息。我知道这个inst是正确的,我有更多的语法可写,但到目前为止这就是我所拥有的: -

请注意我已声明所有变量和我的表列名称和类型都是正确的。我还没有运行代码,因为我确定我错过了更多的东西。所以请帮忙。我在plsql中编写了forad for oracle的代码。

以下代码用于获取数据并将其放在特定字段上。

BEGIN
-- fetching data from table 'unsus' 
    IF EXISTS SELECT UNSUS_STUDENT_NO student_no,
                     UNSUS_STUDENT_NAME name,
                     UNSUS_SUSPEND_ACCOUNT suspend_acc,
                     UNSUS_UNSUSPEND_DATE unsus_date,
                     UNSUS_USER_ID user_id
              FROM   SATURN.UNSUS
              WHERE  UNSUS_SUSPEND_NO = ('000123456');

-- opening table rows (form based)
twbkfrmt.P_TableRowOpen;
twbkfrmt.P_TableData ('Student ID');
twbkfrmt.P_TableData ('Full Name');
twbkfrmt.P_TableData ('Suspended ?');
twbkfrmt.P_TableData ('Unsuspension Date');
twbkfrmt.P_TableData ('Added On ?');
twbkfrmt.P_TableData ('Altered By');
twbkfrmt.P_TableRowOpen;

-- table data adding onto form fields
            twbkfrmt.p_TableDataWhite (HTF.formtext (
                                        cname        => '',
                                        csize        => 25,
                                        cmaxlength   => 9,
                                        cvalue       => student_no,
                                        cattributes  => 'style="font-size:12px" readonly ' || disabled));

            twbkfrmt.p_TableDataWhite (HTF.formtext (
                                        cname        => '',
                                        csize        => 60,
                                        cmaxlength   => 60,
                                        cvalue       => name,
                                        cattributes  => 'style="font-size:12px" readonly ' || disabled));

            twbkfrmt.p_TableDataWhite (HTF.formtext (
                                        cname        => '',
                                        csize        => 15,
                                        cmaxlength   => 5,
                                        cvalue       => suspend_acc,
                                        cattributes  => 'style="font-size:12px" readonly ' || disabled));

            twbkfrmt.p_TableDataWhite (HTF.formtext (
                                        cname        => '',
                                        csize        => 20,
                                        cmaxlength   => 15,
                                        cvalue       => unsus_date,
                                        cattributes  => 'style="font-size:12px" readonly ' || disabled));               

            twbkfrmt.p_TableDataWhite (HTF.formtext (
                                        cname        => '',
                                        csize        => 20,
                                        cmaxlength   => 15,
                                        --cvalue       => ,
                                        cattributes  => 'style="font-size:12px" readonly ' || disabled));       

            twbkfrmt.p_TableDataWhite (HTF.formtext (
                                        cname        => '',
                                        csize        => 30,
                                        cmaxlength   => 30,
                                        cvalue       => user_id,
                                        cattributes  => 'style="font-size:12px" readonly ' || disabled));   

2 个答案:

答案 0 :(得分:2)

有几种方法可以解决这个问题。标准方法,它快速闪亮,只是选择数据并具有no_data_found异常。我希望你没有用表名开头所有的列名,这不是恕我直言的好习惯。

DECLARE
    l_student_no        saturn.unsus.student_no%TYPE;
    l_student_name      saturn.unsus.student_name%TYPE;
    l_suspend_account   saturn.unsus.suspend_account%TYPE;
BEGIN
    SELECT student_no, student_name, suspend_account
      INTO l_student_no, l_student_name, l_suspend_account
      FROM saturn.unsus
     WHERE suspend_no = ('000123456');

    -- you have your data, do your HTML formatting.
    twbkfrmt.p_tabledatawhite (
        HTF.formtext (
            cname       => ''
          , csize       => 25
          , cmaxlength  => 9
          , cvalue      => l_student_no
          , cattributes => 'style="font-size:12px" readonly ' || disabled
        )
    );
-- ...
EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
        -- code jumps to here when the suspend_no is not found
        -- the null means just ignore no_data_found
        NULL;
END;

答案 1 :(得分:1)

只需检查该集是否存在。

SELECT COUNT(UNSUS_STUDENT_NO) INTO studentCount FROM SATURN.UNSUS
          WHERE  UNSUS_SUSPEND_NO = ('000123456');

IF studentCount > 0 THEN
  -- Insert all logic here.
END IF;