![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
All my database accesses are done through Pro*C/C++. Sometimes my code needs to verify whether a table exists. Years ago, I was about to post that particular questions here. I then realized that the following statements achieve the desired results: EXEC SQL SELECT COUNT(1) INTO :howMany FROM user_tables WHERE table_name = :table_name; if (howMany == 1) doThis(); else doThat(); Is that "the" proper way? -Ramon |
#3
| |||
| |||
|
|
All my database accesses are done through Pro*C/C++. Sometimes my code needs to verify whether a table exists. Years ago, I was about to post that particular *questions here. I then realized that the following statements achieve the desired results: EXEC SQL SELECT COUNT(1) INTO :howMany FROM user_tables WHERE table_name = :table_name; if (howMany == 1) * * doThis(); else * *doThat(); Is that "the" proper way? -Ramon |
#4
| |||
| |||
|
|
Ramon F Herrera schreef: All my database accesses are done through Pro*C/C++. Sometimes my code needs to verify whether a table exists. Years ago, I was about to post that particular *questions here. I then realized that the following statements achieve the desired results: EXEC SQL SELECT COUNT(1) INTO :howMany FROM user_tables WHERE table_name = :table_name; if (howMany == 1) * * doThis(); else * *doThat(); Is that "the" proper way? -Ramon I always get a bit worried if an application has to check whether a table exists.... should they not be there just by design? Shakespeare |
#5
| |||
| |||
|
|
Since the following question is conceptually similar to the previous, I will tag it along this thread. I need to write code which creates a new record if it doesn't exist and modifies it otherwise. It seems that Oracle (actually, the SQL language) has two different statements for doing this, one being INSERT and the other UPDATE, right? (IOW, there is no single command like "create or replace" - I have to roll my own "create or replace"). Therefore, my code should probably look like this: SELECT COUNT(1) INTO howMany FROM mytable WHERE <some constraint if (howMany == 1) UPDATE mytable (); else INSERT INTO mytable(); Right? I just want to make sure that that is the correct way. |
#6
| |||
| |||
|
|
I need to write code which creates a new record if it doesn't exist and modifies it otherwise. It seems that Oracle (actually, the SQL language) has two different statements for doing this, one being INSERT and the other UPDATE, right? (IOW, there is no single command like "create or replace" - I have to roll my own "create or replace"). Therefore, my code should probably look like this: SELECT COUNT(1) INTO howMany FROM mytable WHERE <some constraint if (howMany == 1) *UPDATE mytable (); else *INSERT INTO mytable(); Right? I just want to make sure that that is the correct way. |
#7
| |||
| |||
|
|
Ramon F Herrera schreef: All my database accesses are done through Pro*C/C++. Sometimes my code needs to verify whether a table exists. Years ago, I was about to post that particular *questions here. I then realized that the following statements achieve the desired results: EXEC SQL SELECT COUNT(1) INTO :howMany FROM user_tables WHERE table_name = :table_name; if (howMany == 1) * * doThis(); else * *doThat(); Is that "the" proper way? -Ramon I always get a bit worried if an application has to check whether a table exists.... should they not be there just by design? Shakespeare |
#8
| |||
| |||
|
|
On Oct 16, 4:48*pm, Shakespeare <what... (AT) xs4all (DOT) nl> wrote: Ramon F Herrera schreef: All my database accesses are done through Pro*C/C++. Sometimes my code needs to verify whether a table exists. Years ago, I was about to post that particular *questions here. I then realized that the following statements achieve the desired results: EXEC SQL SELECT COUNT(1) INTO :howMany FROM user_tables WHERE table_name = :table_name; if (howMany == 1) * * doThis(); else * *doThat(); Is that "the" proper way? -Ramon I always get a bit worried if an application has to check whether a table exists.... should they not be there just by design? Shakespeare I think it is reasonable for many applications, they can ascertain where in a process things are or whether they are being run for the first time. *Now, I'm a great believer in the DBA being in control of DDL, and I think you are right to worry, I'm just saying it isn't necessarily in the nightmare realm. As far as the proper way, TIMTOWTDI. jg -- @home.com is bogus. yay, boss is going fishing! *That means I can... have more work to do... boo. |
#9
| |||
| |||
|
|
On Oct 16, 7:48 pm, Shakespeare <what... (AT) xs4all (DOT) nl> wrote: Ramon F Herrera schreef: All my database accesses are done through Pro*C/C++. Sometimes my code needs to verify whether a table exists. Years ago, I was about to post that particular questions here. I then realized that the following statements achieve the desired results: EXEC SQL SELECT COUNT(1) INTO :howMany FROM user_tables WHERE table_name = :table_name; if (howMany == 1) doThis(); else doThat(); Is that "the" proper way? -Ramon I always get a bit worried if an application has to check whether a table exists.... should they not be there just by design? Shakespeare Good point. The thing about my design is that I have "a table of tables". The code in question is for my internal use, and I type it from the Unix prompt. Let's say I have a bunch of company clients and the command in question tells me when was the last time such company made a payment or something. For policy and other reasons I treat every company as a separate entity with their own tables. Some companies demand not to share table space with other companies. Therefore the interaction would look like this: % last_payment google The program -after checking that a table named "google" does not exist- will retort: "Are you kidding me, Ramon? `google' is not your client" -RFH |
#10
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |