![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hello. I'm looking at Oracle after having used Sybase for a few years. I'm trying to put a script together that deletes from a table where a particular field is today's date in YYYYMMDD format. The SQL I'm using is: declare v_today varchar(8); begin v_today := to_char(sysdate, 'YYYYMMDD'); delete from target_table where archive_date = v_today; end; I always get the following error: PLS-00201: identifier 'target_table' must be declared Obviously, target_table is a table and isn't meant to be a declared variable. Could someone please point out what I'm doing wrong and how to fix the syntax of this? Thanks in advance for any information, Ian |
#3
| |||
| |||
|
|
"Ian McCall" <ian (AT) eruvia (DOT) org> wrote in message news:IvfRa.12685$nP.10671 (AT) newsfep4-winn (DOT) server.ntli.net... Hello. I'm looking at Oracle after having used Sybase for a few years. I'm trying to put a script together that deletes from a table where a particular field is today's date in YYYYMMDD format. Apologies - should have added the version. It's 8i v8.1.6.0.0. Cheers, Ian |
#4
| |||
| |||
|
|
Ian McCall wrote: "Ian McCall" <ian (AT) eruvia (DOT) org> wrote in message news:IvfRa.12685$nP.10671 (AT) newsfep4-winn (DOT) server.ntli.net... Hello. I'm looking at Oracle after having used Sybase for a few years. I'm trying to put a script together that deletes from a table where a particular field is today's date in YYYYMMDD format. Apologies - should have added the version. It's 8i v8.1.6.0.0. Cheers, Ian It appears that you don't own the table. You must, in this case, use the fully qualified object name which is: schema_name dot table_name. -- Daniel Morgan http://www.outreach.washington.edu/e...ad/oad_crs.asp damorgan@x.washington.edu (replace 'x' with a 'u' to reply) Additionally,Why are you converting a date to a string and then comparing it |
#5
| |||
| |||
|
|
"Daniel Morgan" <damorgan (AT) exxesolutions (DOT) com> wrote in message news:3F15AA3F.AAB4DA9E (AT) exxesolutions (DOT) com... Ian McCall wrote: "Ian McCall" <ian (AT) eruvia (DOT) org> wrote in message news:IvfRa.12685$nP.10671 (AT) newsfep4-winn (DOT) server.ntli.net... Hello. I'm looking at Oracle after having used Sybase for a few years. I'm trying to put a script together that deletes from a table where a particular field is today's date in YYYYMMDD format. Apologies - should have added the version. It's 8i v8.1.6.0.0. Cheers, Ian It appears that you don't own the table. You must, in this case, use the fully qualified object name which is: schema_name dot table_name. -- Daniel Morgan http://www.outreach.washington.edu/e...ad/oad_crs.asp damorgan@x.washington.edu (replace 'x' with a 'u' to reply) Additionally,Why are you converting a date to a string and then comparing it to a field that in all likelyhood is a date? begin delete from target_table where archive_date> trunc(sysdate) and archive_date<trunc(sysdate+1) ; end; |
#6
| |||
| |||
|
|
Additionally,Why are you converting a date to a string and then comparing it to a field that in all likelyhood is a date? |
#7
| |||
| |||
|
|
"Jim Kennedy" <kennedy-down_with_spammers (AT) no_spam (DOT) comcast.net> wrote in message news:rpoRa.79756$ye4.58653 (AT) sccrnsc01 (DOT) .. Additionally,Why are you converting a date to a string and then comparing it to a field that in all likelyhood is a date? The field is an existing table, and is a varchar(8). It forms part of a primary key, which is why dates were avoided (don't want to accidently add timing resolution beyond that of one day). Cheers, Ian |
#8
| |||
| |||
|
|
Should be a date. Leaving it at midnight is perfectly acceptable. Dates only take 7 bytes and give you flexibility to treat them as dates. |
#9
| |||
| |||
|
|
"Jim Kennedy" <kennedy-down_with_spammers (AT) no_spam (DOT) comcast.net> wrote in message news:LetRa.81709$H17.25850 (AT) sccrnsc02 (DOT) .. Should be a date. Leaving it at midnight is perfectly acceptable. Dates only take 7 bytes and give you flexibility to treat them as dates. Understand your point, and I'd normally agree. The problem I'm trying to avoid is catching bad coding that could mess up the primary key however. With archive_date as a date a user could run insert into target_table values(someValue, sysdate) and it would work. sysdate now has a resolution including a time component, which means they could run that statement again and it would work, rather than faily with a duplicate key error (the desired behaviour). Enforcing varchar(8) does mean I could potentially get problems like (someValue, 'herring') working instead of the YYYYMMDD I expected, but at least it won't allow two values for the same day. |
#10
| |||
| |||
|
|
"Jim Kennedy" <kennedy-down_with_spammers (AT) no_spam (DOT) comcast.net> wrote in message news:LetRa.81709$H17.25850 (AT) sccrnsc02 (DOT) .. Should be a date. Leaving it at midnight is perfectly acceptable. Dates only take 7 bytes and give you flexibility to treat them as dates. Understand your point, and I'd normally agree. The problem I'm trying to avoid is catching bad coding that could mess up the primary key however. With archive_date as a date a user could run insert into target_table values(someValue, sysdate) and it would work. sysdate now has a resolution including a time component, which means they could run that statement again and it would work, rather than faily with a duplicate key error (the desired behaviour). Enforcing varchar(8) does mean I could potentially get problems like (someValue, 'herring') working instead of the YYYYMMDD I expected, but at least it won't allow two values for the same day. Cheers, Ian |
![]() |
| Thread Tools | |
| Display Modes | |
| |