Shades
Shades

Reputation: 295

need to insert string of data into a table column with a NUMBER datatype

In Oracle, I have a table with a column of data type NUMBER. I need to insert a string into a new row I'm about to create. The other rows can certainly remain NUMBERs because usually that's what I need to insert in them. So is there a way to insert a new row with a string sort of like this(this wouldn't work for me)?

INSERT INTO keyboard_learning (emplid,wpm,date_completed,exercise,attempt)
VALUES (seq_keyboard_learning.nextval,to_char('LEVEL 3'),'14-JUN-2012','Meteor typing blast',1)

I want to create a new row where usually I would put a number like for example ' 23 ' in a new row of the WPM column. This time I want to put 'LEVEL 3'instead just the number 23

Upvotes: 0

Views: 2930

Answers (1)

Justin Cave
Justin Cave

Reputation: 231671

Assuming that WPM is the NUMBER column that we're talking about, no, there is no way to insert a string like "LEVEL 3" into that column without changing the definition of the column. You could convert the column to a VARCHAR2 but that would cause numerous headaches down the line when you want to treat WPM like a number (i.e. have them sort numerically rather than alphabetically, compute percentage improvements, etc.).

Why do you want to store a string in a WPM column in the first place? It seems likely that the problem is that you need a new column or, perhaps, a new entity in your data model.

Upvotes: 3

Related Questions