Invalid identifier on the Select statement

New to SQL. I'm having some trouble with a function.
Assignment is:
1. develop and execute a CREATE FUNCTION statement to create the DAY_ORD_SF function. Use the column DTCREATED table bb_basket as the date that the basket was created. Call the function TO_CHAR using the option of the DAY to extract the day of the week for a date value.
1. create a SELECT statement that lists the basket id and the day of the week set for each basket.
3. create a SELECT with a GROUP BY clause query to list the total number of baskets by day of the week. Who is the most popular of a day shopping? (Should discover that it is FRIDAY).

So far, I have the function:
CREATE OR REPLACE FUNCTION DAY_ORD_SF (P_ORDER_DATE IN BB_BASKET.DTORDERED%TYPE)
 RETURN VARCHAR2
 IS
   LV_DAY_WK VARCHAR2(3);
BEGIN
 SELECT TO_CHAR(P_ORDER_DATE, 'DAY') 
  INTO LV_DAY_WK
  FROM BB_BASKET
  WHERE P_ORDER_DATE = DTORDERED;
 RETURN LV_DAY_WK;
END;
/
Have you tried a select invalid identifier and get on o_dt. have you tried several different variables and impossible to find one that works.
SELECT DAY_ORD_SF(O_DT) "DAY", COUNT(*)
FROM BB_BASKET
GROUP BY DAY_ORD_SF(O_DT)
;
Any help would be appreciated.

>
DTCREATED is a column name in the table BB_BASKET. When I pass O_DT to DTCREATED, I get an error:
>
So track what causes this error. Your instructions were to use DTCREATED.

You use this query in your service

SELECT TO_CHAR(P_ORDER_DATE, 'DAY')
  INTO LV_DAY_WK
  FROM BB_BASKET
  WHERE P_ORDER_DATE = DTORDERED;

And the error tells you that LV_DAY_WK is too small. Why is it too small? Look at how it is defined and then look at the results of this query

SELECT TO_CHAR(DTCREATED, 'DAY')
  FROM BB_BASKET

and see if you can see what the problem is.

You do your development backward. Failed to start by trying to call a function that does not work. And you can't start by writing a function that includes queries that have not been tested.

The right way to generate code is to create simple components. Then test these simple components (for example a query) to ensure they work. Then mix the simple components in a component more complex as a function. Then, you can test the function of another request call.

The key is to start with simple things that work.

Tags: Database

