Tools to use:
First step: Create a function to get the data in the XML
CREATE function create_table (@str XML) returns @tb table (SourceID varchar) asbegin INSERT INTO @tb SELECT v.value (' @sourceId [1] ', ' VARCHAR ') as SourceIDfrom @str. Nodes ('/ Rsssources/rsssource ') x (v) return end
Step two: Create a table with a stored procedure call to the function above
CREATE PROCEDURE t_pro (@doc xml) as BEGIN CREATE TABLE tbl (sourceid varchar)INSERT into tbl select B.sourceid from create_table (@doc) b END
Step three: Call the stored procedure in the database
DECLARE @doc XML = ' <rsssources><rsssource sourceid= ' 1 "/><rsssource sourceid=" 2 "/><rsssource sourceId=" 3 "/> <rsssource sourceid= "4"/></rsssources> ' EXEC t_pro @doc
Fourth step: MyBatis call the stored procedure
<select id= "CreateTable" statementtype= "callable" resulttype= "string" > {call T_pro (#{xml})} </select>
Fifth step: Calling a stored procedure in a Java program
Sqlsessionfactory factory == = Sqlsession.getmapper (newsinfomapper. Class= "<rsssources><rsssource sourceid=\" 1\ "/><rsssource sourceid=\" 2\ "/>< Rsssource sourceid=\ "3\"/><rsssource sourceid= "4"/></rsssources> "; Mapper.createtable ( SourceXML); Sqlsession.commit (); Sqlsession.close () ;
A stored procedure in SQL Server that creates a table as an XML parameter