我在mysql中创建了这个
CREATE VIEW MYVIEW AS (
SELECT A.FNAME,A.LNAME,B.EMAIL
FROM EMPLOYEE A,EMPEMAIL B
WHERE A.EID = :empId
AND A.EID = B.EID
AND B.EMAILTYP = :emailType)
现在我想让“empId”和“emailType”动态化.我的意思是在选择时传递值.
什么需要改变代码?
提前
最佳答案
只需创建没有参数的视图(即仅处理连接):
CREATE VIEW MYVIEW AS (
SELECT A.FNAME,B.EMAIL,A.EID AS EID,B.EMAILTYP AS EMAILTYP
FROM EMPLOYEE A,EMPEMAIL B
WHERE A.EID = B.EID)
并在查询时应用动态参数:
SELECT FNAME,LNAME,EMAIL
FROM my_view
WHERE eid = :empId AND emailtyp = :emailType