select max(substr(SYS_CONNECT_BY_PATH(COLUMN_NAME, ','), 2))
into m_col
from (select decode(UPPER(COLUMN_NAME),'ID','AAID',COLUMN_NAME) as COLUMN_NAME,column_id
from dba_tab_columns
where table_name = UPPER(m_tabname))
start with column_id = 1
connect by column_id = rownum;
---取得VALUE列名 除ID
m_col:=replace(m_col,'AAID,','');
m_col:=replace(m_col,'MAIN_ID,','');
---新增该表记录(明细)复制
m_sql := 'insert into '||m_tabname||' select grua_sequent.nextval,'||m_mainid||',' || m_col ||' from '||m_tabname||' where main_id='||i_grua_id;
execute immediate m_sql ;
commit;