Similar Questions

  • uniol all in the select statement

    Hi I have a situation where I have to return the value based on the if statement, is it possible to put union all in the select statement

    My use case is

    IN the column State

    If column01 > 0 to condtion 't'

    IF column02 > 0 that the condition of 'Y '.

    Condition IF COLUMN03 > 0 THAN 'w '.

    If COLUMN04 > 0 that the condition of "Z".

    Select 't'

    TableName

    where column01 > 0

    Union of all the

    Select "y".

    TableName

    where column02 > 0

    Union of all the

    Select 'W '.

    TABLENAME

    WHERE COLUMN03 > 0

    I have what it takes to show value as it

    EmpName, condition, empno

    Jerry, T, 0158754585

    TOM, Y, 0054789568

    Am in oracle database 11 g 2

    Yes you can put all THE UNION here

    Select empname, 't' State, empno from tablename where column01 > 0

    Union of all the

    Select empname, 't' State, empno from tablename where column02 > 0

    Union of all the

    Select empname, condition of "W", empno FROM tablename WHERE COLUMN03 > 0

    Union of all the

    Select empname, condition of "Z", empno FROM tablename WHERE COLUMN04 > 0

    and if you are looking for how to remove duplicates because your line might have satisfied all the conditions and my happen 4 times in your result set, you just need to give them an order and filter it.

    For example, you want this

    If column01 > 0 to condtion 't'

    ELSE IF column02 > 0 that the condition of 'Y '.

    Another condition of THAN > 0 IF COLUMN03 'w '.

    otherwise if COLUMN04 > 0 that the condition of "Z".

    Select empname, condition, empno, in

    (

    Select a.*, row_number() over (partition by empno arrested by myorder) rn

    Of

    (

    Select empname, 't' State, empno, 1 myorder tablename where column01 > 0

    Union of all the

    Select empname, 't' State, empno, 2 myorder tablename where column02 > 0

    Union of all the

    Select empname, condition of "W", empno 3 myorder FROM tablename WHERE COLUMN03 > 0

    Union of all the

    Select empname, empno, condition of 'Z', 4 myorder FROM tablename WHERE COLUMN04 > 0

    ) a

    ) where rn = 1

  • There is no possibility of ambiguity in the SELECT clause because any identifier in the SELECT clause must be a database column name

    Hello

    Doc Oracle says the following on the identifiers in the SELECT in PL/SQL clause: there is no possibility of ambiguity in the SELECT clause because any identifier in the SELECT clause must be a database column name.

    If we assume that only valid column identifier are allowed in the SELECT clause.

    But I tried the following:

    DECLARE
    toto NUMBER := 10;
    tata NUMBER := 0;
    BEGIN
    SELECT toto INTO tata FROM employees WHERE employee_id = 101;
    DBMS_OUTPUT.PUT_LINE(tata);
    END;
    /
    

    And there is no error telling me that toto is not a column in the employees table and the result is the same as: toto: = aunt;

    Won't the doc or did I just miss something?

    Thanks for your response!

    Hello

    rep0ne wrote:

    Hello

    Doc Oracle says the following on the identifiers in the SELECT in PL/SQL clause: there is no possibility of ambiguity in the SELECT clause because any identifier in the SELECT clause must be a database column name.

    If we assume that only valid column identifier are allowed in the SELECT clause.

    Post a link to this Oracle doc.

    But I tried the following:

    1. DECLARE
    2. Toto NUMBER: = 10;
    3. Auntie NUMBER: = 0;
    4. BEGIN
    5. SELECT toto IN Auntie FROM Employees WHERE employee_id = 101;
    6. DBMS_OUTPUT. Put_line (Auntie);
    7. END;
    8. /

    And there is no error telling me that toto is not a column in the employees table and the result is the same as: toto: = aunt;

    ...

    You're right that toto is an identifier, but this isn't a column name.  (Of a subquery) column alias are not database of the names of columns either, nor are the names of the user-defined function.

    Also, there is a possibility for ambiguity even if all the names are the database column names.

    Won't the doc or did I just miss something?

    I can't say until I see the doc you're talking about.

    Oracle documentation is sometimes misleading and sometimes just plain wrong.  For each mistake outright example that I saw in the docs of Oracle, there might be 20 cases where the meaning is unclear or misleading and maybe 200 where I just read it wrong.

  • mixture of column type in the select statement

    Oracle 11g r2.

    tab_test (name varchar2, blob... photo)

    (1) select general use *.

    Stored procedure: open ref_cursor to some * of table_test...

    Coast of java: call.registerOutParameter (1, OracleTypes.CURSOR);  Call.Execute ();

    It works very well.

    (2) enter the name of the column in the select such as

    Stored procedure: open ref_cursor to select name, photo table_test...

    Coast of java: call.registerOutParameter (1, OracleTypes.CURSOR);  Call.Execute ();

    ERROR: java.sql.SQLSyntaxErrorException: ORA-00932: inconsistent data types: expected - got BLOB

    My question, if I specify the column names in the select statement, including the varchar2 and blob, how can I registerOutParameter (1, OracleTypes.CURSOR);?

    Thank you

    Scott

    PS The number of returned columns, in real case schenario, is a little, so I prefer to specify column names.

    Wrong forum. This forum is for questions of sql and pl/sql.

    Enter the question ANSWER and the repost in the JDBC forum

    https://community.oracle.com/community/developer/english/java/database_connectivity/java_database_connectivity _(jdbc)

    When repost you provide the necessary information to help you:

    1. information on the full version for Oracle DB

    2 version of the JDK

    3. the name and version of the JDBC jar file

    4. real code that demonstrates the problem

    You should also review the info re REF CURSOR in the JDBC Developer's Guide

    http://docs.Oracle.com/CD/E16655_01/Java.121/e17657/oraint.htm#i1058743

  • function() nested in the select statement

    Oracle 11g. Try to nest a function within the select statement.  Goal: get the average customer rating for each of the qualified user.

    Select user_name, f_get_avg_cust_rating() "Notation.

    of u, OTHER_TABLES o TAB_USER

    where u.id = o.id and another condition matched;

    How Oracle would deal with the sql.  Is it

    (1) first of all display records based on the where clause, then call the f_get_avg_cust_rating() for each of the selected records OR

    (2) for the analysis in tables, the f_get_avg_cust_rating() will be called for each record met?

    Thank you

    Scott

    Words of Frank, I created two functions with dbms_output and used a function in where clause in select another function. See the bottom of the unit tests. Everyone says, where first clause then select...

    -Where function clause

    SQL > CREATE or REPLACE FUNCTION ret_empno

    2 RETURN NUMBER

    3 AS

    4 BEGIN

    5 DBMS_OUTPUT. Put_line (' where Clause Function');

    6 RETURN 7839;

    7 END;

    8.

    The function is created.

    -Select the function

    SQL > CREATE or REPLACE FUNCTION ret_1

    2 RETURN NUMBER

    3 AS

    4 BEGIN

    5 DBMS_OUTPUT. Put_line ('Select function');

    6 RETURN 1;

    7 END;

    8.

    The function is created.

    SQL > SELECT empno, ename,ret_1

    2 FROM emp

    3. WHERE empno = ret_empno;

    EMPNO, ENAME RET_1

    ---------- ---------- ----------

    7839 KING 1

    Where the function Clause

    Select the function

  • Pivot will not get result in the select statement

    This is the version of oracle 11g R2 on windows details 7 OS

    CREATE TABLE OTBOOKINGDETAILS
    (EMPNO VARCHAR2 (10 BYTE),
    DATE OF OTBOOKEDDATE,
    NUMBER (5.0) DAY OF THE WEEK.
    DAYCEILINGHRS VARCHAR2 (10 BYTE));

    Here is the data

    INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 MARCH 2013', 1,' 09:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 APRIL 2013', 2' 01:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 MAY 2013', 3,' 01:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 JUNE 2013', 4' 01:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 JULY 2013', 5,' 01:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 AUGUST 2013', 6,' 01:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 SEPTEMBER 2013', 7,' 00:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (102 ', 3 MARCH 2013', 1,' 09:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (102 ', 3 APRIL 2013', 2' 01:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (102 ', 3 MAY 2013', 3,' 01:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (102 ', 3 JUNE 2013', 4,' 02:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (102 ', 3 JULY 2013', 5,' 01:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (102 ', 3 AUGUST 2013', 6,' 04:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (102 ', 3 SEPTEMBER 2013', 7' 01:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 OCTOBER 2013', 1,' 00:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 NOVEMBER 2013', 2' 01:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 DECEMBER 2013', 3,' 01:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 13 MARCH 2013', 4,' 04:45 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 14 MARCH 2013', 5,' 01:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 15 MARCH 2013', 6,' 01:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 16 MARCH 2013', 7' 01:00 ');

    Here, I want to Dayceiling hours below the output using pivot

    EMPNO OTBOOKEDDATE DAY1_HRS DAY2_HRS DAY3_HRS DAY4_HRS DAY5_HRS DAY6_HRS DAY7_HRS
    101 03/03/2013 09:00 01:00 01:00 01:00 01:00 01:00 00:00
    102 03/03/2013 09:00 01:00 01:00 02:00 01:00 04:00 01:00
    101 03/10/2013 00:00 01:00 01:00 04:45 01:00 01:00 01:00

    ChakravarthyDBA wrote:
    I need to include the pivot query in the select statement

    Can' are you use PIVOT here since you do not know from the start what values OTBOOKEDDATE. So use:

    select  empno,
            otbookeddate - weekday + 1 otbookeddate,
            max(
                case weekday
                  when 1 then dayceilinghrs
                end
               ) day1_hrs,
            max(
                case weekday
                  when 2 then dayceilinghrs
                end
               ) day2_hrs,
            max(
                case weekday
                  when 3 then dayceilinghrs
                end
               ) day3_hrs,
            max(
                case weekday
                  when 4 then dayceilinghrs
                end
               ) day4_hrs,
            max(
                case weekday
                  when 5 then dayceilinghrs
                end
               ) day5_hrs,
            max(
                case weekday
                  when 6 then dayceilinghrs
                end
               ) day6_hrs,
            max(
                case weekday
                  when 7 then dayceilinghrs
                end
               ) day7_hrs
      from  otbookingdetails
      group by empno,
               otbookeddate - weekday + 1
      order by otbookeddate,
               empno
    /
    
    EMPNO      OTBOOKEDDA DAY1_HRS   DAY2_HRS   DAY3_HRS   DAY4_HRS   DAY5_HRS   DAY6_HRS   DAY7_HRS
    ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
    101        03-03-2013 09:00      01:00      01:00      01:00      01:00      01:00      00:00
    102        03-03-2013 09:00      01:00      01:00      02:00      01:00      04:00      01:00
    101        10-03-2013 00:00      01:00      01:00      04:45      01:00      01:00      01:00
    
    SQL> 
    

    SY.

  • validation for each 1,000 records to be inserted in the select statement

    Hi, I have the following INSERTION in the SELECT statement.
    The SELECT statement (who joined) data fo about 6 crores. I need to insert this data into another table.

    Please suggest me the best way to do it.
    I use the INSERT in the SELECT statement, but I want to use the statement commit for each 1,000 records.

    How can I do this...
    insert into emp_dept_master 
     select e.ename ,d.dname ,e.empno ,e.empno ,e.sal 
       from emp e , dept d
      where e.deptno = d.deptno       ------ how to use commit for every 1000 records .
    Thank you

    Method 4 is the best

    You could combine method 3 and 1 (without dynamic SQL)

    Method 2 is the less optimal solution from the list.

  • SHOW_LOV need to pass a parameter for the select statement

    Hello

    I have a requirement that there is only a drop down list but the display of the list should be based on the certern parameter.

    I have a table (id, type, description). The select statement for dropdown I need is

    SELECT id, description of the table where type = & input_param.

    Can someone help please!

    create a field and create value in the list select id, description from table1 where col =: block1.item

  • Menu Module v2 supported for the selected state?

    I can't understand if v2 menu module supports the selected state. I remember reading somewhere that it was planned to produce in the future, but it seems that the file /ModuleTemplates/Menu/Default/container.html has accommodations for her.

    A resource if so, it would be appreciated.

    By default I did, the JavaScript code is there in the updates page and not different from the normal version in this respect.

  • passing multiple values from the query in the select statement of the procedure

    I am collecting IDS to select education agreement from the date of rental values and then I would pass the result of the query in the statement select to get the result.
    data type for the contract id is of type varchar and date of rental there is more than one id to contract for most of the time. Help, please. Thank you

    CREATE OR REPLACE PROCEDURE abstract_menu (p_letting   IN     VARCHAR2,
                                               p_results      OUT SYS_REFCURSOR)
    IS
       v_contractId   VARCHAR2 (40);
    
    SELECT lcontid
      INTO v_contractId
      FROM letprop
     WHERE datestat IS NOT NULL AND letting = p_letting AND letstat <> 'R';
    
    
    BEGIN
       OPEN p_results FOR
            SELECT DISTINCT
                      SUBSTR (l.letting, 3, 2)
                   || '-'
                   || SUBSTR (l.letting, 5, 2)
                   || '-'
                   || SUBSTR (l.letting, 1, 2)
                      lettingdate,
                   l.lcontid contractid,
                   SUBSTR (q.cprojnum, 1, 10) projectnumber,
                   DECODE (TRIM (MIN (j.route)), NULL, 'N/A', TRIM (MIN (j.route)))
                      routenumber,
                   L.DATESTAT statusdate,
                   L.LETSTAT lettingstatus,
                   (q.cdescr) jobdescription,
                   INITCAP (q.clocat1 || q.clocat2) LOCATION
              FROM vendor v,
                   vendaddr r,
                   letprop l,
                   planhold p,
                   proposal q,
                   project j,
                   propproj k,
                   bidlet bd
             WHERE     v.vendor = r.vendor
                   AND k.contid = q.contid
                   AND k.pcn = j.pcn
                   AND l.lcontid = k.contid
                   AND p.vendor = v.vendor
                   AND l.letting = p.letting
                   AND l.lcontid IN v_contactid  "**************This is where I would like to pass the contract id from the above select statement***********'"
                   AND l.CALL = p.CALL
                   AND r.addrnum = p.billto
                   AND bd.letting = l.letting
          GROUP BY q.cdescr,
                   q.clocat1,
                   q.clocat2,
                   bd.letting,
                   l.letting,
                   l.lcontid,
                   q.cprojnum,
                   L.LETSTAT,
                   L.DATESTAT
          ORDER BY lettingdate;
    
    end;

    user9196150 wrote:
    AND l.lcontid IN v_contactid ' * this is where I would like to pass the id of the select statement above contract * ""»

    CREATE OR REPLACE PROCEDURE abstract_menu (p_letting   IN     VARCHAR2,
                                               p_results      OUT SYS_REFCURSOR)
    IS
    BEGIN
       OPEN p_results FOR
            SELECT DISTINCT
                      SUBSTR (l.letting, 3, 2)
                   || '-'
                   || SUBSTR (l.letting, 5, 2)
                   || '-'
                   || SUBSTR (l.letting, 1, 2)
                      lettingdate,
                   l.lcontid contractid,
                   SUBSTR (q.cprojnum, 1, 10) projectnumber,
                   DECODE (TRIM (MIN (j.route)), NULL, 'N/A', TRIM (MIN (j.route)))
                      routenumber,
                   L.DATESTAT statusdate,
                   L.LETSTAT lettingstatus,
                   (q.cdescr) jobdescription,
                   INITCAP (q.clocat1 || q.clocat2) LOCATION
              FROM vendor v,
                   vendaddr r,
                   letprop l,
                   planhold p,
                   proposal q,
                   project j,
                   propproj k,
                   bidlet bd
             WHERE     v.vendor = r.vendor
                   AND k.contid = q.contid
                   AND k.pcn = j.pcn
                   AND l.lcontid = k.contid
                   AND p.vendor = v.vendor
                   AND l.letting = p.letting
                   AND l.lcontid IN (
                                     SELECT  ll.lcontid
                                       FROM  letprop ll
                                       WHERE ll.datestat IS NOT NULL AND ll.letting = p_letting AND ll.letstat  'R'
                                    )
                   AND l.CALL = p.CALL
                   AND r.addrnum = p.billto
                   AND bd.letting = l.letting
          GROUP BY q.cdescr,
                   q.clocat1,
                   q.clocat2,
                   bd.letting,
                   l.letting,
                   l.lcontid,
                   q.cprojnum,
                   L.LETSTAT,
                   L.DATESTAT
          ORDER BY lettingdate;
    
    end;
    /
    

    SY.

  • Set the Variable in the select statement

    Hello

    Can we define a variable in the select statement.

    Example:

    Select firstname, lastname
    employees;

    in this simple select statement we can define x as number?
    select fname,lname
    from employees
    where rownum <= 30;
    
  • to find the number of records retrieved in the select statement in the cursor

    Hi all
    with the cursor, I'm selecting select statement together and writing in the .txt file.
    his worksheet, but it should not open the file, if the cursor returns nothing.
    How to find the number of records returned by the select statement in the cursor.
    pls help me.

    Thank you...

    Don't understand what you're trying to say, but maybe it's...

    DECLARE
       vCounter NUMBER;
       -- Other variables...
    BEGIN
       vCounter:=0;
       FOR .. IN cursor LOOP
        IF vCounter=0 THEN
          -- Here open file...
          -- Here write one time data...
        END IF;
        -- Here write cursor data...
        vCounter:=1;
       END LOOP;
    END;
    

    -Clément

  • Cross tab in the SELECT statement?

    Hello

    The following SQL statement:
    SELECT
    T.LASTFIRST, C.COURSE_NAME, CC. COURSE_NUMBER, CC. SECTION_NUMBER, CC. EXPRESSION, ST. SEX, COUNT (CC.) STUDENTID) STUDENTCOUNT
    TEACHERS T
    JOIN THE CC
    ON CC. TEACHERID = T.DCID
    JOIN THE COURSE C
    ON C.COURSE_NUMBER = CC. COURSE_NUMBER
    JOIN STUDENTS ST
    ON CC. STUDENTID = ST.ID
    WHERE CC. SCHOOLID = 100 AND TERMID > = 1900
    T.LASTFIRST, C.COURSE_NAME, CC GROUP. COURSE_NUMBER, CC. SECTION_NUMBER, CC. EXPRESSION, ST. BETWEEN THE SEXES
    ORDER OF T.LASTFIRST, CC. COURSE_NUMBER, CC. SECTION_NUMBER, CC. EXPRESSION, ST. BETWEEN THE SEXES

    Returns the following dataset:
    Abram, American history Michael SOC1000 1 a 2 F 7
    Abram, American history Michael SOC1000 1 has 2 M 12

    Is there a way to make the count gender for each sex, introduce yourself as a column in the SELECT statement so that there is only ONE row returned by course number with as FEMALECOUNT and MALECOUNT column headers?

    I tried to use a statement select count nested inside the original SELECT statement but without success.

    Jeff

    You should be able to use a CASE statement for this in collaboration with the County. COUNTY does not indicate that null instances no I have not specified a part to the CASE ELSE (so the default value is NULL).

    COUNT(CASE ST.GENDER WHEN 'F' THEN 1 END) as Female_count,
    COUNT(CASE ST.GENDER WHEN 'M' THEN 1 END) as Male_count, 
    

    Note that you need to remove the Gender of your query column.

  • How to ask the user to type in the select statement

    Hello

    Can anyone tell me the syntax of the select statement where I can ask the user to enter the value.

    for example, I try to use belowthing, but it displays error

    Select * from emp where empname =: empname

    SP2-0552: Bind "empname' undeclared variable.


    2. is there a dictionary of data table to see all pl/sql procedures and corresponding code?


    Thank you
    Sri

    Try:

    select * from emp where empname='&empname';
    

    L.

  • How to pass parameter in the function using the select statement?

    Hello

    I had a problem. I can't pass as parameter to the function by using the select statement. But it can pass as a parameter using the "code". How can I solve this problem?

    For example,.
    Select * from table (SplitFunction ('HS750020, HS750021')) < < < this work.

    but

    Select * from table (SplitFunction (select LOT_NO in the TRACER_SEARCH_SCHEDULE where JOB_ID = '36')) < < < do not work.

    Thank you for trying to help him. Thank you.

    Select * from table (SplitFunction (select LOT_NO in the TRACER_SEARCH_SCHEDULE where JOB_ID = '36'))< do="" not="">

    Try like this

    select * from table(select splitfunction(lot_no) from tracer_search_schedule where job_id='36')
    

    Just make sure that your subquery returns only 1 row.

Maybe you are looking for