BookmarkSubscribeRSS Feed
marzieh
Calcite | Level 5

Hi all

I want to insert a record to a table in oracle and read its ID just after inserting it.

I don't want to lose my record while so many records might be inserted at the time.

How can I do that?

Thanks a lot

6 REPLIES 6
Ksharp
Super User

Make a counterpart of original dataset, then using EXCEPT operation to see what record you have inserted.

data one;set sashelp.class;run;
data two;set sashelp.class;run; 
proc sql;
insert into one values('Patrick','M',30,52.2,89.4);


 select * from one 
  except
 select * from two;
quit;

Ksharp

marzieh
Calcite | Level 5

Dear Ksharp

I read the values from table 'three' and insert it to 'one', how can I keep the  rsult of (select *... ) in a table? It seems that it doesn't understand the code.

my code is:

data three;

input name $ sex$ age@@ height@@ weight@@;

cards;

Patrick M 30 52.2 89.4

;

run;

proc sql;

  insert into one (name, sex, age, height, weight)

  select name, sex, age, height, weight

  from three;

select * from one

  except

select * from two;

quit;

run;

Ksharp
Super User

OK. Easy.

data one; set sashelp.class; run;
data two; set sashelp.class;run;
data three;
input name $ sex$ age height weight;
cards;
Patrick M 30 52.2 89.4
Peter M 40 54.3 100.2
;
run;

proc sql;
insert into one select * from three;

create table want as
 select * from one 
  except
 select * from two;
quit;



Ksharp

marzieh
Calcite | Level 5

another question:

Does this code guarantee that we read the inserted record?

I mean if another data inserted from another procedure while our proc sql is running, does it guarantee that the result is our record?

this procedure lock the table while runing or not?

Ksharp
Super User

Just as Tom said, I think you need some help from Oracle Administrator .

If you are familiar with Oracle ,why not do it in Oracle?

Ksharp

Tom
Super User Tom
Super User

Why do you need to know the ID number generated by the Oracle database?

If you are not competing against other proceses then just query the database to find the record you just inserted.  Otherwise if you really need to get the number that Oracle generated you might need to trigger a stored procedure in Oracle that would insert the record and return the new ID as the result.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1288 views
  • 3 likes
  • 3 in conversation