oracle中chr函数转换mysql_Oracle学习之:ASCII,CHR函数的作用和用法

可能有人会对回车和换行有些分不清,因为平常这两个符号是合在一起使用的。回车即回到行首,换行即换到下一行。那我们在oracle中

对于ASCII以及CHR函数的用法,Oracle给出的解释是:

ASCII(x)gets the ASCII value of the character X, CHR() and ASCII() have the opposite effect.

即:ASCII函数是用于将字符转换成其相应的ASCII码,而CHR函数作用则恰好相反;

下面我来看一些简单的例子:

SELECT ASCII('x'), ASCII('y'),ASCII('z') from dual;

语句执行的结果为 120,121,,122(即字符x,y,z对应的ASCII码分别为120,121,122)。那么SELECT CHR('120'), CHR('121'),CHR('122') from dual;的结果我们应该很容易知道。

上面我们的例子中都是单个字符,那么如果是多个字符会有什么结果呢?SELECT ASCII('xy') from dual;结果为120;SELECT ASCII('x') from dual;结果为120。从这两个例子中可能我们已经看出了什么。

"ASCII gives the ascii value of the first character of a string"即:ASCII函数只对你给出的字符串中的第一个字符起作用;

最后我们再介绍几个常用的chr()函数,chr(9);chr(10);chr(13);chr(32);chr(34),其中chr(9)是tab,chr(10)是换行符,chr(13)是回车符,chr(32)是空格符,chr(34)是双引号“"”。

可能有人会对回车和换行有些分不清,因为平常这两个符号是合在一起使用的。回车即回到行首,换行即换到下一行。那我们在oracle中用chr(13)和chr(10)会有区别吗?(结果没有区别,因为现在的语言会自动把它们转成“回车换行”)。即

declare

begin

dbms_output.put_line('huiche');

dbms_output.put_line(chr(10));

dbms_output.put_line('hhh');

end;

declare

begin

dbms_output.put_line('huiche');

dbms_output.put_line(chr(13));

dbms_output.put_line('hhh');

end;

两个块输出的结果是完全一样的。

logo.gif

本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉

本文系统来源:php中文网

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是根据您的要求编写的Python脚本,用于将GRCh38_latest_genomic.gtf文件转换为多个exon的种类RNA的bed文件: ```python import re # 定义染色体转换字典 chromosome_dict = { "NC_000001.11": "chr1", "NC_000002.12": "chr2", "NC_000003.12": "chr3", "NC_000004.12": "chr4", "NC_000005.10": "chr5", "NC_000006.12": "chr6", "NC_000007.14": "chr7", "NC_000008.11": "chr8", "NC_000009.12": "chr9", "NC_000010.11": "chr10", "NC_000011.10": "chr11", "NC_000012.12": "chr12", "NC_000013.11": "chr13", "NC_000014.9": "chr14", "NC_000015.10": "chr15", "NC_000016.10": "chr16", "NC_000017.11": "chr17", "NC_000018.10": "chr18", "NC_000019.10": "chr19", "NC_000020.11": "chr20", "NC_000021.9": "chr21", "NC_000022.11": "chr22", "NC_000023.11": "chrX", "NC_000024.10": "chrY" } # 读取gtf文件 with open('GRCh38_latest_genomic.gtf', 'r') as gtf_file: lines = gtf_file.readlines() transcripts = {} # 存储符合条件的transcript # 提取符合条件的transcript for line in lines: if line.startswith('#'): # 跳过注释行 continue columns = line.strip().split('\t') if columns[2] == 'transcript': attributes = re.findall(r'(\w+)\s+"([^"]+)"', columns[8]) gene_id = None transcript_id = None for attr in attributes: if attr[0] == 'gene_id': gene_id = attr[1] elif attr[0] == 'transcript_id': transcript_id = attr[1] if gene_id and transcript_id: if gene_id not in transcripts: transcripts[gene_id] = transcript_id else: # 比较长度并保留最大的transcript_id max_length = int(columns[4]) - int(columns[3]) curr_length = int(lines[transcripts[gene_id]].split('\t')[4]) - int(lines[transcripts[gene_id]].split('\t')[3]) if max_length > curr_length: transcripts[gene_id] = transcript_id # 提取exon行信息并转换为bed格式 bed_lines = [] # 存储bed文件的内容 for line in lines: if line.startswith('#'): # 跳过注释行 continue columns = line.strip().split('\t') if columns[2] == 'exon': attributes = re.findall(r'(\w+)\s+"([^"]+)"', columns[8]) transcript_id = None for attr in attributes: if attr[0] == 'transcript_id': transcript_id = attr[1] if transcript_id and transcript_id in transcripts.values(): chromosome = columns[0] start = columns[3] end = columns[4] gene_id = re.findall(r'gene_id\s+"([^"]+)"', columns[8])[0] strand = columns[6] # 检查染色体是否需要转换 if chromosome in chromosome_dict: chromosome = chromosome_dict[chromosome] else: continue bed_line = f"{chromosome}\t{start}\t{end}\t{gene_id}\t1000\t{strand}" bed_lines.append(bed_line) # 写入bed文件 with open('output.bed', 'w') as bed_file: bed_file.write('\n'.join(bed_lines)) print("转换完成,bed文件已生成。") ``` 请将您的`GRCh38_latest_genomic.gtf`文件与上述代码放在同一目录下,并执行该脚本,即可生成名为`output.bed`的bed文件。希望这能满足您的需求!如有其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值