简体   繁体   中英

how to patabless result of mysql stored procedure inside temporary

I have one stored procedure with one in parameter that returns multiple rows with 3 different columns. I want this result to be inserted inside another table with these 3 column filed and other tables individual fields.

However, when I create the temporary table it shows a blank resultset.

Can anybody help me to sort out this?

CREATE DEFINER=`root`@`localhost` PROCEDURE `getContactRolePermission`(
in contactroleid double
-- inout PermissionTableID double
)
BEGIN

select -- entitydetails.id,
 contact.id as userid,
 -- contacttyperolemap.contacttypeId ,
 contacttyperolemap.roleid ,rolepermission.permissionid
 from contacttyperolemap 
 join rolepermission on contacttyperolemap.roleid=rolepermission.roleid
 join entitydetails on  entitydetails.id = contacttyperolemap.ContactTypeID 
 join contact on contact.contactTypeID = entitydetails.id 
 where  contacttyperolemap.contactTypeID = contactroleid
 order by contact.id;

CREATE temporary TABLE tmp(
     ID double ,
    userid double ,
    roleid double ,
    permissionid double
);

END


stored procedures result is
uid rid pid 
2   1   5
2   1   2
2   1   3
2   1   4
2   1   1
23  1   4
23  1   1
23  1   5
23  1   2
23  1   3
26  1   4
26  1   1
26  1   5
26  1   2
26  1   3

I want to insert this data inside userpermission table

schema is
id  uid rid pid
1   10  2   1

Looks like you need to create a view instead of a stored procedure for the first 3 rows. Then in a separate query you can query any columns from that view and join that data with whatever other data you want from other tables. Hopefully I read the question right. Heres an article on creating views: https://msdn.microsoft.com/en-us/library/ms187956.aspx

Use INSERT ... SELECT command to fill target table.

And, your temp table shows empty result, because you have not filled it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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