postsql字符串字段转数字用法

postsql用法TO_NUMBER(text,modetext)

select TO_NUMBER(max(ghdwbm), '9999999999999')+1  from lq_ghdw where xzqdm='340304100'

判断为空的用法

SELECTTO_NUMBER( CASE WHEN MAX ( ghdwbm ) IS NULL THEN '0' ELSE MAX ( ghdwbm ) END ,'9999999999999' ) + 1
FROMlq_ghdw
WHERExzqdm = '340304100'
//postsql用法 取数据库字段值最大值加1,并取最大值的后二位数值var sql  = "select TO_NUMBER( CASE WHEN MAX ( ghdwbm ) IS NULL THEN '0' ELSE MAX ( ghdwbm ) END, '9999999999999' ) + 1  from lq_ghdw where xzqdm='"+dwdm+"'";GetValueBySQL(sql,function(d){if(d){d+="";SetValue('textbox12',d);if(d.length==1){SetValue('textbox11', '0'+d);   //不够2位前面补0}else {SetValue('textbox11', d.substring(d.length-2,d.length));}}});

postsql数字字段取最大值加1的功能

var max1_sql='select (case when max(id) is null then 0 else max(id) end)+1 from lq_jg_cl';
SetValueBySQL('textbox4',max1_sql);

postsql保存表单写法一例:

if(fmode=='insert')
{var max_sql = 'select (case when max(id) is null then 0 else max(id) end)+1 from lq_task_xc';SetValueBySQL('textbox2',max_sql);
}
SaveForm2(function(){parent.GetObject('grid1').RefreshViewData();parent.CloseForm(true);
});

mysql用法

select max(ghdwbm)+1  from lq_ghdw where xzqdm='340304100'

其它postsql函数参考地址:
https://www.cnblogs.com/wangyhua/p/4050520.html

postsql 其它字符串函数
函数:string || string 
说明:String concatenation 字符串连接操作
例子:select ‘Post’ || ‘greSQL’; = PostgreSQL

函数:string || non-string or non-string || string
说明:String concatenation with one non-string input 字符串与非字符串类型进行连接操作
例子:select 'Value: ’ || 42; = Value: 42

函数:bit_length(string)
说明:Number of bits in string 计算字符串的位数
例子:select bit_length(‘pmars’); = 40

函数:char_length(string) or character_length(string)
说明:Number of characters in string 计算字符串中字符个数
例子:select char_length(‘pmars’); = 5

函数:lower(string)
说明:Convert string to lower case 转换字符串为小写
例子:select lower(‘PmArS’); = “pmars”

函数:octet_length(string)
说明:Number of bytes in string 计算字符串的字节数
例子:select octet_length(‘我是pmars’); = 11 select octet_length(‘我’); = 3

函数:overlay(string placing string from int [for int])
说明:Replace substring 替换字符串中任意长度的子字串为新字符串
例子:select overlay(‘I am pmars’ placing ‘ming’ from 6 for 5); = “I am ming”

函数:position(substring in string)
说明:Location of specified substring 子串在一字符串中的位置
例子:select position(‘ma’ in ‘pmars’); = 2

函数:substring(string [from int] [for int])
说明:Extract substring 截取任意长度的子字符串
例子:select substring(‘topmars’ from 3 for 3); = “pma”

函数:substring(string from pattern)
说明:Extract substring matching POSIX regular expression. See Section 9.7 for more information on pattern matching. 利用正则表达式对一字符串进行任意长度的字串的截取
例子:select substring(‘topmars’ from ‘p.*$’); = “pmars”

