Probably the easiest way is to write a procedural program to do that, something like (this is PL/SQL):
Code:
DECLARE
v_nameid NUMBER := -1;
v_categoryall VARCHAR2(4000);
BEGIN
FOR r IN (SELECT nameid, category FROM table2 ORDER BY nameid, category)
LOOP
IF r.nameid != v_nameid THEN
IF v_nameid != -1 THEN
INSERT INTO table1(nameid, categoryall)
VALUES (v_nameid,v_categoryall);
END IF;
v_nameid := r.nameid;
v_categoryall := r.category;
ELSE
v_categoryall := v_categoryall||','||r.category;
END IF;
END LOOP;
/* Catch the last record */
IF v_nameid != -1 THEN
INSERT INTO table1(nameid, categoryall)
VALUES (v_nameid,v_categoryall);
END IF;
END;
There may be syntax errors in the above, I haven't run it, but you may get the idea.