0

我正在尝试制作一个程序,它将员工 id 作为输入,并为我获取包含 7 列的整行。但是,我创建了一个过程,但是当我运行它时,它会给出一个错误,指出“标识符无效”。请告诉我我做错了什么?

   create or replace procedure getdetails (empid number) 
   is 
    stmt varchar2 (1000);
    begin
    stmt :='select  * from myadmin where employe_id=empid';
    execute immediate stmt;
    end;
    /

使用下面的语句执行

begin getdetails (5); 
end;


     package pack.java;
     import pack.java.allrequestmodel;
     import java.io.*;
     import java.lang.*;
     import java.sql.*;
     import javax.servlet.*;
     import javax.servlet.http.*;
     import javax.servlet.jsp.*;
     import javax.servlet.jsp.tagext.*;

         public class allrequestcontrol extends TagSupport
       {
       HttpServletRequest request;
       HttpServletResponse response;
       String ss="";
       String emp="";
       public int doStartTag() throws JspException
       {
            request=(HttpServletRequest)pageContext.getRequest();
            response=(HttpServletResponse)pageContext.getResponse();
        return EVAL_PAGE;
        }

        public ResultSet check()
        {           
        HttpSession mysession=request.getSession();
         ss=(String)mysession.getAttribute("user");
         mysession.setAttribute("user",ss);
      JspWriter out=pageContext.getOut();
      Connection con;
      CallableStatement stmt;
      ResultSet rs=null;
          try
        {
       Class.forName("oracle.jdbc.driver.OracleDriver");
        }
        catch( ClassNotFoundException ex)
        {
        }
          try
        {

 con= DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","gaurav","oracle");
        stmt=con.prepareCall("call getdetails(?)");
        stmt.setString(1,ss);
        rs=stmt.executeQuery();
       }
        catch(SQLException ex)
       {
       }

        return rs;
       } 

         public int doEndTag() throws JspException
       {

        JspWriter out=pageContext.getOut();
        ResultSet rs= check();
        try
      {
      out.println("<table border=2>");
      out.println("<tr>");
      out.println("<th>EmployeId</th>");
      out.println("<th>Supervisor</th>");
      out.println("<th>Department</th>");
      out.println("<th>PickDate.</th>");
      out.println("<th>PickTime</th>");
      out.println("<th>DropDate</th>");
      out.println("<th>DropTime</th>");
      out.println("<th>Status</th>");
      out.println("<th></th>");
      out.println("</tr>");
      while(rs.next())
     {
     out.println("<tr>");
     out.println("<td>"+rs.getString(1)+"</td>");
     out.println("<td>"+rs.getString(2)+"</td>");
     out.println("<td>"+rs.getString(3)+"</td>");
     out.println("<td>"+rs.getString(4)+"</td>");
     out.println("<td>"+rs.getString(5)+"</td>");
     out.println("<td>"+rs.getString(6)+"</td>");
     out.println("<td>"+rs.getString(7)+"</td>");
     out.println("<td>"+rs.getString(8)+"</td>");
     out.println("<td><input type=radio name=radio value="+rs.getString(8)+"></td>");
    out.println("</tr>");
   }
   emp=(String)request.getParameter("radio");
   HttpSession mysession=request.getSession();
   mysession.setAttribute("deleteemp",emp);
  }
   catch(Exception ex)
  {
  }

   return super.doEndTag();
  }
}
4

1 回答 1

0

PL/SQL 允许您直接使用 SQL,在这种情况下您不需要动态 SQL(立即执行)。

此外,您可以将整行选择到 ROWTYPE 变量中,这将是与表中的行具有相同结构的记录类型。例如:

procedure getdetails (empid number) 
is 
  my_rec myadmin%ROWTYPE;
begin
  select *
  INTO my_rec
  from myadmin
  where employe_id=empid;
  -- now you can refer to my_rec.employe_id, etc.
end;
于 2013-10-15T04:32:04.423 回答