What means ".... FROM DUAL" in SQL statements?

Occasionally I find in different SQL statement the appedix "....from dual" e.g.
SELECT blahblah FROM DUAL;
It seems to me that this is a special built-in table.
What does that mean exactely?
Peter

I guess 'FROM' clause is mandatory in Oracle. Hence,
there must always be a table from which we are
selecting values. So, for selecting some arbitary
values which are not coming from any DB Table, we use
this dummy table 'Dual'.
Like
select substr('sometext',5) from dual;
select sysdate from dual ;
etc.
Hope this clarifies.This explanation might be misleading.
The FROM clause is of cause mandatory for a SELECT statement (I think any SQL DB system, not only Oracle). So whenever you need to write a SELECT you might need a dual table.
If you are in PL/SQL you can use most functions without doing a SELECT. Like
a:= substr('sometext',5);
myDate := sysdate;For some things we need to do a select. If we don't have a matching table, then the dual table is handy to return only one row.
example
SELECT mySequence.nextval FROM DUAL;When we are using some tools, like SQL*Plus or T.O.A.D. our typical path to get information returned to the gui is a select. This would be a case were your examples could be used. But you could also do it like this: execute dbms_output.put_line(to_char(sysdate)); After switching the serveroutput on.

Similar Messages

  • Is it possible to create a physical DS from an insert SQL statement?

    Hi,
    From the ALDSP docs I came to know we can create a physical data service from a select SQL statement. Can we use an insert statement to create a physical data service? we dont want to use stored procedure for this.
    Please help.
    Thanks,
    Leela

    When you create a physical data service from a database table, the data service will contain a create<tableName> procedure. That procedure will execute an insert statement for the table.

  • What does || do in a SQL statement after a where with a like?

    We have a packaged application that outputs a SQL statement with the || operator in a where clause along with a LIKE. I have never seen it before and expected it to be a syntax error. I do not see any examples of this syntax in sources such as Morgan's Library.
    For example purposes, observe in the 10g Express Edition currently up for download. Observe that the SQL statement "compiles" when the || operator is used before a like statement, but does not "compile" when used on its own - it gives the error I expected that || is not a relational operator. What does this syntax do?
    For orignal context, the relevant portion of the where clause is:
    T1.QUOTE_NUM || :3 || T1.REV_NUM LIKE :4but the below does so just off of what is available in any instance - much easier to reproduce.
      1  select * from v$sqltext
      2* where (hash_value || 3657695316 || sql_text like 'L%')
    SQL> /
    no rows selected
    SQL> edit
    Wrote file afiedt.buf
      1  select * from v$sqltext
      2* where (hash_value || 3657695316)
    SQL> /
    where (hash_value || 3657695316)
    ERROR at line 2:
    ORA-00920: invalid relational operator
    [pre]
    Thanks for your attention and advice.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    I may have answered my own question. It appears that you can use the || to concatenate strings for comparison with a relational operator as in the example below. I've just never seen this before. Can anyone confirm this is what it really does?
    SQL> select count(*) from dual;
      COUNT(*)
             1
    SQL> select count(*) from dual
      2  where '123' = '123';
      COUNT(*)
             1
    SQL> edit
    Wrote file afiedt.buf
      1  select count(*) from dual
      2* where '123' = '124'
    SQL> /
      COUNT(*)
             0
    SQL> edit
    Wrote file afiedt.buf
      1  select count(*) from dual
      2* where '1' || '23' = '123'
    SQL> /
      COUNT(*)
             1
    SQL> edit
    Wrote file afiedt.buf
      1  select count(*) from dual
      2* where '1' || '23' = '124'
    SQL> /
      COUNT(*)
             0

  • What's wrong with this SQL Statement?

    I hope somebody can help explain to me what is wrong wiht the
    following SQL statement in my Recordest. It does not return an
    error, but it will only filter records from the first variable
    listed, 'varFirstName%'. If I try to use any other variables on my
    search form,for example LastName, it returns all records. Why is it
    doing this?
    Here is the SQL statement:
    SELECT *
    FROM [Sysco Food Show Contacts]
    WHERE FirstName LIKE 'varFirstName%' AND LastName LIKE
    'varLastName%' AND OrganizationName LIKE 'varOrganizationName%' AND
    Address LIKE 'varAddress%' AND City LIKE 'varCity%' AND State LIKE
    'varState' AND PostalCode LIKE 'varPostalCode%'
    The variables are defined as below:
    Name Default Value Run-Time Value
    varFirstName % Request.Form("FirstName")
    varLastName % Request.Form("LastName")
    ...and such with all variables defined the same way.
    Any help would be much appreciated. I am pulling my hair out
    trying to make this Search Form work.
    Thanks, mparsons2000

    PLEASE IGONRE THIS QUESTION!
    There was nothing wrong with the statement. I had made
    another STUDIP mistake!

  • What is wrong with my SQL Statement

    I am getting errors when trying to apply an SQL statement to a report, and I can't figure it out. The error reads: "Syntax error (missing operator) in the query expression 'Title = "Sales Representative"'. Could someone please tell
    me where it is I have gone wrong? The statement is suppose to show records of employees that have Sales Representative as their Title. This is what I came up with:
    SELECT * FROM Employees WHERE Title = “Sales Representative” 

    Try putting brackets around table and field names.  
    I found wrong kind of double quote also ---
    SELECT [Employees].* FROM [Employees] WHERE
    [Employees].[Title] = "Sales Representative"; 
    Build a little, test a little

  • What's wrong with my SQL statement?

    Guys,
    Please help me with this one.
    I am using Oracle JDBC Driver 9.2.0. When I did "select column1, column2 from tableName where rownum<1000", it was really fast. But when I do "select column1, column2 from tableName where rownum between 100 and 200", it won't return. The whole program just sit there, like there is some kind of infinite loop going on or something. I don't know Oracle database at all. Is there anything wrong with my SQL statements or there is some special Oracle SQL statement requirement/syntax?
    Thanks.

    Guys,
    Please help me with this one.
    I am using Oracle JDBC Driver 9.2.0. When I did
    "select column1, column2 from tableName where
    rownum<1000", it was really fast. But when I do
    "select column1, column2 from tableName where rownum
    between 100 and 200", it won't return. The whole
    program just sit there, like there is some kind of
    infinite loop going on or something. I don't know
    Oracle database at all. Is there anything wrong with
    my SQL statements or there is some special Oracle SQL
    statement requirement/syntax?
    Thanks.
    why don't you just try a standard WHERE
    "select column1, column2 from tableName where rownum > 100 and rownum < 200"

  • How to retreive out parameters from function in sql statement

    hi dear,
    Suppose i have a fuction with two "out" parameters, i want to show the values of these paramenters in sql stm.
    like
    select my_function() from dual;
    Thanx

    Can't be done. To use a function in SQL it can only have a single return value.
    Try something like this changing the data types appropriately.
    var x number
    var y number
    var z number
    exec :x := my_function(:y, :z)
    print

  • Can anybody see what is wrong with this SQL statement?

    Hey guys, just a quick question. Can anybody tell me what is wrong with this line of SQL? I keep getting a syntax error message. I've been trying for ages and I can't see any problem at all!"
    {code}prepStat = connection.prepareStatement("INSERT INTO WeatherHistory (Date, Location, Overview, Temperature, WindDirection, WindSpeed, Pressure) VALUES ('"+date+"','"+location+"','"+temp+"','"+windDir+"','"+windSpd+"','"+pressure+"')");{code}
    All the field names and variables definitely exist so I can't see what the problem is!

    DHD wrote:
    Thanks for the replies.
    I've matched the correct number of column names and variables, but still no luck.
    And how exactly am I misusing Prepared Statements here?As noted above, not according to the code you posted. I didn't just pluck something out of my @ss and throw it out there. There was a reason behind what I said. And, if you mean you changed it, and you still got an exception, then post that exception (completely), and your new code, which is, hopefully, using PreparedStatement, (properly).

  • Whats wrong with this sql statement ??

    Hello all, I am trying to run the below query out of persheet(tanel poder) performance excel chart...but i get below error...db is on 9.2
    what is wrong with this sql statement ?
    http://blog.tanelpoder.com/2008/12/28/performance-visualization-made-easy-perfsheet-20-beta/
    select * from (
    with fsq as (
      select /*+ materialize */
       i.dbid
        , i.instance_name
        , i.instance_number
    --    , trunc(s.snap_time, 'DD')     DAY
    --    , to_number(to_char(s.snap_time, 'HH24'))  HOUR
    --   -- , to_char(s.snap_time, 'MI')    MINUTE
    --    , 0           MINUTE
        , trunc(
          lag(s.snap_time, 1)
          over(
           partition by
          v.dbid
           , i.instance_name
           , v.instance_number
           , v.event
         order by
          s.snap_time
          , 'HH24'
         )           SNAP_TIME
        , v.event_type        EVENT_TYPE
        , v.event          EVENT_NAME
        , nvl(
        decode(
         greatest(
          time_waited_micro,
          nvl(
           lag(time_waited_micro,1,0)
           over(
            partition by
             v.dbid
              , i.instance_name
              , v.instance_number
              , v.event
            order by v.snap_id
           , time_waited_micro
         time_waited_micro,
         time_waited_micro - lag(time_waited_micro,1,0)
         over (
          partition by
           v.dbid
            , i.instance_name
            , v.instance_number
            , v.event
          order by v.snap_id
         time_waited_micro
           , time_waited_micro
         ) / 1000000         SECONDS_SPENT
        , total_waits         WAIT_COUNT
      from
       (select distinct dbid, instance_name, instance_number from stats$database_instance) i
        , stats$snapshot s
        , ( select
         snap_id, dbid, instance_number, 'WAIT' event_type, event, time_waited_micro, total_waits
        from
         stats$system_event
        where
         event not in (select event from stats$idle_event)
        union all
        select
         snap_id, dbid, instance_number,
         case
          when name in ('CPU used by this session', 'parse time cpu', 'recursive cpu usage') then 'CPU'
          when name like 'OS % time' then 'OS'
          else 'STAT'
         end,
         name , value, 1
        from
         stats$sysstat
    --    where      name in ('CPU used by this session', 'parse time cpu', 'recursive cpu usage')
    --    or  name like('OS % time')
    --    or 1 = 2 -- this will be a bind variable controlling whether all stats need to be returned
       ) v
      where
       i.dbid = s.dbid
      and i.dbid = v.dbid
      and s.dbid = v.dbid
      and s.snap_id = v.snap_id
      and s.snap_time between '%FROM_DATE%' and '%TO_DATE%'
      and i.instance_name = '%INSTANCE%'
    select * from (
      select
       instance_name
        , instance_number
        , snap_time
        , trunc(snap_time, 'DD')  DAY
        , to_char(snap_time, 'HH24') HOUR
        , to_char(snap_time, 'MI') MINUTE      
        , event_type  
        , event_name  
        , seconds_spent
        , wait_count  
        , ratio_to_report(seconds_spent) over (
    --      partition by (to_char(day, 'YYYYMMDD')||to_char(hour,'09')||to_char(minute, '09'))
          partition by (snap_time)
          ) ratio
      from fsq
      where
       snap_time is not null -- lag(s.snap_time, 1) function above will leave time NULL for first snapshot
      -- to_char(day, 'YYYYMMDD')||to_char(hour,'09')||to_char(minute, '09')
      -- > ( select min(to_char(day, 'YYYYMMDD')||to_char(hour,'09')||to_char(minute, '09')) from fsq)
    where ratio > 0
    order by
        instance_name
      , instance_number
      , day
      , hour
      , minute
      , event_type
      , seconds_spent desc
      , wait_count desc
    Error at line 6
    ORA-00604: error occurred at recursive SQL level 1
    ORA-00972: identifier is too long

    Hi Alex,
    Subquery factoring a.k.a. the with-clause should be possible on 9.2:
    http://download.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_103a.htm#2075888
    (used it myself as well on 9.2)
    @OP
    I recall having problems myself using PL/SQL Developer and trying to get the with clause to work on 9.2 some years ago.
    A workaround might be to create a view based on the query.
    Also, your error message is "ORA-00972: identifier is too long"...
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14219/e900.htm#sthref419
    Can't test things currently, no 9.2 available at the moment, but perhaps tomorrow I'll have a chance.

  • JDBC Lookup in PI 7.1 - SELECT ? FROM DUAL and Connection timed out

    Hi,
    We have a scenarios (Idoc to JMS) with JDBC lookup. We have used graphical JDBC lookup functionality.
    We are reading country names for a given country code from SAP in an external database table. The query is so simple. That  should not take much time
    Now the actual issues is,
    When we are executing the scenario, its taking quite a long time. Almost 6 minutes to excute a mapping. Which causing high performance issue in the Porduction.
    We started the inviestigation about found some interesting stuff. Here we have used Willy Introscope for the investigation.
    1. First few messages are taking quite a long time. LIke 6 minutes per messages. As i can see in the log i am getting below error in Willy,
    I dont know why PI is executing below queury apart from real secelt query to fetch the country name. I am getting below error: Error Message: Backends|ABCD2 mydatabase01-1526 (Oracle DB)|SQL|Dynamic|Query|SELECT ? FROM DUAL: java.sql.SQLException: Io exception: Connection timed out
    2. After couple of messages, interface works very normal. I mean rest of the messages works pretty fine.
    Please let me know if you have any idea about this error. What could be the problem for the issue.
    Thank you in advnace.
    Best Regards,
    Prasad.

    Did you check how many SQL requests were executed per one message ? Do you have a log of these SQL requests ?
    I assume that the country table is quite small, so that lookup should not be an issue.
    About this:
    >Message: Backends|ABCD2 mydatabase01-1526 (Oracle DB)|SQL|Dynamic|Query|SELECT ? FROM DUAL: >java.sql.SQLException: Io exception: Connection timed out
    1. I only know SELECT * FROM DUAL, not SELECT ? FROM DUAL. Better use the former
    2. the exception means that the database server can not be reached => check your network configuration
    So I assume that there is a network (performance) problem between PI and this Oracle server. Or the Oracle Server is so overloaded that it has (sometimes) problems in processing new requests.
    CSY
    Edited by: Christian Sy on Mar 9, 2010 10:17 AM

  • PASSING PARAMETER IN SQL STATEMENT .

    HI,
    Can any one tell me how to use on of the field name as a parameter in the same sql statement ? Here is what i am looking for :
    SELECT EMPNO, DEPTNO, (SELECT COUNT(ORDERNO) FROM ORDERS WHERE DEPTNO = :DEPTNO AND EMPNO = :EMPNO) TOTAL_ORDER FROM EMP;
    Here the embeded sql statment should take the paramter :DEPTNO , :EMPNO from the main sql statement. That means , each DEPTNO, EMPNO should be passed as a aparameter to the embeded SQL statement.
    Thanks
    Feroz

    WHATS THE CONACT, ||, +, HOW TO USE IT, CAN U GIVE ME AN EXAMPLE.
    SORRY , HERE IS THE ACTUAL THING WHAT I AM LOOKING FOR, I WANT TO GET THE MEDIAN AND MODE VALUE IN ORACLE, BUT COZ ORACLE DOES NOT HAVE IN BUILT FUNCTION TO ET THE ABOVE TOW , I WROTE MY SQL STATEMENTS, FOR EXAMPLE THE MEDIAN OF SAL FOR DEPT 20 IS IS
    SELECT AVG(SAL) FROM
    (SELECT RowNum The_Rownum, SAL FROM
    (SELECT SAL FROM EMP WHERE DEPTNO = 20 ORDER BY 1)) V
    WHERE V.The_Rownum = ( SELECT FLOOR((COUNT(SAL)+1)/2) FROM EMP WHERE DEPTNO = 20)
    OR V.the_rownum = (SELECT CEIL((count(SAL)/2) + 1/2) FROM EMP WHERE DEPTNO = 20)
    This median value ncalculation i can put in a functio and return it, but for a record os 1,800,000 volume, calling this function that many times, the sql never executes. It just hangs. so i thought if i can emabede the whole calculaton in the main sql statement instead of writing a function and calling that function in the sql statement. But the median calculation needs the department no as a parameter to calculate the median for that perticular department. Here , where the requirement of PARAMETER comes. ANY IDEA ???
    Thanks
    Feroz

  • Output of value returned from function in SELECT statement ??

    Hi
    I have created the below function
    create or replace
    FUNCTION jc_test
    RETURN VARCHAR2
    IS myrec VARCHAR2(270);
    BEGIN
    SELECT RPAD('*',270,'*')
    INTO myrec
    FROM DUAL ;
    RETURN myrec;
    END ;
    and I executed the SELECT statement in Oracle SQL developer as a script
    select
    LENGTH(jc_test()) len
    *,jc_test() rec*
    from dual ;
    I get exact output as below
    LEN REC
    270 ******************************************************************************************************************************************************************************************************************************************************************************
    So here LEN is correctly shown as 270 characters but when I see the astrisk's (also appended with spaces ) its total length is 4000 characters
    Can anyone give their thoughts on this.
    Its fine if I run as normal, i mean not as a script.
    Regards
    jc
    Edited by: JC on Jun 16, 2011 11:25 AM

    Hi,
    So here LEN is correctly shown as 270 charactersYes, correct
    but when I see the astrisk's (also appended with spaces ) its total length is 4000 charactersNo buts. It is not padded. That is just how it is displayed by your tool. In SQL*Plus this is controlled by LINESIZE and COLUMN
    SQL> create or replace function dummy return varchar2 as begin return null; end;
      2  /
    Function created.
    SQL> select dummy from dual;
    D
    X
    SQL> select dummy() from dual;
    DUMMY()
    SQL> col "dummy()" for a10
    SQL> select dummy() from dual;
    DUMMY()
    SQL>P.S: It is a really bad idea to create your own wrapper functions, built-in functions. Hopefully you are not really doing that?
    Regards
    Peter

  • Query SQL Statement & Update SQL Statement

    Hi!
    I configure the JDBC adapter sender (XI) to take data from MSSQL database.
    I have to run select like this:
    SELECT
    tblMilestone.Site,
    tblMilestone.Revision,
    tblMilestone.MilestoneNameID,
    tblMilestone.ApprovedDate,
    tblMilestoneName.MilestoneName
    FROM
    tblMilestoneName
    INNER JOIN tblMilestone ON tblMilestoneName.MilestoneNameID = tblMilestone.MilestoneNameID
    WHERE tblMilestone.StatusCode = 1;
    My question is what "Update SQL Statement" I should use in communication channel definition? I only need to update tblMilestone or this two tables?
    Maybe you give me some example.

    Check this from SAP help...
    Update SQL Statement
    You have the following options:
    &#9679;     Enter a valid SQL statement that is to be applied to the database once the data (determined from the Query SQL Statement) has been successfully sent to the Integration Server/PCK.
    It must be an INSERT, UPDATE, or DELETE statement.
    &#9679;     In place of the SQL statement, you can also enter <TEST>. Once the data determined from Query SQL Statement has been successfully sent, the data in the database remains unaltered.
    This is recommended if the data has not only been read, but also changed by a stored procedure entered under Query SQL Statement.

  • SQL statement help

    If someone would be so kind, I need help in formulating a SQL statement.
    Table A - employees(empoyee_id, employee_name, status)
    This table contains all employees
    employee status can be one of three values (A=active, T=temporary, I=inactive)
    Table B - savings_program(employee_id, plan_type)
    This table only has employee_id's of those that participate in a savings program (subset of all employees).
    plan_type can be one of three numeric values (30,35,40)
    I need SQL to report a.employee_id,a.employee_name,b.plan_type (return plan_type 30,35, or none)of all active employees in Table A that don't participate in Table B plan_type 40.
    Working with version 9iR2. Thanks!
    Edited by: fosterk on Nov 21, 2008 12:59 PM

    The tables and columns above were for demo purposes but actual code I'm trying is below. Please excuse me I'm more of an SA type so SQL is not my thing.
    As you can see from the first SQL statement below I know that I have exactly
    3,000 employees that meet this criteria. The second SQL statement is my attempt to return the rows I want (I'm just nesting it in a count(*) until the numbers look right)
    The last statement is what was given to me by someone else (seeking my help haha) trying to resolve it and it only returns 3 rows. This SQL shows the actual columns that we're trying to return from both tables.
    HR> select count(*) from ps_All_employees where empl_status != 'T'
    2 and emplid not in
    3 (select emplid from ps_savings_pt_vw where plan_type = 40)
    4 /
    COUNT(*)
    3000
    HR> select count(*) from (
    2 (select * from ps_all_employees where empl_status != 'T') a left outer join
    3 (select emplid from ps_savings_pt_vw where plan_type != 40) s
    4 on a.emplid = s.emplid
    5 )
    6 /
    COUNT(*)
    4587
    select count(*) from (
    select a.location, a.ssn, a.first_name, a.last_name, a.birthdate, a.orig_hire_dt, a.hire_dt, a.location, a.street1,
    a.street2, a.city, a.state, a.zip, s.plan_type
    from ps_all_employees a, ps_savings_pt_vw s
    where a.empl_status != 'T' and
    a.emplid = s.emplid and
    a.emplid not in (select s.emplid from ps_savings_pt_vw s where s.plan_type = 40)
    COUNT(*)
    3

  • Why there having duplicate record occur by simply sql statement

    The table is following
    SQL> desc customers;
    名稱 空值? 類型
    TID NOT NULL NUMBER(38)
    COM_NUM VARCHAR2(4000)
    COM_NAME NOT NULL VARCHAR2(4000)
    COM_ADDRESS VARCHAR2(4000)
    COM_TEL VARCHAR2(4000)
    COM_FAX VARCHAR2(4000)
    COM_CONTACT VARCHAR2(4000)
    COM_MOBILE VARCHAR2(4000)
    COM_COUNTRY VARCHAR2(4000)
    COM_BRANCH NOT NULL NVARCHAR2(1)
    COM_SALE_ID NUMBER
    COM_TRANSPORT_ID NUMBER
    COM_PAYMENT_DAY NOT NULL NUMBER
    COM_HEADER_NAME VARCHAR2(4000)
    COM_DISABLED NOT NULL NVARCHAR2(1)
    COM_BALANCE NOT NULL NUMBER(12,2)
    SQL is select tid,com_name from customers where tid=360;
    SQL> select tid,com_name from customers where tid=360;
    TID     COM_NAME
    360 利富家品
    360 利富家品
    the statement is select one record, but there are two duplicate record occur.
    is anyone free to help me?
    Thanks a lot

    By yours SQL statement,
    select unique tid,com_name from customers where tid=360;
    there will one record only now.
    is being filled ? NO filled any things
    integrity rules ? I am not understand what is integrity rules,
    my sql statement was
    select * from customers where com_disabled = 0 order by com_name
    most of record is appear once, BUT, some of those is appeared twice. Not only the record tid = 30
    is there a way SQL statement like
    select unique * from customers where com_disabled = 0 order by com_name?
    curious ? Chinese words
    Message was edited by:
    Devotee

Maybe you are looking for

  • Background Jobs with Dynamic Dates

    I am looking for how to run a job in the background on a Daily basis where the data time range is always Yesterday - specifically, I want to run a Notification report daily to see the previous day's notifications. I have established a Variant with th

  • The icon for Norton Identity Safe has disappeared and I can't figure out how to get it back on my toolbar.

    I use Norton which has a feature called "Identity Safe." In the old version of Mozilla, the icon for this feature was available on my toolbar. Now that I have converted to the latest version of Firefox, the icon has disappeared and I cannot figure ou

  • Safari (5) Keeps Crashing on Startup

    Every time I open Safari, it crashes. I have reset the cache, cookies, etc. no luck. I have even completely removed it and reinstalled it. No progress. Any Suggestions? Here is the code that it provides me when Safari crashes: Process: Safari [10524]

  • Disappearing footnote numbers in InDesign CS4

    Hi all, This is my very first post here, and hope that this is the right place to expose my problem. Forgive me if this is not so. The thing is, some footnotes numbers (both in the text body and in the footnote) are nowhere to be seen in the pdf vers

  • How to work with Group Administration

    I am working as a System Administration. I have knowledge in Windows based environment. I am newly got a job, where I have to maintain MAC based servers. I don't have knowledge about USER and GROUP Administration. Please help me out about this thorou