We're populating a table containing two GUID columns:
create table object
( object_guid raw(16) primary key
, project_guid raw(16)
)
All object GUIDs are unique (thus the PK), and each object belongs to a given project (should be a FK to some project table). We want N objects / rows, belonging to only 100 projects, i.e. 1% of the rows of the object table belong to the project #1, 1% to #2, etc...
Right now we're using about 25 lines of C++/OCI code to do that (one query doing a "select sys_guid() from dual", and using the generated GUIDs to do inserts into object), but I suspect it's possible to do this using a single SQL statement using mysterious
connect by or some other Oracle SQL magic. (our OCI code does quite a few round-trips to do the equivalent).
Would anyone please demonstrate how to generate the rows as explained above, and possibly describe how it works for the non-initiated?
Thanks, --DD
PS: I'm sure it can be done in PL/SQL as well, but I'm interested in a SQL version if one's possible.