可以这样:
select substr(max(sys_connect_by_path(字段名,',')),2) 别名 from
(
select 字段名,rn,lead(rn) over(partition by 字段名 order by rn) rn1
from (select 字段名,row_number() over(order by 字段名 desc) rn from 表)
)
start with rn1 is null connect by rn1 = prior rn
group by 字段名
select substr(max(sys_connect_by_path(字段名,',')),2) 别名 from
(
select 字段名,rn,lead(rn) over(partition by 字段名 order by rn) rn1
from (select 字段名,row_number() over(order by 字段名 desc) rn from 表)
)
start with rn1 is null connect by rn1 = prior rn
group by 字段名
解决方案 »
- Oracle安装后登入 没有监听器
- Kettle 将DB2中的表导入oracle是遇到的问题!!!
- ORA-04031: unable to allocate 4200 bytes of shared memory
- ORACLE APPLICATION R11I RAPID CLONE
- 创建varray类型出错!
- oracle内存不足问题..急...
- 按时间分段查询人员所在机构,怎么用sql实现?
- 求一个带有执行动态SQL+异常处理的存储过程.
- 高手帮忙一下,在linux上安装oracle8.16,出现:ORA-12547:TNS:丢失联系 的错误 在线等待,50分
- 为什么我的98机子,装oracle 客户端,sql plus 连接不通??????? 急!!(我的 net8 configurration assistant 测试是成功的)
- 安装oracle10g的问题!在线等!!!急啊!!
- 请问Oracle数据库中有哪些基本的数据类型?
SET ECHO OFF
SET SERVEROUTPUT ON SIZE 10000
CREATE OR REPLACE PROCEDURE GET_COLS (TABLE_NAME IN VARCHAR2) AUTHID CURRENT_USER
IS
theOWNER VARCHAR2(30);
theTABLE VARCHAR2(30);
str VARCHAR2(4000):='';
BEGIN
IF INSTR(TABLE_NAME,'.')>0 THEN
theOWNER:=UPPER(SUBSTR(TABLE_NAME,1,INSTR(TABLE_NAME,'.')-1));
theTABLE:=UPPER(SUBSTR(TABLE_NAME,INSTR(TABLE_NAME,'.')+1));
ELSE
theOWNER:=USER;
theTABLE:=UPPER(TABLE_NAME);
END IF; str:='';
FOR CUR IN(
SELECT COLUMN_NAME FROM ALL_TAB_COLS WHERE OWNER=theOWNER AND TABLE_NAME=theTABLE ORDER BY COLUMN_ID
)LOOP
str:= str || ',' || CUR.COLUMN_NAME;
END LOOP; DBMS_OUTPUT.PUT_LINE(SUBSTR(str,2));
END GET_COLS;
/--仅Oracle9i以上可用
SELECT MAX(SUBSTR(SYS_CONNECT_BY_PATH(COLUMN_NAME, ','),2)) COL
FROM (SELECT COLUMN_ID,COLUMN_NAME FROM USER_TAB_COLUMNS WHERE TABLE_NAME='&TABLE_NAME')
START WITH COLUMN_ID=1
CONNECT BY COLUMN_ID=ROWNUM;