Home » SQL & PL/SQL » SQL & PL/SQL » create new row and inserting variables as values
create new row and inserting variables as values [message #312431] Tue, 08 April 2008 19:52 Go to next message
horax
Messages: 34
Registered: March 2008
Member
Ok,
Here's the situation: Trying to create a new row in a table so I can insert some values using a Procedure. However, I don't know how to create the row and update without a WHERE statement and NOT have it change every field referenced.

Questions: Can you INSERT a variable into a table field instead of a value? What method would be best for achieving the above scenario?

I've thought about declaring a cursor and record, but it would be moot if I cannot update the certain fields without using the PK.
Re: create new row and inserting variables as values [message #312433 is a reply to message #312431] Tue, 08 April 2008 20:02 Go to previous messageGo to next message
BlackSwan
Messages: 25040
Registered: January 2009
Location: SoCal
Senior Member
http://www.orafaq.com/forum/t/88153/0/
Please & FOLLOW the posting guidelines as stated in URL above.

>Trying to create a new row in a table so I can insert some values using a Procedure.
What exactly does this mean in English?

> I don't know how to create the row and update without a WHERE statement and NOT have it change every field referenced.
Why NOT?

Have you looked in the SQL Reference Manual as found at http://tahiti.oracle.com or http://asktom.oracle.com

>Can you INSERT a variable into a table field instead of a value?
Yes; of course.

>I've thought about declaring a cursor and record, but it would be moot if I cannot update the certain fields without using the PK.
It appears you have not had sufficient training in SQL and/or PL/SQL but likely refuse to RTFM to gain the requisite knowledge.
Re: create new row and inserting variables as values [message #312435 is a reply to message #312433] Tue, 08 April 2008 20:07 Go to previous messageGo to next message
horax
Messages: 34
Registered: March 2008
Member
First of all, why are you so rude?

Secondly, I'm in school learning this stuff, and this is my first semester with PL/SQL.

Thirdly, my problem is that I dont' know how to insert values AND NOT HAVE THEM AFFECT ALL THE ROWS WITHOUT THE PK.

I KNOW you can do it, but I can't seem to find out how. I've googled for 3 hours now, so I thought I'd come here to ask you guys.

If this is the type of respone I get here, then it's probably not worth my time.
Re: create new row and inserting variables as values [message #312439 is a reply to message #312431] Tue, 08 April 2008 20:17 Go to previous messageGo to next message
BlackSwan
Messages: 25040
Registered: January 2009
Location: SoCal
Senior Member
INSERT statement NEVER, EVER impact other rows in the table!

For what it is worth, from a quick review of the SQL Reference manual, the INSERT statement does not allow the use of WHERE clause &
I don't understand how "update without a WHERE statement" is involved with the problem of adding new rows to a table.

[Updated on: Tue, 08 April 2008 20:27] by Moderator

Report message to a moderator

Re: create new row and inserting variables as values [message #312440 is a reply to message #312439] Tue, 08 April 2008 20:28 Go to previous messageGo to next message
horax
Messages: 34
Registered: March 2008
Member
Ok, maybe I'm not making my problem clear.

I have a table of 'x' amount of rows.
If I UPDATE without a WHERE statement, all the rows with teh same column name that I reference in my UPDATE statement will be replaced. If I UPDATE with a WHERE statement, only the row that correlates with the WHERE statement gets updated.

My issue is how do I UPDATE only one row WITHOUT a WHERE statement?
Re: create new row and inserting variables as values [message #312442 is a reply to message #312439] Tue, 08 April 2008 20:32 Go to previous messageGo to next message
horax
Messages: 34
Registered: March 2008
Member
anacedent wrote on Tue, 08 April 2008 19:17
INSERT statement NEVER, EVER impact other rows in the table!

For what it is worth, from a quick review of the SQL Reference manual, the INSERT statement does not allow the use of WHERE clause &
I don't understand how "update without a WHERE statement" is involved with the problem of adding new rows to a table.


Ok, I see what you're saying.

The procedure I need to write needs to add a row to a table and insert certain values in that row. However, none of the rows being inserted are associated with teh PK. You can't have NULL in the PK column. Am I approaching the additoin incorrectly?

Sorry for the confusion, after re-reading my posts, I was confused, too.
Re: create new row and inserting variables as values [message #312443 is a reply to message #312431] Tue, 08 April 2008 20:36 Go to previous messageGo to next message
BlackSwan
Messages: 25040
Registered: January 2009
Location: SoCal
Senior Member
>none of the rows being inserted are associated with teh PK.
What does this mean?

>You can't have NULL in the PK
Reasonable.

Since we don't know ANYTHING about the table or the data you desire to INSERT, how much help do you expect?

Still you refuse to read & FOLLOW posting guideline.
Re: create new row and inserting variables as values [message #312449 is a reply to message #312442] Tue, 08 April 2008 21:37 Go to previous messageGo to next message
flyboy
Messages: 1832
Registered: November 2006
Senior Member
> The procedure I need to write needs to add a row to a table and insert certain values in that row.

I do not see any reason, why it should not simply INSERT row to a table with certain values in that row. But apparently I am missing something which is not in your post.

Rather post a testcase: CREATE TABLE script (three columns should be enough), some sample data and test scenario you want to follow. Mentioning the reason would be good too.

After reading http://forums.oracle.com/forums/thread.jspa?threadID=640132&tstart=0 thread on Oracle Forums I finally understand what you want (if it is the same question). Follow the first advice in that thread then.
Read this thread again. Do you post anywhere that the table contains PK? I understand it reversely - that you want to update row in a table without PK. But maybe this is not the same question...

[edit: added last paragraph]

[Updated on: Tue, 08 April 2008 21:48]

Report message to a moderator

Re: create new row and inserting variables as values [message #312792 is a reply to message #312431] Wed, 09 April 2008 14:42 Go to previous message
flyboy
Messages: 1832
Registered: November 2006
Senior Member
@horax: as you did not reply, I suppose that my last assumption was correct and you asked the same question.

have a good luck then.
Previous Topic: Need part of a column (merged)
Next Topic: Purge Script
Goto Forum:
  


Current Time: Tue Dec 06 00:05:29 CST 2016

Total time taken to generate the page: 0.04999 seconds