简体   繁体   English

在mysql中创建临时表的存储过程

[英]stored procedure with creating temporary table in mysql

CREATE PROCEDURE getpatientclaim(IN idd int)  BEGIN 

create temporary table spec(patient_id int,claim_id int,procedure_code int);

insert INTO spec SELECT p.patient_id,p.claim_id,p.procedure_code FROM 
payment p LEFT JOIN patient_visit_cpt pvc ON p.patient_id = pvc.patient_id
WHERE p.claim_id = idd; 
END

it successfully created and i tried to call procedure like this 它创建成功,我试图调用这样的过程

call getpatientclaim(4963);

output comes like : 输出如下:

it returned an empty result set. 它返回一个空结果集。

The select query returns many rows but in procedure it returns empty. 选择查询返回许多行,但在过程中返回空。 please help 请帮忙

Add

SELECT * FROM `spec`;

at the end of your procedure body (before END ). 在过程正文的末尾(在END之前)。

But do you really need a temporary table for this? 但是您真的需要一个临时表吗? Just 只是

CREATE PROCEDURE getpatientclaim(IN idd int)  BEGIN 
     SELECT p.patient_id,p.claim_id,p.procedure_code 
     FROM payment p LEFT JOIN patient_visit_cpt pvc ON p.patient_id = pvc.patient_id
     WHERE p.claim_id = idd; 
END

would produce the same outcome. 会产生相同的结果。 (And in that case a VIEW would probably more appropriate.) (在这种情况下, VIEW可能更合适。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM