• (cs) in reply to JR
    Anonymous:

    Volmarias:
    I have NO idea what's going on in this code. Can someone please step us through it? Otto's summary was nice, but I want to know just why this is a wtf.

    It is using a function to call a cursor to return a table with 5 rows.  And being called many times.

    There are many other ways of doing this.  All are faster.  I can't think of a slower way.  Anyone?

    It could print out the table, put it on a wooden table, take a picture, scan it, and use OCR to extract the data.

    Repeat 5 times

  • John (unregistered) in reply to qqqqqq
    qqqqqq:
    Anonymous:
    Anonymous:

    Oh, come on now.... those function calls are somewhat analogous to the lazy-coding style:

    if (func(x) > func(y))
       then return func(x);
       else return func(y);
    

    ...as opposed to using temp variables,

    Hey, if you're using a proper functional language, it'll cache the return values of func(x) and func(y) for later use, and you don't need to use such counterintuitive things as temporary variables.

     
    Not all language compilers can trace through function calls to all depths - think about side affects (agreed: they shouldn't be coded like that, but alas, frequently are)
     

    Are there any languages that have a way to declare/define a function that given constant inputs, the return value is constant?

    So that something like:

    <FONT color=#000080>if(myfunction(1,2) > 7) {myvariable=(myfunction(1,2)); }</FONT>

    <FONT color=#000080>const int myfuction(x,y) { return(x+y); }</FONT>

    would be optimized to zero instructions, and:

    <FONT color=#000080>if(myfunction(1,2) < 7) {myvariable=(myfunction(1,2)); }</FONT>

    <FONT color=#000080>const int myfuction(x,y) { return(x+y); }</FONT>

    would be optimized to:

    <FONT color=#000080>myvariable = 3;</FONT>

    <FONT color=#000000>aside from using pre-compiler macros/directives that inline the functions code?</FONT>

  • Anon (unregistered) in reply to qqqqqq

    That's version 2.  They're still ironing out the bugs in v1.  I'm not sure, but I wouldn't be surprised if EDS were involved somehow.

  • Anton (unregistered) in reply to JR

    I cannot be so sure about the quantity, but I'm pretty sure that Steve was next on the row

  • (cs) in reply to anonymous
    Anonymous:
    qqqqqq:

    Just curious, do rdbms' have the query-equivalent of file-not-found?

     

     

    There are no stupid questions, only stupid people who ask questions...

    DECLARE @usr

    SET @usr = USER

    SELECT 'file-not-found'

    WHERE @usr = 'Stupid'

    GO

  • (cs)

    This sort of WTF is common when programmers with a procedural language bias write SQL. The instinct for modularity doesn't serve them well here - SQL engines are built for speed, not modularity.

    The nice thing about the fix is that you don't need to know much about what the query is trying to do; you just do multiple passes eliminating redundancy and silliness, and eventually you boil it down to its essence. This was a tough one - Steven must have done a great job.

  • agent_amanuen (unregistered) in reply to mrprogguy

    This is done for clarity and symmetry, as well as future-proofing; if in the future the "then" clause is rewritten to not immediately return, you don't want it unconditionally returning func(y).  The K&R guys knew what they were doing, even in 197x.

    Also, whether or not blocking is done by indention or not has no effect on having to write if/then/else clauses in this way.  You should think more carefully before criticizing things you don't fully understand.

  • agent_amanuen (unregistered) in reply to mrprogguy
    mrprogguy:

    Maybe it will.  But the idiom

    <font face="Courier New" size="2">if(func(x) > func(y))
        then return func(x);
        else return func(y);</font>

    is kind of dorky because if return func(x) ever executes, then there's never a chance to return func(y), rendering the else redundant.

    What's truly scary is that this particular construct shows up in the original K&R, and you'd think those guys would know better, even in 197x.

    Of course, if you're using one of those massively silly languages that does logical blocking by indentation instead of bracing symbols or commands (as God intended), then you have to write something like this, and you have my condolences.



    (Ugh, forgot to quote)

    This is done for clarity and symmetry, as well as future-proofing; if in the future the "then" clause is rewritten to not immediately return, you don't want it unconditionally returning func(y).  The K&R guys knew what they were doing, even in 197x.

    Also, whether or not blocking is done by indention or not has no effect on having to write if/then/else clauses in this way.  You should think more carefully before criticizing things you don't fully understand.
  • (cs) in reply to John

    I don't know if you count optimalization as directive, but GCC does this:

    int func(int x, int y) { return (x+y); }
    int main() { return <font color="#ff0000">func(1,2);</font> }
    With -O3 optimalization this code becomes:
    main:
            pushl   %ebp
            movl    %esp, %ebp
            subl    $8, %esp
            andl    $-16, %esp
            subl    $16, %esp
            <font color="#ff0000">movl    $3, %eax</font>
            leave
            ret
    Welcome to year 2000.

    The second example - C:
    int main() { if(func(1,2)>0) <font color="#ff0000">return 1;</font> else return 0; }
    asm:
    main:
            pushl   %ebp
            movl    %esp, %ebp
            subl    $8, %esp
            andl    $-16, %esp
            subl    $16, %esp
            <font color="#ff0000">movl    $1, %eax</font>
            leave
            ret

  • Anon (unregistered) in reply to John
    Anonymous:

    Are there any languages that have a way to declare/define a function that given constant inputs, the return value is constant?

    <font color="#000000">aside from using pre-compiler macros/directives that inline the functions code?</font>


    This is called Common Subexpression Elimination (CSE) and is done as a compiler optimization. I think many optimizing compilers would have a reasonable chance at doing the optimization you listed (by detecting a bunch of constants), but they'd have to detect side effects, which is generally more easily done in functional languages. I know Haskell's GHC does not perform CSE but I'm not sure about other Haskell compilers. Clean might do full CSE, haven't looked into it.

    (I just so happen to be learning Haskell, so I had these open earlier today)
  • JoeBloggs (unregistered) in reply to TRauMa
    Anonymous:
    (display "Yeah, sure, no side effects.")

    Until you are doing anything with your code, like, say, input/output...

    LISP is not a proper functional language.

  • Gnictigezoink (unregistered)

    With exactly two exceptions, cursor-based SQL queries are a proper subset of all WTFs.

    http://en.wikipedia.org/wiki/Subset

    Select count(*)
    from allWTFs as crap
    where crap.samplecode like '% declare cursor %' ...



  • Frandsen (unregistered)

    I can quite understand The Policy. I've seen policies like that being made because it was obvious to the managers that every time the thing was being maintained, it would be broken for a week or two, only to come back slower than ever before. C'mon, what's a non-programmer to think?

    And speaking of cursors: A while ago, I was writing a stored proc that would update some of my tables and then triggers on those tables would handle the rest. Now, one of my coworkers had some tables that also needed updating. I told him I'd just update his main table when the proc fired, and he could use triggers like I did. No way, that couldn't be done because there were several rows and several related tables involved. All my sweet talking did no good, so he wrote another stored proc to do his cursor thing, which in turn meant that I was left with no option but to open a cursor myself and call his proc once for every row. So now there's a stored proc out there with my name on it that will just grow slower and slower :(

    Why are they called cursors anyway? I'm the cursor, they are the cursees.

  • Jon (unregistered) in reply to Randyd
    Anonymous:

    I wonder - what all thos inserts were doing.. and if they'll be missed..

    They're inserting into a table variable (similar to a temporary table).
  • (cs) in reply to John

    Actually, many flavors of SQL support this.  For example, in SQL Server, the SIN function is considered "deterministic," and it will not be called for every row in a query if the arguments are the same.  I believe that the values can even be stored and indexed in the case of a view.  However, GETDATE is not deterministic, and needs to be called every time it is referenced.

    If you are writing a function in another language (like C#), you have to state if the function is deterministic with the SqlFunction attribute.  Weird and unpredictable things can happen if you lie about being deterministic, although it can be interesting to make your function log a message just to see how well SQL Server is able to optimize calls to a function.

    It certainly would be cool if general-purpose languages supported marking a function as deterministic in order to avoid redundant execution.  I mean, pretty much every Math function could be markes as such.  It'd be similar (but not exactly like) marking a function "const" in C++.

  • (cs) in reply to TheMuuj

    Why the heck show the quoted post in the preview if you're not going to post it?

    As much as I like .NET, people sure do use it to write horrible software.  Most php-based forums are much more intuitive.

    And WYSIWYG editors are worthless if they don't work.  Give me HTML or BBCode any day.

  • (cs) in reply to merreborn
    merreborn:
    qqqqqq:
    Anonymous:
    Anonymous:

    Oh, come on now.... those function calls are somewhat analogous to the lazy-coding style:

    if (func(x) > func(y))
       then return func(x);
       else return func(y);
    

    ...as opposed to using temp variables,

    Hey, if you're using a proper functional language, it'll cache the return values of func(x) and func(y) for later use, and you don't need to use such counterintuitive things as temporary variables.

     
    Not all language compilers can trace through function calls to all depths - think about side affects (agreed: they shouldn't be coded like that, but alas, frequently are)


    "think about side affects"

    In a functional language, there are no side effects. You're thinking of imperative languages.

     

    Your comment finally forced me to devote time to understand "monads" in Haskell, which I have postponed so many times...

    //of course it was clear to me that it is possible to carry the whole PC state with you through subsequent calls...but I didn't believe somebody was crazy enough to....

  • (cs)
    Alex Papadimoulis:

    Everyone knew about The Report. On a moderately sunny day, with just the right wind speed and the planets properly aligned, The Report would run in a reasonable amount of time: two, maybe three minutes. But on every other day, The Report would take an incredible amount of time (measured in hours) to run, if it decided to run at all that day.

    I'm not an SQL person, so I can't quite grasp the true sense of this WTF, although that code does look heinous.

     

    What I don't understand is, WHY would this report take longer on same does than on others? Should it just always take a long time? And as more data is added, shouldn't it take even longer? What am I missing? Or are the tables of data per day?

  • (cs) in reply to chrismcb

    By introducing such a large performance delta, our boy may have made people even more nervous about The Report.  Nobody else fixed it, so why should we trust this new code.  Surely there's a mistake somewhere...

    He should have only made it 20% faster.  That would've gotten him some kudos.  Then, a month or so later, he makes it 20% faster again.  More kudos.  After a few months, The Report is purring along, everyone knows who's making it work better, and our boy is an SQL genius with a fat raise.

    Damn, I'm going to write a book.

     

  • Anonymous (unregistered) in reply to TheMuuj
    TheMuuj:
    Actually, many flavors of SQL support this.  For example, in SQL Server, the SIN function is considered "deterministic," and it will not be called for every row in a query if the arguments are the same.  I believe that the values can even be stored and indexed in the case of a view.  However, GETDATE is not deterministic, and needs to be called every time it is referenced.

    If you are writing a function in another language (like C#), you have to state if the function is deterministic with the SqlFunction attribute.  Weird and unpredictable things can happen if you lie about being deterministic, although it can be interesting to make your function log a message just to see how well SQL Server is able to optimize calls to a function.

    It certainly would be cool if general-purpose languages supported marking a function as deterministic in order to avoid redundant execution.  I mean, pretty much every Math function could be markes as such.  It'd be similar (but not exactly like) marking a function "const" in C++.


    You mean like GCC's __attribute__((const))?
  • add (unregistered) in reply to qqqqqq

    Me too.. I learned that anonymous should've said "pure functional language", since (in the article he referenced) "Not all functional programs or functional programming languages are purely functional."

  • konrad (unregistered) in reply to mrprogguy
    mrprogguy:

    Of course, if you're using one of those massively silly languages that does logical blocking by indentation instead of bracing symbols or commands (as God intended), then you have to write something like this, and you have my condolences.



    Ok let us have a show of hands
    howmany of you has forgoten a ; or } at the end of  a line of code.

    How many of you have accidently written an entire function on
    one line because you forgot to press the return key.

  • (cs) in reply to Anon
    Anonymous:
    That's version 2.  They're still ironing out the bugs in v1.  I'm not sure, but I wouldn't be surprised if EDS were involved somehow.


    I don't think so. You must have missed the part where they said it actually WORKED every other day!

    Thanks
  • TSQL Guy (unregistered) in reply to HopHead

    create table #JOBTEMP
    (
    ID smallint IDENTITY(1,1),
    JobCD int,
    JobID int
    )

    insert into #JOBTEMP
    (
    JobCD,
    JobID
    )
    select top 5 cojobs.job_cd, job_id
    from cojobs
    inner join jobs on cojobs.job_cd = jobs.job_cd
    where del_ind = 0

    select  JobCD, ID,JobID from #JOBTEMP

    ----
    What do I win?

    Note too that Alex does say this is a /small/ part of the function....I wonder what the parameter is for...

  • (cs) in reply to TSQL Guy

    Anonymous:
    create table #JOBTEMP
    (
    ID smallint IDENTITY(1,1),
    JobCD int,
    JobID int
    )

    insert into #JOBTEMP
    (
    JobCD,
    JobID
    )
    select top 5 cojobs.job_cd, job_id
    from cojobs
    inner join jobs on cojobs.job_cd = jobs.job_cd
    where del_ind = 0

    select  JobCD, ID,JobID from #JOBTEMP

    ----
    What do I win?

    Note too that Alex does say this is a /small/ part of the function....I wonder what the parameter is for...

     

    No no.. the select statement should be like this to complete the WTF:

     

    insert into #JOBTEMP
    (
    JobCD,
    JobID
    )
    select cojobs.job_cd, job_id
    from cojobs
    inner join jobs on cojobs.job_cd = jobs.job_cd
    where del_ind = 0

    select JobCD, ID,JobID from #JOBTEMP where ID <= 5 

    e.g. removed the select top 5, that is unknown to oracle users and since there isn't "where rownum < 5" the workaround is to copy the data to a temporary table adding an identity field and then select the range you need and voila - you got what you need - magic, eh? :-)

  • person guy (unregistered) in reply to qbolec
    qbolec:

    Your comment finally forced me to devote time to understand "monads" in Haskell, which I have postponed so many times...

    //of course it was clear to me that it is possible to carry the whole PC state with you through subsequent calls...but I didn't believe somebody was crazy enough to....

    Haskell's monads are easy to understand, just badly explained. They're parameterised data types that work with >>= and return, which are simple enough in themselves (have a play with >>= using Lists and Maybes). Monads can also contain the equivalent of private variables, and those private vars can be used to implement clever things.

    Haskell happens to use monads to represent input/output operations. This isn't the only possible way to represent I/O -- it's just the way that Haskell happens to use. The easiest way to think about I/O in Haskell is that a Haskell program takes no inputs and returns a special data structure that represents an imperative program, and that it's the imperative program that actually does the I/O. That data structure is of type IO (), where () is Haskell's equivalent of a void type. You can join IO objects together with the >>= operator, and the IO type will sort itself out for you.

    Just for fun, this means that putStrLn does not actually print a line of text (as you can verify with "putStrLn "foo" seq True"). It doesn't do anything until the return value of putStrLn gets returned from main (or to the interactive interpreter).

  • sadfsfdsdfasdfasfd (unregistered) in reply to mrprogguy

    Ah, I so wish this site existed when I worked at one of my previous jobs.  I'd fix shit like this all the time.  I'd take jobs that took hours to run and made them run in seconds.  The "lead" programmer didn't know what the hell an inner join was, so he'd use a plethora of temp tables to narrow down his result sets.

  • bah (unregistered) in reply to TheMuuj
    TheMuuj:

    It certainly would be cool if general-purpose languages supported marking a function as deterministic in order to avoid redundant execution.  I mean, pretty much every Math function could be markes as such.  It'd be similar (but not exactly like) marking a function "const" in C++.


    We have such a thing in Perl; it's called Memoize.pm.  It would be trivial to do in Haskell for sure.
  • anonymous (unregistered) in reply to person guy

    Re: Haskell, it also means getLine is not a function:

    getLine :: IO String    -- see? a simple constant.

  • Nate (unregistered) in reply to same old song
    Anonymous:
    if (func(x) > func(y))
       then return func(x);
       else return func(y);
    


    Couldn't you avoid both temp variables and re-evaluations with:

    <font face="Courier New">func2(x,y)
    {
        return x > y ? x : y;
    }

    func2(func(x),func(y);
    </font>
  • Nate (unregistered) in reply to Nate
    Nate:

    <font face="Courier New">func2(func(x),func(y);
    </font>


    Missed a close paren.

    <font face="Courier New">func2(func(x),func(y));
    </font>
    There.  Much better.
  • Mike (unregistered) in reply to John

    quiet a few, fortran springs to mind using the keyword pure, i think there are some C/C++ extensions and some scientific languages support this, too. (Notable maple, but they use the remember keyword, that is they just remeber the result, so it works even for non-pure functions.)

    HTH,
     mike

    captch=enterprisey - not very fitting captcha this time

  • Mike (unregistered) in reply to Nate

    You do not get rid of the temp variables, they just get hidden. Also you add a whole function call/return to your programm. Speak about simplicity.

    Then again, sometimes it makes sense, speak about for i.e. the java compare function.

    Captcha=craptastic - now thats fits^^

  • Gabe (unregistered) in reply to qqqqqq

    qqqqqq:
    Not all language compilers can trace through function calls to all depths - think about side affects (agreed: they shouldn't be coded like that, but alas, frequently are)

    As it turns out, SQL Server can analyze a function to figure out whether it is deterministic (i.e. given inputs always yield the same outputs). If it is deterministic, it will only have to be called once for each set of input states.

  • Nate (unregistered) in reply to Mike
    Mike:
    You do not get rid of the temp variables, they just get hidden. Also you add a whole function call/return to your programm. Speak about simplicity.

    Then again, sometimes it makes sense, speak about for i.e. the java compare function.


    If it's an imperative language like C++, you can inline the new function; if it's functional, then adding function calls/returns is business as usual.  There are indeed hidden temporary variables, but the whole point was not to have to declare/name them, I thought.

    *shrug*
  • piersy (unregistered) in reply to JR

    "There are many other ways of doing this.  All are faster.  I can't think of a slower way.  Anyone?"

    I guess we could have each join call a function that calls an extended procedure which calls a dll that calls a web service that gets hold of the first 5 rows from a photograph of an excel sheet (on a wooden table of course) as XML. Inserts the resultant parsed values (of course write own overelaborate funtion to parse XML and wood) into a temporary table....blah etc.
    Enterprisey right?

  • (cs) in reply to BiggBru
    BiggBru:
    Alex Papadimoulis:

    No one had a good explanation for why The Report acted this way, nor did they want to find out. It was The Policy: questioning The Report might upset it; if The Report got upset, it might not run; and if The Report didn't run, its users would be deprived its bountiful data. The Report was good to its users most of the time, and no one wanted to change that. That is, no one, except Steven Dargal.

    How many virgins had to be sacrificed daily to please The Report?

    One would assume most of their developers by the time Steven got to work. He probably did it out of fear for his life. :-)

  • (cs) in reply to bah
    Anonymous:
    TheMuuj:

    It certainly would be cool if general-purpose languages supported marking a function as deterministic in order to avoid redundant execution. I mean, pretty much every Math function could be markes as such. It'd be similar (but not exactly like) marking a function "const" in C++.

    We have such a thing in Perl; it's called Memoize.pm. It would be trivial to do in Haskell for sure.

    Yup, it's trivial in Haskell. Heck, you can even do it in JavaScript: http://talideon.com/weblog/2005/07/javascript-memoization.cfm

  • (cs) in reply to Keith Gaughan
    Keith Gaughan:
    Anonymous:
    TheMuuj:

    It certainly would be cool if general-purpose languages supported marking a function as deterministic in order to avoid redundant execution. I mean, pretty much every Math function could be markes as such. It'd be similar (but not exactly like) marking a function "const" in C++.

    We have such a thing in Perl; it's called Memoize.pm. It would be trivial to do in Haskell for sure.

    Yup, it's trivial in Haskell. Heck, you can even do it in JavaScript: http://talideon.com/weblog/2005/07/javascript-memoization.cfm



    Oracle's PL/SQL has even more detailed markers about a function, like
    "doesn't read the database", "doesn't write to the database", "doesn't read package status", "doesn't write package status"
  • (cs) in reply to mrprogguy
    mrprogguy:

    Maybe it will. But the idiom

    if(func(x) > func(y))
    then return func(x);
    else return func(y);

    is kind of dorky because if return func(x) ever executes, then there's never a chance to return func(y), rendering the else redundant.

    Yes, that's what branches do. What's retarded here is that the function will be ran an extra time when for one or other of the values <var>x</var> or <var>y</var>. But that's a completely different matter.

    mrprogguy:

    Of course, if you're using one of those massively silly languages that does logical blocking by indentation instead of bracing symbols or commands (as God intended), then you have to write something like this, and you have my condolences.

    Hmmm... smells like trolling... but I'll bite.

    Let's use some Python code as an example. I'll write all the different ways of expressing this code that I can think of below:

    # The retarded way
    if (func(x) > func(y)):
    return func(x)
    else:
    return func(y)

    # Better: use temporary variables
    x1 = func(x)
    y1 = func(y)
    if (x1 > y1):
    return x1
    else:
    return y1

    # But why do we need the "else"? Use a guard clause instead.
    x1 = func(x)
    y1 = func(y)
    if (x1 > y1):
    return x1
    return y1

    # Even better: use a function
    def max(x, y):
    if (x > y):
    return x
    return y

    return max(func(x), func(y)

    # Or there's always reduce()
    return reduce(max, [x, y])

    And your point again was..?

  • File Not Available (unregistered) in reply to qqqqqq
    qqqqqq:
    Just curious, do rdbms' have the query-equivalent of file-not-found?

    This looks like something that fits:

    ORA-00320 cannot read file header from log string of thread string

    Cause: The file is not available.

  • home homine lupus est (unregistered) in reply to mrprogguy
    mrprogguy:

    Maybe it will.  But the idiom

    <font face="Courier New" size="2">if(func(x) > func(y))
        then return func(x);
        else return func(y);</font>

    ...

    What's truly scary is that this particular construct shows up in the original K&R, and you'd think those guys would know better, even in 197x.



    The joy of PHP:

    <font face="Courier New">$customer = new Client();
    $john = $customer;</font>

    This PHP code create 3 objects.

    If you arent not scared enough. You sould read that about leaks on Mozilla:

    http://www.mozilla.org/scriptable/avoiding-leaks.html

    A snip of code, this javascript code leak:
    <font face="Courier New">
    </font>
    <font face="Courier New">// This function returns an array containing two functions.
    function function_array() {
    // Once this function is done running, this variable is still
    // accessible to the functions created here.
    var private_data = 0;

    var result = new Array();
    result[0] = function() { return (private_data += 1); }
    result[1] = function() { return (private_data *= 2); }
    return result;
    }

    // This function returns the string "Results: 1, 2, 4, 0, 5, 1, 10."
    function test() {
    var fns1 = function_array();
    var fns2 = function_array();
    return "Results: " +
    fns1[0]() + ", " + // increments first private_data to 1
    fns1[1]() + ", " + // doubles first private_data to 2
    fns1[1]() + ", " + // doubles first private_data to 4
    fns2[1]() + ", " + // doubles second private_data to 0
    fns1[0]() + ", " + // increments first private_data to 5
    fns2[0]() + ", " + // increments second private_data to 1
    fns1[1]() + "."; // doubles first private_data to 10</font>
    }
    --Tei

    captcha: "knowhutimean" .. .heee..WTF?



  • (cs) in reply to File Not Available
    Anonymous:
    qqqqqq:
    Just curious, do rdbms' have the query-equivalent of file-not-found?

    This looks like something that fits:

    ORA-00320 cannot read file header from log string of thread string

    Cause: The file is not available.



    UTL_FILE would create other errors, in the most cases it throws user-defined exceptions.
  • (cs) in reply to Anon
    Anonymous:
    Somewhere, deep in the guts of the UK National Air Traffic Services processing system (the guys responsible for routing and timetabling), there's a COBOL program which creates several dozen temporary tables in the course of its activities.
    <br/>
    While working on a summer placement at Uni, they wouldn't let me 'fix it'.  I guess it was their 'The Report'.
    <br/>
    Being COBOL, and an UK government system, it's possible it was written before SQL was standardised, CRTs were invented, or Edison invented the lightbulb.


    So... for something as trivial and minor as air traffic control they wouldn't let some know-it-all student that was there for a month or two rewrite part of this unimportant system? Personally I'd have told you to go play with it and do what you want. After all, it works as it is, and there's no more dedicated a worker than a part time student during his time off Uni!

    I guess that that is the real WTF!
  • (cs) in reply to merreborn

    "think about side affects"

    In a _functional_ language, there _are_ no side effects. You're thinking of imperative languages.

    Except that's not actually true.

    Even if we restrict ourselves to pure functional languages (Haskell, say), there are still side-effects.  I/O is a side-effect, for example.  Hence the use of monads.

  • Yo (unregistered) in reply to ammoQ
    ammoQ:
    Anonymous:
    qqqqqq:
    Just curious, do rdbms' have the query-equivalent of file-not-found?

    This looks like something that fits:

    ORA-00320 cannot read file header from log string of thread string

    Cause: The file is not available.



    UTL_FILE would create other errors, in the most cases it throws user-defined exceptions.


    oracle-sql-test> r
      1  begin
      2  for i in reverse -20000..-1
      3  loop
      4  if (upper(sqlerrm(i)) like '%FILE%NOT%FOUND%') then
      5  dbms_output.put_line(sqlerrm(i));
      6  end if;
      7  end loop;
      8* end;
    ORA-00404: Convert file not found: ''
    ORA-01141: error renaming data file  - new file '' not found
    ORA-01169: DATAFILE number 1 not found.  Must be present
    ORA-01170: file not found ''
    ORA-01512: error renaming log file  - new file  not found
    ORA-03296: cannot resize datafile - file  not found
    ORA-06133: NETTCP: file not found
    ORA-16071: dependency archived log file not found
    ORA-16572: Data Guard configuration file not found
    ORA-19613: datafile  not found in backup set
    ORA-19615: some files not found in backup set
    ORA-19632: file name not found in control file
    ORA-19687: SPFILE not found in backup set
    ORA-19696: control file not found in backup set
    ORA-19697: standby control file not found in backup set

    PL/SQL procedure successfully completed.



    Of course there are "FNF" messages... :)
  • An apprentice (unregistered) in reply to Keith Gaughan
    Keith Gaughan:

    Hmmm... smells like trolling... but I'll bite.

    Let's use some Python code as an example. I'll write all the different ways of expressing this code that I can think of below:

    ...snip...

    # Or there's always reduce()
    return reduce(max, [x, y])

    Sorry for nitpicking, but I think you meant return reduce(max, map(func, [x, y])). Nice and convoluted, too bad the functional features are getting removed...

  • Anonymous Cowherd (unregistered) in reply to JoeBloggs
    Anonymous:
    Anonymous:
    (display "Yeah, sure, no side effects.")

    Until you are doing anything with your code, like, say, input/output...

    LISP is not a proper functional language.


    I think you mean LISP is not a pure functional language. Nor are most other functional languages, such as ML.

  • File Not Available (unregistered) in reply to ammoQ
    ammoQ:
    File Not Available:
    qqqqqq:
    Just curious, do rdbms' have the query-equivalent of file-not-found?

    ORA-00320 cannot read file header from log string of thread string

    Cause: The file is not available.



    UTL_FILE would create other errors, in the most cases it throws user-defined exceptions.

    Actually, the guy asked about QUERY equivalents, which could even make the inquiry and/or answer slightly interesting.  For if you query for a field value which isn't in the table, e.g.
    <FONT face="Courier New">select NAME from SYS.USER$ where NAME = 'FileNotFound';</FONT>
    that's not an error at all, SQL just returns an empty result set.

    However, if we go back to today's WTF and define a cursor using that result set and try to FETCH records inside a loop, we might get something like OCI_NO_DATA (on Oracle).

  • Paul (unregistered) in reply to File Not Available

    I don't understand how he optimised it. Please EXPLAIN. ;)

Leave a comment on “The Magical Mystery Report”

Log In or post as a guest

Replying to comment #:

« Return to Article