Avatar of Palmer_Admin
Palmer_Admin
Flag for United States of America asked on

SQL code to remove content from a field in DB needed

Hi,
Can someone provide me with a SQL statement to remove content from 1 field in my DB.
I have a table called SHOP and withing that table I have Project field.
So this "Project" field should have no data at all, but some of our emp. but the letter "H" in it and how I cannot delete it.
So I want field "Project" to be " " instead of having "H" in it.

Thanks
MySQL Server

Avatar of undefined
Last Comment
arnold

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Muhammad Khan

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
arnold

update SHOP set project="" where length(project)>0 ;

The above checks if project has anything it will be changed.
You can run the update query without a where clause and it will update every project column in every row.
Note " " is not nothing it is a space.  Nothing is "" i.e. empty set.

Palmer_Admin

ASKER
hi,
can I write something like this:
update shop
set project = '  ' ,
/
commit
/
Muhammad Khan

yah you can... but then project field wont be called empty.. coz it has a value ' ' (space even)...
Your help has saved me hundreds of hours of internet surfing.
fblack61
Palmer_Admin

ASKER
how about "insert" command do I need to you it?
Muhammad Khan

no... you do not want to insert any new row....just update the existing ones
Palmer_Admin

ASKER
here is the whole script:

insert into shop
select * from shop
where line2 = '31944'
/
commit
/
update shop
set project = ' ',
where line2 = '31944'
/
commit
/


is this the correct format?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Palmer_Admin

ASKER
ok,
So I typed
update shop
set project = ' ',
where line2 = '31944'
/

and I got error on line 3 "Invalid user.table.column"
Muhammad Khan

remove the comma at the end of 3rd line i.e. Set project=''

Palmer_Admin

ASKER
i got the error saying

virtual column not allowed here

update shop
set project = ' '
where line2 = '31944'
/
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Muhammad Khan

is SHOP a view?
Palmer_Admin

ASKER
I don't quiet understand you on this.
SHOP is a table name.
Muhammad Khan

which database are you working with? MYSQL? MS SQL Server or oracle?

>>virtual column not allowed here
this error i saw in oracle.. .when we try to update a computed column of a view.. which is offcourse not updateable...
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Palmer_Admin

ASKER
it is oracle db,
you you think the parent table is on SHOP ?
Muhammad Khan

that means SHOP is not a table... it is a view.. can you do desc SHOP in sql plus to see ... it should give you the query behind this table... from there you can see the actual table which contains project column.. .and then use the above statement on that table.
arnold

Do you have another table that has a project field?  IS there a row that has an H in it?  Update that table and see whether the changes are now reflected in the SHOP view.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Palmer_Admin

ASKER
OK,
so I did DESC SHOP and it gave me bunch of fields. One of them is Project and the other one is LINE2

Project NULL ? (is blank) and Type (VARCHAR2(10))
LINE2  NULL ? (NOT NULL) and Type (VARCHAR2(12))

So looks like SHOP is a table
Palmer_Admin

ASKER
Arnold, I cannot change the value "H" from front-end. Trying to do it through sql statement......
I have a lot of tables, so I don't know if I have Project in differernt table.
I am pretty sure that it should be replaced in SHOP table......

thanks
Muhammad Khan

select text from all_views where view_name='SHOP';

write this.. i forgot that desc command will only show the column even for views... i dont work with sqlplus...sorry for that.. above query should return you the sql which is behind SHOP view....

i am positive that SHOP is a view
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Palmer_Admin

ASKER
here is the answer, but I don't know what that means:

TEXT
--------------------------------------------------------------------
select LINE2                                        LINE2,
           RELEASE_NO

it gave my my LINE2 field.....
Muhammad Khan

so its a view...
okay now... we are close... but sqlplus is not showing u all the data... run following to get the output in a file and attach the file here

spool c:\view_details.txt
select text from all_views where view_name='SHOP';
spool off;
Palmer_Admin

ASKER
here it is....
VIEW-DETAILS.TXT
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Palmer_Admin

ASKER
my line2 is order_no

sorry for confusion
Muhammad Khan

now we are having trouble with sqlplus display settings... i thought it would give full output in the file.. but it didn't.... try this

set wrap on
spool c:\view_details.txt
select text from all_views where view_name='SHOP';
spool off;


try again now...i am at home and do not have access of sqlplus... let see if this works..
Palmer_Admin

ASKER
same result
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
arnold

IMHO, it is better to have an empty field: "" rather than null.