• 2.3 字符串链接


    package main
    
    import (
    	"fmt"
    	"strings"
    )
    
    const selectBase = "SELECT * FROM user WHERE %s "
    
    var refStringSlice = []string{
    	" FIRST_NAME = 'Jack' ",
    	" INSURANCE_NO = 333444555 ",
    	" EFFECTIVE_FROM = SYSDATE "}
    
    func main() {
    
    	sentence := strings.Join(refStringSlice, "AND")
    	fmt.Printf(selectBase+"
    ", sentence)
    
    }
    
    /*
    SELECT * FROM user WHERE  FIRST_NAME = 'Jack' AND INSURANCE_NO = 333444555 AND EFFECTIVE_FROM = SYSDATE
    
    */
    
    
    

    package main
    
    import (
    	"fmt"
    	"strings"
    )
    
    const selectBase = "SELECT * FROM user WHERE "
    
    var refStringSlice = []string{
    	" FIRST_NAME = 'Jack' ",
    	" INSURANCE_NO = 333444555 ",
    	" EFFECTIVE_FROM = SYSDATE "}
    
    type JoinFunc func(piece string) string
    
    func main() {
    
    	jF := func(p string) string {
    		if strings.Contains(p, "INSURANCE") {
    			return "OR"
    		}
    
    		return "AND"
    	}
    	result := JoinWithFunc(refStringSlice, jF)
    	fmt.Println(selectBase + result)
    }
    
    func JoinWithFunc(refStringSlice []string, joinFunc JoinFunc) string {
    	concatenate := refStringSlice[0]
    	for _, val := range refStringSlice[1:] {
    		concatenate = concatenate + joinFunc(val) + val
    	}
    	return concatenate
    }
    
    /*
    SELECT * FROM user WHERE  FIRST_NAME = 'Jack' OR INSURANCE_NO = 333444555 AND EFFECTIVE_FROM = SYSDATE 
    
    */
    
    
  • 相关阅读:
    转 :table的边框属性设置总结
    Redis Sentinel 配置文件
    nginx unit的初探
    负载均衡器之 Haproxy
    利用python itchat给女朋友定时发信息
    nginx unit 的使用
    Redis Sentinel 模拟故障迁移
    Python 获取车票信息
    Nginx unit 源码安装初体验
    初识 Proxysql
  • 原文地址:https://www.cnblogs.com/zrdpy/p/8620366.html
Copyright © 2020-2023  润新知