oracle中如何将csv转换为表格

2023-09-20数据库问题
3

本文介绍了oracle中如何将csv转换为表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

如何制作一个包,在传入 csv 值时以表格格式返回结果.

How can I make a package that returns results in table format when passed in csv values.

select * from table(schema.mypackage.myfunction('one, two, three'))

应该返回

one
two
three

我尝试了 问汤姆,但这只适用于 sql 类型.

I tried something from ask tom but that only works with sql types.

我使用的是 oracle 11g.有内置的东西吗?

I am using oracle 11g. Is there something built-in?

推荐答案

以下作品调用它作为select * from table(splitter('a,b,c,d'))

The following works invoke it as select * from table(splitter('a,b,c,d'))

create or replace function splitter(p_str in varchar2) return  sys.odcivarchar2list
is
v_tab sys.odcivarchar2list:=new sys.odcivarchar2list();
begin
with cte as (select level  ind from dual
connect by 
level <=regexp_count(p_str,',') +1
)
select regexp_substr(p_str,'[^,]+',1,ind)
bulk collect into v_tab
from cte;
return v_tab;
end;
/

这篇关于oracle中如何将csv转换为表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同
Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)...
2024-04-16 数据库问题
13

创建分层定义的数据集的扁平表/视图
Creating a flattened table/view of a hierarchically-defined set of data(创建分层定义的数据集的扁平表/视图)...
2024-04-16 数据库问题
4

MySQL:如何做到行级安全(如 Oracle 的 Virtual Private Database)?
MySQL: how to do row-level security (like Oracle#39;s Virtual Private Database)?(MySQL:如何做到行级安全(如 Oracle 的 Virtual Private Database)?)...
2024-04-16 数据库问题
6

强制执行具有完整性约束的“子集"关系的最佳方法是什么
What is the best way to enforce a #39;subset#39; relationship with integrity constraints(强制执行具有完整性约束的“子集关系的最佳方法是什么)...
2024-04-16 数据库问题
7

在 SSIS 中将带有逗号分隔符的单列数据拆分为多列
Split a single column of data with comma delimiters into multiple columns in SSIS(在 SSIS 中将带有逗号分隔符的单列数据拆分为多列)...
2024-04-16 数据库问题
8

在 SQL Server 中将字符串拆分为给定行分隔符和列分隔符的表
Split string into table given row delimiter and column delimiter in SQL server(在 SQL Server 中将字符串拆分为给定行分隔符和列分隔符的表)...
2024-04-16 数据库问题
6