函数:substring(string from pattern for escape)
说明:Extract substring matching SQL regular expression. See Section 9.7 for more information on pattern matching. 利于正则表达式对某类字符进行删除,以得到子字符串
例子:select substring(‘Thomas’ from ‘%#“o_a#”_’ for ‘#’); = “oma”

函数:trim([leading | trailing | both] [characters] from string)
说明:Remove the longest string containing only the characters (a space by default) from the start/end/both ends of the string 去除尽可能长开始,结束或者两边的某类字符,默认为去除空白字符,当然可以自己指定,可同时指定多个要删除的字符串
例子:select trim(leading ‘p’ from ‘pmars’); = “mars”

函数:upper(string)
说明:Convert string to uppercase 将字符串转换为大写
例子:select upper(‘pmars’); = “PMARS”

函数:ascii(string)
说明:ASCII code of the first character of the argument. For UTF8 returns the Unicode code point of the character. For other multibyte encodings. the argument must be a strictly ASCII character. 得到某一个字符的Assii值
例子:select ascii(‘pmars’); = select ascii(‘p’); = 112

函数:btrim(string text [, characters text])
说明:Remove the longest string consisting only of characters in characters (a space by default) from the start and end of string 去除字符串两边的所有指定的字符,可同时指定多个字符
例子:select btrim(‘pmars’,‘prs’); = “ma”

函数:chr(int)
说明:Character with the given code. For UTF8 the argument is treated as a Unicode code point. For other multibyte encodings the argument must designate a strictly ASCII character. The NULL (0) character is not allowed because text data types cannot store such bytes. 得到某ACSII值对应的字符
例子:select chr(65); = A

函数:convert(string bytea, src_encoding name, dest_encoding name)
说明:Convert string to dest_encoding. The original encoding is specified by src_encoding. The string must be valid in this encoding. Conversions can be defined by CREATE CONVERSION. Also there are some predefined conversions. See Table 9-7 for available conversions. 转换字符串编码,指定源编码与目标编码
例子:select convert(‘我是pmars_in_utf8’, ‘UTF8’, ‘GBK’); = “\316\322\312\307pmars_in_utf8”

函数:convert_from(string bytea, src_encoding name)
说明:Convert string to the database encoding. The original encoding is specified by src_encoding. The string must be valid in this encoding. 转换字符串编码,自己要指定源编码,目标编码默认为数据库指定编码,
例子:select convert_from(’\316\322\312\307pmars’,‘GBK’); = “我是pmars”

函数:convert_to(string text, dest_encoding name)
说明:Convert string to dest_encoding.转换字符串编码,源编码默认为数据库指定编码,自己要指定目标编码,
例子:select convert_to(‘我是pmars_in_utf8’,‘GBK’); = “\316\322\312\307pmars_in_utf8”

函数:decode(string text, type text)
说明:Decode binary data from string previously encoded with encode. Parameter type is same as in encode. 对字符串按指定的类型进行解码
例子:select decode(‘MTIzAAE=’, ‘base64’); = “123\000\001”

函数:encode(data bytea, type text)
说明:Encode binary data to different representation. Supported types are: base64, hex, escape. Escape merely outputs null bytes as \000 and doubles backslashes. 与decode相反,对字符串按指定类型进行编码
例子:select encode(‘123\000\001’,‘base64’); = “MTIzAAE=”

函数:initcap(string)
说明:Convert the first letter of each word to uppercase and the rest to lowercase. Words are sequences of alphanumeric characters separated by non-alphanumeric characters. 将字符串所有的单词进行格式化,首字母大写,其它为小写
例子:select initcap(‘I AM PMARs’); = “I Am Pmars”

函数:length(string)
说明:Number of characters in string 讲算字符串长度
例子:select length(‘我是pmars’); = 7

函数:length(stringbytea, encoding name )
说明:Number of characters in string in the given encoding. The string must be valid in this encoding. 计算字符串长度,指定字符串使用的编码
例子:select length(‘我是pmars’,‘GBK’); = 8

函数:lpad(string text, length int [, fill text])
说明:Fill up the string to length length by prepending the characters fill (a space by default). If the string is already longer than length then it is truncated (on the right). 对字符串左边进行某类字符自动填充,即不足某一长度,则在左边自动补上指定的字符串,直至达到指定长度,可同时指定多个自动填充的字符
例子:select lpad(‘pmars’, 10, ‘to’); = “tototpmars”

函数:ltrim(string text [, characters text])
说明:Remove the longest string containing only characters from characters (a space by default) from the start of string 删除字符串左边某一些的字符,可以时指定多个要删除的字符
例子:select ltrim(‘pmars’,‘amp’); = “rs”

函数:md5(string)
说明:Calculates the MD5 hash of string, returning the result in hexadecimal 将字符串进行md5编码
例子:select md5(‘pmars’); = “1018ceb949f1472f7252f7da1f5eff42”

函数:pg_client_encoding()
说明:Current client encoding name 得到pg客户端编码
例子:select pg_client_encoding(); = “UTF8”

函数:quote_ident(string text)
说明:Return the given string suitably quoted to be used as an identifier in an SQL statement string. Quotes are added only if necessary (i.e., if the string contains non-identifier characters or would be case-folded). Embedded quotes are properly doubled. 对某一字符串加上两引号
例子:quote_ident(‘Foo bar’) = “Foo bar”

函数:quote_literal(string text)
说明:Return the given string suitably quoted to be used as a string literal in an SQL statement string. Embedded single-quotes and backslashes are properly doubled. 对字符串里两边加上单引号,如果字符串里面出现sql编码的单个单引号,则会被表达成两个单引号
例子:quote_literal(‘O’Reilly’) = ‘O’‘Reilly’

函数:quote_literal(value anyelement)
说明:Coerce the given value to text and then quote it as a literal. Embedded single-quotes and backslashes are properly doubled. 将一数值转换为字符串,并为其两边加上单引号,如果数值中间出现了单引号,也会被表示成两个单引号
例子:quote_literal(42.5) = ‘42.5’

函数:regexp_matches(string text, pattern text [, flags text])
说明:Return all captured substrings resulting from matching a POSIX regular expression against the string. See Section 9.7.3 for more information. 对字符串按正则表达式进行匹配,如果存在则会在结果数组中表示出来
例子:regexp_matches(‘foobarbequebaz’, ‘(bar)(beque)’) = {bar,beque}

函数:regexp_replace(string text, pattern text, replacement text [, flags text])
说明:Replace substring(s) matching a POSIX regular expression. See Section 9.7.3 for more information. 利用正则表达式对字符串进行替换
例子:regexp_replace(‘Thomas’, ‘.[mN]a.’, ‘M’) = ThM

函数:regexp_split_to_array(string text, pattern text [, flags text ])
说明:Split string using a POSIX regular expression as the delimiter. See Section 9.7.3 for more information. 利用正则表达式将字符串分割成数组
例子:regexp_split_to_array(‘hello world’, E’\s+’) = {hello,world}

函数:regexp_split_to_table(string text, pattern text [, flags text])
说明:Split string using a POSIX regular expression as the delimiter. See Section 9.7.3 for more information. 利用正则表达式将字符串分割成表格
例子:regexp_split_to_table(‘hello world’, E’\s+’) =
hello
world
(2 rows)

函数:repeat(string text, number int)
说明:Repeat string the specified number of times 重复字符串一指定次数
例子:repeat(‘Pg’, 4) = PgPgPgPg

函数:replace(string text, from text, to text)
说明:Replace all occurrences in string of substring from with substring to 将字符的某一子串替换成另一子串
例子:(‘abcdefabcdef’, ‘cd’, ‘XX’) = abXXefabXXef

函数:rpad(string text, length int [, fill text])
说明:Fill up the string to length length by appending the characters fill (a space by default). If the string is already longer than length then it is truncated. 对字符串进行填充,填充内容为指定的字符串
例子:rpad(‘hi’, 5, ‘xy’) = hixyx

函数:rtrim(string text [, characters text])
说明:Remove the longest string containing only characters from characters (a space by default) from the end of string
去除字符串右边指定的字符
例子:rtrim(‘trimxxxx’, ‘x’) = trim

函数:split_part(string text, delimiter text, field int)
说明:Split string on delimiter and return the given field (counting from one) 对字符串按指定子串进行分割,并返回指定的数值位置的值
例子:split_part(‘abc@def@ghi’, ‘@’, 2) = def

函数:strpos(string, substring)
说明:Location of specified substring (same as position(substring in string), but note the reversed argument order) 指定字符串在目标字符串的位置
例子:strpos(‘high’, ‘ig’) = 2

函数:substr(string, from [, count])
说明:Extract substring (same as substring(string from from for count)) 截取子串
例子:substr(‘alphabet’, 3, 2) = ph

函数:to_ascii(string text [, encoding text])
说明:Convert string to ASCII from another encoding (only supports conversion from LATIN1, LATIN2, LATIN9, and WIN1250 encodings) 将字符串转换成ascii编码字符串
例子:to_ascii(‘Karel’) = Karel

函数:to_hex(number int or bigint)
说明:Convert number to its equivalent hexadecimal representation  对数值进行十六进制编码
例子:to_hex(2147483647) = 7fffffff

函数:translate(string text, from text, to text)
说明:Any character in string that matches a character in the from set is replaced by the corresponding character in the to set 将字符串中某些匹配的字符替换成指定字符串,目标字符与源字符都可以同时指定多个
例子:translate(‘12345’, ‘14’, ‘ax’) = a23x5

标签: PostgreSQL

postsql字符串字段转数字用法相关推荐

  1. Mysql字符串截取 mysql将字符串字段转为数字排序或比大小

    SELECT * FROM Student WHERE 1 = 1 ORDER BY -ID DESC ; SELECT * FROM Student WHERE 1 = 1 ORDER BY (ID ...

  2. mysql将字符串字段转为数字排序或比大小

    SELECT * FROM Student WHERE 1 = 1 ORDER BY -ID DESC ; SELECT * FROM Student WHERE 1 = 1 ORDER BY (ID ...

  3. mysql sql 字符串字段保留数字_sql中取字符串中的数字语句_MySQL

    bitsCN.com one: declare @s varchar(20) declare @i varchar(20) set @i='' set @s='新会员必须购买350元产品' while ...

  4. mysql sql 字符串字段保留数字_SQL字符串以及数字常用操作汇总

    SQL字符串以及数字常用操作汇总 更新时间:2013年06月11日 09:05:12   作者: 本篇文章是对SQL字符串以及数字的常用操作进行了详细的总结与分析,需要的朋友参考下 --将字符串中从某 ...

  5. Swift3 Scanner用法之判断是否数字、提取字符串里的数字

    1.判断是否数字 /// 判断是否是数字////// - Parameter string: <#string description#>/// - Returns: <#retur ...

  6. MySQL判断字符串是否是数字

    采用REGEXP运算符 {String} REGEXP '[^0-9.]' isNotNum : true 不是数字 , false 是数字,字符串中有空格也会被判断出来 select ('123' ...

  7. php bc 取字符串长度,PHP bcsqrt()用法及代码示例

    PHP中的bcsqrt()函数是一个内置函数,用于评估任意精度数的平方根.此函数接受任意精度数字作为字符串,并在将结果缩放到指定精度后返回数字的平方根. 用法: string bcsqrt ( $nu ...

  8. 如何在Java中检查字符串是否为数字

    在解析字符串之前,如何检查字符串是否为数字? #1楼 解析它(即使用Integer#parseInt )并简单地捕获异常. =) 需要澄清的是:parseInt函数检查它是否可以在任何情况下(显然)都 ...

  9. python正则表达式提取数字比较好_python正则表达式从字符串中提取数字的思路详解...

    python从字符串中提取数字 使用正则表达式,用法如下: ## 总结 ## ^ 匹配字符串的开始. ## $ 匹配字符串的结尾. ## \b 匹配一个单词的边界. ## \d 匹配任意数字. ## ...

  10. mysql提取数字_Mysql中实现提取字符串中的数字的自定义函数分享

    因需要在mysql的数据表中某一字符串中的字段提取出数字,在网上找了一通,终于找到了一个可用的mysql函数,可以有效的从字符串中提取出数字. 该mysql提取出字符串中的数字函数如下: 复制代码 代 ...

最新文章

  1. c# 逆转数组元素的排序
  2. 欧洲打击洗钱 全球联合行动 178名钱骡落网
  3. Uploadify v3.2.1
  4. 使用word完成毕业论文的所有详细步骤
  5. Eigen入门之密集矩阵 6 - Reductions, visitors and broadcasting
  6. 嵌入式系统Linux内核开发工程师必须掌握的三十道题
  7. Centos7 +Django的安装
  8. B3log 分布式社区的 Java 博客端节点系统
  9. input 对伪元素(:before :after)的支持情况
  10. shell脚本发邮件内容html,Shell发送邮件以HTML展示
  11. RestTemplate返回List类型,用数组接收
  12. 字符串 - KMP模式匹配
  13. React学习笔记 - 组件Props
  14. 牛客网-公司真题-买帽子
  15. XmlAttribute与实体的转换和匹配方案(附源码)
  16. unix系列系统镜像下载
  17. Mac中将Apple移动设备(iPhone或iPad)屏幕录屏转换为gif图片的极简方法
  18. R语言中的rgl包的安装问题
  19. 上传webshell(入侵目标页面主机靶机演示)
  20. 【项目篇-资料获取】怎么获取创新创业比赛资料、优秀作品?如何去借鉴?

热门文章

  1. 【MFC】如何使用MFC?MFC如何编写界面?MFC使用零基础教程
  2. Fortran入门教程(六)——循环结构
  3. 为openstack制作windows镜像
  4. 【photoshop Action Manager】动作管理器- 获取预设管理器信息
  5. 下载主题jar包并导入到idea
  6. 产品配件类目税目分类_商品类别税率一览表
  7. Selenium3 Java自动化测试完整教程
  8. Unity美术字体教程--BMFont美术字体的制作流程以及在unity中美术字体的生成
  9. android json解析歌词,网易云歌词获取
  10. 求PIFA天线相关介绍