• SqlServer中以xml作为参数创建表格的存储过程


    用到的工具:

    • SqlServer
    • java
    • mybatis

    第一步:创建function,用于获取xml中的数据

     CREATE function create_table (@str xml)
     returns @tb table(sourceId varchar(20))
     as
     begin
          insert into @tb 
             SELECT
             v.value('@sourceId[1]','VARCHAR(20)') AS sourceId
            FROM @str.nodes('/RSSsources/rssSource') x(v)
        return   
     end

    第二步:用存储过程调用上面的函数创建表格

    CREATE PROCEDURE T_PRO(@doc xml)
     AS
     BEGIN
        
         CREATE TABLE tbl(sourceId varchar(20))
         INSERT INTO tbl
         select b.sourceId from 
         create_table(@doc) b
     END

    第三步:在数据库中调用存储过程

     DECLARE @doc xml 
     SET @doc = '<RSSsources><rssSource sourceId="1"/><rssSource sourceId="2"/><rssSource sourceId="3"/><rssSource sourceId="4"/></RSSsources>'
    
     EXEC T_PRO @doc

    第四步:mybatis调用存储过程

    <select id="createTable" statementType="CALLABLE" resultType="string">
            {call T_PRO(#{xml})}
    </select>

    第五步:java程序中调用存储过程

    SqlSessionFactory factory = GetSqlSessionFactory.getInstance();
    SqlSession sqlSession = factory.openSession();
    NewsInfoMapper mapper = sqlSession.getMapper(NewsInfoMapper.class);
    String sourceXml = "<RSSsources><rssSource sourceId="1"/><rssSource sourceId="2"/><rssSource sourceId="3"/><rssSource sourceId="4"/></RSSsources>";
    mapper.createTable(sourceXml);
    sqlSession.commit();
    sqlSession.close();
  • 相关阅读:
    窗口程序及其反汇编
    PE文件结构及其加载机制(一)
    PE文件结构及其加载机制(三)
    RadAsm配置与第一个程序的编译
    另一个类型的窗口汇编程序及反汇编程序
    发现blogcn真的是做得不错!
    虚拟机学习
    这个blog的定位
    以前做的界面
    用Windows Server 2003搭建安全文件服务器 (转)
  • 原文地址:https://www.cnblogs.com/hzwl-2015/p/4228914.html
Copyright © 2020-2023  润新知