Home » SQL & PL/SQL » SQL & PL/SQL » sys_guid() help with bulk insert (11g r2)
sys_guid() help with bulk insert [message #587151] Wed, 12 June 2013 14:09 Go to next message
rexi
Messages: 7
Registered: June 2013
Junior Member
I am trying to insert from 3 different files in 3 tables and I am finding that the same id is being inserted for each row.
Any ideas what I am doing wrong?

thanks


DECLARE
    
	F UTL_FILE.FILE_TYPE;
    V_LINE VARCHAR2 (1000);
    V_Name varchar2(512 char);
    V_ParentUID raw(16);
    V_Path varchar2(1024 char);
    V_PrimaryType varchar2(32 char);
    V_SubType varchar2(32 char);
    V_GeneralType number(5,0);
    V_Undeletable number(1,0);
    V_ErrorWarningStatus number(10,0);
    V_ComplianceStatus number(10,0);
    V_Description clob;
	
	
	
	Q UTL_FILE.FILE_TYPE;
    G_LINE VARCHAR2 (1000);
    G_FilterString clob;
    G_LogHistoryCount number(5,0);
   

   
  T UTL_FILE.FILE_TYPE;
    X_LINE VARCHAR2 (1000);
    X_contextid raw(16);
    X_position number(10,0);
	
	
  folderUID raw(16);
  
  o_zuid folderUID%type;
  
  BEGIN
	
	
  F := UTL_FILE.FOPEN ('SOU', 'zenobject.csv', 'R');
	Q := UTL_FILE.FOPEN ('SOU', 'querygroup.csv', 'R');
	T := UTL_FILE.FOPEN ('SOU', 'querycontext.csv', 'R');
    IF UTL_FILE.IS_OPEN(F) AND UTL_FILE.IS_OPEN(Q) AND UTL_FILE.IS_OPEN(T) THEN
      LOOP
        BEGIN
          UTL_FILE.GET_LINE(F, V_LINE, 1000);
           UTL_FILE.GET_LINE(Q, G_LINE, 1000);
           UTL_FILE.GET_LINE(T, X_LINE, 1000);
          IF V_LINE IS NULL THEN
            EXIT;
          END IF;
          IF G_LINE IS NULL THEN
            EXIT;
          END IF;
          IF X_LINE IS NULL THEN
            EXIT;
          END IF;
          V_Name := REGEXP_SUBSTR(V_LINE, '[^,]+', 1, 1);
          V_ParentUID := REGEXP_SUBSTR(V_LINE, '[^,]+', 1, 2);
          V_Path := REGEXP_SUBSTR(V_LINE, '[^,]+', 1, 3);
          V_PrimaryType := REGEXP_SUBSTR(V_LINE, '[^,]+', 1, 4);
          V_SubType := REGEXP_SUBSTR(V_LINE, '[^,]+', 1, 5);
          V_GeneralType := REGEXP_SUBSTR(V_LINE, '[^,]+', 1, 6);
          V_Undeletable := REGEXP_SUBSTR(V_LINE, '[^,]+', 1, 7);
          V_ErrorWarningStatus := REGEXP_SUBSTR(V_LINE, '[^,]+', 1, 8);
          V_ComplianceStatus := REGEXP_SUBSTR(V_LINE, '[^,]+', 1, 9);
          V_Description := REGEXP_SUBSTR(V_LINE, '[^,]+', 1, 10);
		  
          G_LogHistoryCount := REGEXP_SUBSTR(G_LINE, '[^,]+', 1, 1);
          G_FilterString := REGEXP_SUBSTR(G_LINE, '[^,]+', 1, 2);
          
      
          X_contextid := REGEXP_SUBSTR(X_LINE, '[^,]+', 1, 1);
          X_position := REGEXP_SUBSTR(X_LINE, '[^,]+', 1, 2);
       
     
      folderUID := sys_guid();
       
			INSERT INTO zob VALUES(folderUID, V_Name, V_ParentUID, V_Path, V_PrimaryType, V_SubType, V_GeneralType, V_Undeletable, V_ErrorWarningStatus, V_ComplianceStatus, V_Description)
			returning folderUID into o_zuid;
		
			INSERT INTO zqg VALUES(o_zuid, G_LogHistoryCount, G_FilterString);
			INSERT INTO zctx VALUES(o_zuid, X_contextid, X_position);
      COMMIT;
        EXCEPTION
        WHEN NO_DATA_FOUND THEN
          EXIT;
        END;
      END LOOP;
    END IF;
    UTL_FILE.FCLOSE(F);
  	UTL_FILE.FCLOSE(Q);
  	UTL_FILE.FCLOSE(T);
	
END;

Re: sys_guid() help with bulk insert [message #587152 is a reply to message #587151] Wed, 12 June 2013 14:12 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
      
			INSERT INTO zob VALUES(folderUID, V_Name, V_ParentUID, V_Path, V_PrimaryType, V_SubType, V_GeneralType, V_Undeletable, V_ErrorWarningStatus, V_ComplianceStatus, V_Description)
			returning folderUID into o_zuid;
		
			INSERT INTO zqg VALUES(o_zuid, G_LogHistoryCount, G_FilterString);
			INSERT INTO zctx VALUES(o_zuid, X_contextid, X_position);

If you require a different value, then don't use the same variable "o_zuid" in all 3 INSERT statements
Re: sys_guid() help with bulk insert [message #587157 is a reply to message #587152] Wed, 12 June 2013 14:46 Go to previous messageGo to next message
rexi
Messages: 7
Registered: June 2013
Junior Member
the id in the zqg and zctx is a foreign key on zob, so I need to return folderuid after the insert in zob to use for zqg and zctx to maintain the relationship. Regardless I get the same id for all entries in zob as well.
Re: sys_guid() help with bulk insert [message #587161 is a reply to message #587157] Wed, 12 June 2013 15:57 Go to previous messageGo to next message
Bill B
Messages: 1971
Registered: December 2004
Senior Member
Why not use a sequence. That is what they are for.
Re: sys_guid() help with bulk insert [message #587162 is a reply to message #587161] Wed, 12 June 2013 15:59 Go to previous messageGo to next message
rexi
Messages: 7
Registered: June 2013
Junior Member
Our database is designed to use sys_guid() (raw(16)) for primary key.
Re: sys_guid() help with bulk insert [message #587163 is a reply to message #587162] Wed, 12 June 2013 16:13 Go to previous message
rexi
Messages: 7
Registered: June 2013
Junior Member
false alarm, the value does change, it was just a single digit change and hard to detect
Previous Topic: Need help to read CLOB and use in SQL query
Next Topic: Like operation for multiple values
Goto Forum:
  


Current Time: Thu Jul 31 19:45:05 CDT 2025