Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to generate synthetic rows (raw(16) guid cols) in one SQL statement?

ddevienneJun 5 2008 — edited Jun 5 2008
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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 3 2008
Added on Jun 5 2008
2 comments
1,106 views