Subselect query returns "invalid identifier", but the nested query return lines

I don't think it's a general SQL question.

Select * from persons where person_id in)

Select person_id with people whose name = 'Obama' - subquery

) and age > 18;

When I run the subquery, I get:

ORA-00904: "PERSON_ID": invalid identifier

00904, 00000 - '% s: invalid identifier '.

* Cause:

* Action:

Error on line: column 5: 8

This is because the table people do not have the person_id field.

But when I run the nested together query it returns all the lines in people with the AGE greater than 18.

How is he succeeds when the subquery is obviously wrong?

363f652b-263D-4418-933F-74a1d0a41b4c wrote:

I don't think it's a general SQL question.

Select * from persons where person_id in)

Select person_id with people whose name = 'Obama' - subquery

) and age > 18;

When I run the subquery, I get:

ORA-00904: "PERSON_ID": invalid identifier

00904, 00000 - '% s: invalid identifier '.

* Cause:

* Action:

Error on line: column 5: 8

This is because the table people do not have the person_id field.

But when I run the nested together query it returns all the lines in people with the AGE greater than 18.

How is he succeeds when the subquery is obviously wrong?

Yes - this is a general SQL question and ask often enough.

Correlated subqueries depend on the inner query, be able to see and access to the columns of the outer query. Normally see you referenced in the WHERE clause of the subquery and not in the SELECT clause, but the reference is valid in both places. This works because the columns of the tables in the main query are accessible in the subquery. "Person_id" is probably a column in the table 'people '.

Which can be a cause of problems 'odd' when the column (in your case "person_id") is more of a table.

Use an alias in the subquery in the subquery and you will find that it will not succeed.

See these two articles AskTom where he addresses this specific issue

http://asktom.Oracle.com/pls/Apex/f?p=100:11:0:P11_QUESTION_ID:3317493900346468494

http://asktom.Oracle.com/pls/Apex/f?p=100:11:0:P11_QUESTION_ID:155200640564

Tags: Database

Similar Questions

  • 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.

  • Get the error invalid identifier in the left outer join

    I wrote a query and get the invalid identifier error during execution:
    the exact error is: ORA-00904: "D". "" ACCT_NO ": invalid identifier
    This query is not able to access the parent table alias in the subquery of the left outer join.

    This is the query:
    SELECT D.PROD_DESC_TX, BASE. ASSET_NUM, BASE. PROD_ID, BASE.NAME
    OF TABLE1 D
    LEFT OUTER JOIN
    (
    SELECT ASSET_NUM, PROD_ID, B.SID
    FROM TABLE2 E
    JOIN IN-HOUSE TABLE3 HAS IT E.PROD_ID = A.ROW_ID
    JOIN INTERNAL TABLE 4 C ON A.PAR_PROD_INT_ID = C.ROW_ID
    INTERNAL TABLE5 JOIN B ON C.ROW_ID = B.PAR_ROW_ID
    AND B.TYPE = 'VALUE '.
    AND B.NAME = 'VALUE '.
    WHERE E.ASSET_NUM = ((CASE WHEN LTRIM (RTRIM (D.BANK_NO)) = '021 ' THEN '021' ELSE ' 020' END) |) LTRIM (RTRIM (D.APPL_CD)). LTRIM (RTRIM (D.ACCT_NO)))
    ) BASE ON ((CASE WHEN LTRIM (RTRIM (D.BANK_NO)) = '021 ' THEN '021' ELSE ' 020' END) |) LTRIM (RTRIM (D.APPL_CD)). LTRIM (RTRIM (D.ACCT_NO))) = BASE. ASSET_NUM
    WHERE D.BANK_NO = 'VALUE '.
    AND D.APPL_CD = 'VALUE '.
    AND D.ACCT_NO = 'VALUE '.

    Edited by: user648525 13 Sep, 2011 01:21

    I can easily look at your request at this time (using my iPhone on a train).

    But trying out this line in the WHERE (the one with the invalid reference) clause in the main query.

    Who is... in the view of inline, use only the logic of the join (the clauses).

    Overflow the filtering logic (WHERE clause) to the main request. You may need to select some additional inline view columns to make these references work.

  • Invalid identifier in the procedure

    Hi all

    I have an example of how I'm trying to pass two arguments.

    Unfortunately, when I do that, I get the below error:
    ORA-00904: "V_END_DATE": invalid identifier
    ORA-06512: at "PROCEXAMPLE", line 10
    ORA-06512: at line 2

    Before I remove the rest of my hair, is - it possible to let me know what goes wrong? I know what means the error but I don't see where I have, I got an invalid identifier. Even on line 10. : P


    ARGUMENTS TO PASS TO THE PROCEDURE
    BEGIN
        procExample (   p_start_date => '01/01/2011', 
                            p_end_date => '07/01/2011') ;
    END  
    ;
    PROCEDURE
    {
    CREATE OR REPLACE PROCEDURE procExample (p_start_date in varchar2, p_end_date in varchar2) is
    date of v_start_date;
    date of v_end_date;

    Start
    v_start_date: = to_date(p_start_date,'dd/mm/yyyy');
    v_end_date: = to_date(p_end_date,'dd/mm/yyyy');

    EXECUTE IMMEDIATE ' CREATE TABLE test_a AS
    SELECT v_start_date, v_end_date FROM DUAL';
    end procExample;
    }

    Hello

    When you use EXECUTE IMMEDIATE, you pass a string to the database must be executed in the database engine, where nothing is known about local variables in your procedure, such as v_start_date. There are ways to pass variables in an EXECUTE IMMEDIATE statement, but not in the context of the deifinitions column. About the closest thing you can do is:

    CREATE OR REPLACE PROCEDURE procExample ( p_start_date IN VARCHAR2
                                            , p_end_date   IN VARCHAR2
                             )
    IS
        sql_txt         VARCHAR2 (500);
    begin
        sql_txt := 'CREATE TABLE test_a '
                 || 'AS '
             || 'SELECT  TO_DATE (''' || p_start_date || ''', ''dd/mm/yyyy'') AS dt_1 '
             || ',       TO_DATE (''' || p_end_date   || ''', ''dd/mm/yyyy'') AS dt_2 '
             || 'FROM     dual';
    
        dbms_output.put_line (sql_txt || ' = sql_txt');     -- For debugging
    
        EXECUTE IMMEDIATE sql_txt;
    end procExample;
    /
    SHOW ERRORS
    

    Creating tables in procedures is not usually a good idea. Why do you need to do this in PL/SQL?

    Since you know that the columns are DATEs, you can simply create the table with two columns DATE and not use CREATE TABLE As. It would be less prone, although you would need to separate INSERT statements.
    Don't forget to provide names for the columns.

    Whenever you write dynamic SQL code, it is a good idea to put all the text in a variable, so that you can view before you run, for debugging purposes. After the test is finished, you can comment or remove the call to dbms_output.put_line.

  • Outgoing e-mail constantly is rejected Server Error # 0x800CCC779, 550 response from Server (invalid address) but the address is valid!

    I sent 4 emails from people I know and 3 had sent, but not the fourth.  I had an attachment (YouTube video).  Read the error message:

    Has been rejected by e-mail * address email is removed from the privacy *, subject: ' Chirichaua travel, account: pop.west.cox.net; Server: smtp.west.cox.net, SMTP Protocol; 550 server response invalid 5.5.0, address, Port 25, secure (SSL) Server Error 0x800CCC79 #.

    2 / 3 completed tasks

    I'm not a technical type of person (at all) and hope that your answer tells me exactly how to solve this problem.  Thank you!!!

    Eileen BK

    You are the very welcome. Happy, I was able to help.
     
     
  • ORA-00904 invalid identifier with the insert command

    Please inform me of what's wrong with insert.




    Declare
    cursor c1 is
    Select column_name as Column_namee, data type data_type, data_length as datalen ALL_TAB_COLUMNS where table_name = upper('ALI');
    temp_col_names varchar2 (1000);

    BEGIN
    for j in loop c1

    temp_col_names: = temp_col_names | j.column_namee | «, » ;

    end loop;
    Select substr (temp_col_names, 0, length (temp_col_names)-1) in the double temp_col_names;

    dbms_output.put_line (temp_col_names);

    INSERT INTO temp_col_names (temp_col_names) SELECT id WHERE Ali ali2 = 4;


    END;

    This means that there is no temp_col_names of the column in the table ALI2. Looks like you are the dynamic SQL search - you want to insert all the table columns ALI in the same set of columns in table ALI2, right? Then use:

    EXECUTE IMMEDIATE ' INSERT INTO ali2 (' | temp_col_names |) ') SELECT ' | temp_col_names | "Ali WHERE id = 4';

    SY.

  • ODI: Error invalid identifiers in "insert stream I$ table. '

    Hello

    I am trying to write a temporary interface (yellow), which will act as a source for a standard interface (in blue).

    However when I run the standard interface, I get the error on step 8 - integration: Insert flow I$ table

    ODI-1228: CR_2 (integration) task fails on the connection target ORACLE ORACLE_Local.

    Caused by: java.sql.SQLSyntaxErrorException: ORA-00904: "T". "" R_id ": invalid identifier

    The target code:

    / * DETECTION_STRATEGY = NOT_EXISTS * /.

    Insert / * + append * / in THE_SCHEMA. I _CR_TABLE $

    (

    CNUMBER,

    R_ID,

    IND_UPDATE

    )

    Select

    CNUMBER,

    R_ID,

    IND_UPDATE

    de)

    Select

    C1_CNUMBER CNUMBER,

    C2_R_ID R_ID,

    'I' IND_UPDATE

    of THE_SCHEMA. C$ _0CR_TABLE

    where (1 = 1)

    ) S

    If NOT EXISTS

    (select 1 from THE_SCHEMA. CR_TABLE T

    where T.R_ID = S.R_ID

    and ((T.CNUMBER = S.CNUMBER) or (T.CNUMBER IS NULL and S.CNUMBER IS NULL))

    )

    Source : DB2 v9.1.0.7,.

    Target : database Oracle 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production

    ODI v11.1.1

    On the standard interface:

    I set the box "use the temporary interface as an underlying table (subselect).

    R_ID field on the target table is the key field. It is mapped to one of the fields in the interface of temp and it the value "run on: Source" with set of Insert and Update check boxes.

    I use SQL LKM for Oracle components to get the data from the interface of the target temp.

    On the interface of temp:

    No key for each field in the target field

    IKM DB2 using updated incremental, FLOW_CONTROL with STATIC_CONTROL set to false.

    Any help would be greatly appreciated!

    In the target database, I changed the name of the field R_ID... but I forgot to update this column in the ODI of the table model. Once I have updated the model and mappings, the interface ran as expected.

  • PL/SQL: ORA-00904: invalid identifier (DG4ODBC 11.2.0.2 & MySQL)

    I have a PL/SQL script, processing of information between Oracle and MySQL databases. My script runs perfectly with DG4ODBC 11.1.0.7. Then we went from Oracle 10.2.0 and 11.2.0.2 DG4ODBC. Now, if I run my script from command line Solaris love. / myscript.shl, I get the following errors:

    PL/SQL: ORA-00904: "cmswhit_moodle1." "" "" mdl_grade_grades "." finalgrade ": invalid identifier.

    PL/SQL: ORA-00904: "cmswhit_moodle1." "" "" mdl_question_states '. "the attempt": invalid identifier "

    The strange thing is that if I run the same query by cut and paste in sqlplus command line, the application works perfectly without any problems.

    What is the cause of this problem?

    Any help would be greatly appreciated.

    Jeffrey

    Hi Klaus,

    The problem has been resolved after I upgraded MySQL ODBC to a new version of 5.1.8 to 5.1.13.

    Summary of the problem and its solution:

    The problem: It seems that dg4odbc 11.2.0.2 requires a newer version of MyODBC. Previously, I used MyODBC 5.1.8, which ran into problems with dg4odbc 11.20.0.2.

    The Solution: After that I upgraded 5.1.13 MyODBC, my PL/SQL scripts all work.

    I need to point out that with that MyODBC 5.1.8, I can run queries and updates to SQL * more console, but now the PL/SQL scripts.

    I'm going to close this message.

    Once again, thank you and happy holidays.

    Jeffrey

  • That could leave gaps in the index, but the built-in function NEXT allows you to iterate over any series of clues.

    Hello

    can you please explain the below topic?

    That could leave gaps in the index, but the built-in function NEXT allows you to iterate over any series of clues. -> this line

    1. Arrays have a fixed upper bound, but the nested tables are unlimited (see Figure 5-1). Thus, the size of a nested table can increase dynamically.

    Table in figure 5-1 against the nested Table

    Text description of pls81016_array_versus_nested_table.gif follows
    Description of the illustration pls81016_array_versus_nested_table.gif

    • Tables should be dense (have consecutive indices). So, you can delete individual items from a table. Initially, the nested tables are dense, but they can become sparse (have non-consecutive indexes). So, you can remove items from a table nested by using the integrated procedure DELETE . That could leave gaps in the index, but the built-in function NEXT allows you to iterate over any series of indexes.

    Hello

    Look at the second half of the Figure 5-1, the 'Nested Table after destruction".  X (9), x.5 and x (2) elements have been removed, so the index values are 1, 3, 4, 6, 7, 8 and 10.  There is a gap between 1 and 3, another gap between 4 and 6 and another gap between 8 and 10.

    You could not use a simple FOR loop:

    FOR j IN 1... 10

    LOOP

    ...

    END LOOP;

    to iterate over a collection of rare as this, but you can use a loop where you get with the FOLLOWING indices:

    j: = x.FIRST;

    Then j IS NOT NULL

    LOOP

    ...

    j: = (j) x.NEXT;

    END LOOP;

  • ORA-01017: name of user and password invalid when using the TNS Alias

    Friends,

    I have this strange problem in 11 G R2. When I use tnsalias and connect using sqlplus username/password@TNS it shows ORA-01017: name of user and password invalid. But the same works with ORACLE_SID. See below.
    -bash-3.00$ uname -a
    SunOS ibs-ash-sr147 5.10 Generic_144489-06 i86pc i386 i86pc
    -bash-3.00$ env | grep ORACLE
    ORACLE_SID=DB1
    ORACLE_BASE=/project/oracle/orabase
    ORACLE_HOME=/project/oracle/orabase/product/11.2.0/dbhome_1
    -bash-3.00$ tnsping DB
    
    TNS Ping Utility for Solaris: Version 11.2.0.1.0 - Production on 17-JUN-2011 12:23:12
    
    Copyright (c) 1997, 2009, Oracle.  All rights reserved.
    
    Used parameter files:
    /project/oracle/orabase/product/11.2.0/dbhome_1/network/admin/sqlnet.ora
    
    
    Used TNSNAMES adapter to resolve the alias
    Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = crs-scan)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = DB)))
    OK (0 msec)
    -bash-3.00$ sqlplus IRES_USER@DB
    
    SQL*Plus: Release 11.2.0.1.0 Production on Fri Jun 17 12:30:22 2011
    
    Copyright (c) 1982, 2009, Oracle.  All rights reserved.
    
    Enter password:
    
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
    Data Mining and Real Application Testing options
    
    SQL> show parameter sec_case_sensitive_logon
    
    NAME                                 TYPE        VALUE
    ------------------------------------ ----------- ------------------------------
    sec_case_sensitive_logon             boolean     TRUE
    
    Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
    Data Mining and Real Application Testing options
    -bash-3.00$ sqlplus IRES_USER/U9$bvs#ir@DB
    
    SQL*Plus: Release 11.2.0.1.0 Production on Fri Jun 17 12:34:30 2011
    
    Copyright (c) 1982, 2009, Oracle.  All rights reserved.
    
    ERROR:
    ORA-01017: invalid username/password; logon denied
    
    
    Enter user-name: ^C
    My understanding is that both connections use a TNS alias, but then does not work. Any help is appreciated.

    Thanks in advance,
    SSN

    Published by: SSNair on June 17, 2011 05:43

    After sqlplus apostrophes and try

    http://download.Oracle.com/docs/CD/B28359_01/server.111/b28320/initparams211.htm

  • problem with update of the repository into account line

    Hello..

    I could not update the number of lines in the obiee administration tool while working online.
    I practice the document

    http://www.Oracle.com/technology/OBE/obe_bi/bi_ee_1013/bi_admin/biadmin.html

    I skipped the step
    and I tried following step

    Create a new measure

    right now I tried click on results.

    im getting error


    ODBC driver returned an error (SQLExecDirectW).

    Error codes: OPR4ONWY:U9IM8TAC:OI2DL65P
    State: HY000. Code: 10058. NQODBC SOL_STATE: HY000 nQSError: 10058 a general error has occurred. nQSError: Oracle 17001: 904 error code, message: ORA-00904: "T168 '. "" CHANNEL_ID ": invalid identifier in the OIC call OCIStmtExecute. nQSError: 17010 prepare the SQL statement failed. (HY000)
    SQL issued: SELECT time. "" Calendar year "saw_0"sales facts. " "" Amount sold "saw_1"sales facts. " "" Unit cost "OF SH ORDER BY saw_0 saw_2



    Thank you

    The error indicates, column "CHANNEL_ID" undetected in DB...

    Try to overlap the DB for this column

    Kind regards
    Rambeau

  • Cursor of return of (nested) function - PLS-00201: identifier of the CURSOR must be declared

    Hello

    I have a function in which I use nested functions (because I don't want to create objects explicit / external, it is a requirement that I don't have any effect on / I don't want to change).

    In my external function, I use cursor by declaring them in IS-section and then open using the loop for instruction.

    In my inner function / nested, I also want to use a cursor.

    There I also said one like I did in an external function within the section IS of the nested function.

    SQL Developer complains about syntax error (';: wait ").

    When you try to compile the whole process I get the following error:

    "Error (97,14): PLS-00201: identifier 'CURSOR' must be declared '.

    It's my external function starts as:

    CREATE OR REPLACE FUNCTION FN_GENERATE_QUERY_PMT (instance_id_in IN NUMBER, language_in IN VARCHAR2)
    RETURN CLOB
    IS
         CURSOR c_outer IS
          SELECT * FROM BLA;
    

    When it comes to my internal function with the section IS of the external function and stands (inner functions should be at the end of the Section IS to stand behind the statements of variable and cursor, otherwise there will be an error):

    FUNCTION nfn_get_value (num_in IN NUMBER)
          RETURN SYS_REFCURSOR
        IS
          SYS_REFCURSOR c_inner IS
          SELECT *
          FROM BLUB;
        BEGIN
          RETURN c_where_in;
        END;
    

    After that there will be another nested function, then the BEGIN section will appear.

    When looking for 'function returns cursor' I can only find solutions where the cursor is declared in section IS (sometimes its an AS-section o_O * worried *) but wihtoug select, just declare type.

    The cursor focus is added in the Begin block to the way open for instruction. But I don't want to open it yet. I want to open the cursor using the loop statement. I am able to reopen? used can it be two sliders while one will not be closed properly?

    How to fix to return a cursor that I can use in my external function.

    Advice would be appreciated.

    Thanks in advance.

    Maybe I got the soultion
    First of all, I found this thread:

    http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:5241391331097

    said the following:

    2) a ref cursor is just a cursor.  a ref cursor is just a cursor.  a ref cursor is just a cursor.... (keep saying it over and over
    

    But fortuneately I also found this post:
    http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:14188501024541

    where thankfully someone shared her knowledge with others:

    In view of this block of code - you may see more "prominent" unlike - any

    How many times you run this block - cursor C will always be select * twice.  The ref

    cursor is not guaranteed.

    Another difference is that a ref cursor can be returned to a client.  a plsql 'cursor cursor.

    cannot be returned to a client.

    Another difference is a cursor can be global - a ref cursor cannot (you cannot set

    them outside a procedure / function)

    Another difference is a ref cursor can be passed to the subroutine - a subroutine

    cursor cannot be.

    This explains why the samples seem always fair with open (Ref) cursor within the section to START.

    I expeceted this (as I wrote in the first post) and ask if the course of opening will be sent back twice or just redirect. I suppose it it reassigns who were just a little in performance.

    But I can't yet find this good explanation of this type anywhere within the documentation and of course I didn't read it all. Shame on me, but I'm always engaged by internet download.

    I would be grateful if someone could say my last statement and leave a comment on double-distribution of the refcursors has reopened.

    Thanks in advance.

  • -You also get an invalid identifier error when executing this query sql for a data model, but not in TOAD/SQL Developer?

    Hello OTN.

    I don't understand why my sql query will pass by in the data model of the BI Publisher. I created a new data model, chose the data source and type of Standard SQL = SQL. I tried several databases and all the same error in BI Publisher, but the application works well in TOAD / SQL Developer. So, I think it might be something with my case so I'm tender hand to you to try and let me know if you get the same result as me.

    The query is:

    SELECT to_char (to_date ('15-' |)) TO_CHAR(:P_MONTH) | » -'|| (To_char(:P_YEAR), "YYYY-DD-MONTH") - 90, "YYYYMM") as yrmth FROM DUAL


    Values of the variable:

    : P_MONTH = APRIL

    : P_YEAR = 2015

    I tried multiple variations and not had much luck. Here are the other options I've tried:

    WITH DATES AS

    (

    Select TO_NUMBER (decode (: P_MONTH, 'JANUARY', '01',))

    'FEBRUARY', '02',.

    'MARCH', '03'.

    'APRIL', '04'

    'MAY', '05'.

    'JUNE', '06'.

    'JULY', '07',.

    'AUGUST', '08'.

    'SEPTEMBER', '09'.

    'OCTOBER', '10',.

    'NOVEMBER', '11'.

    "DECEMBER", "12."

    '01')) as mth_nbr

    of the double

    )

    SELECT to_char (to_date ('15-' |)) MTH_NBR | » -'|| (TO_CHAR(:P_YEAR), 'DD-MM-YYYY') - 90, "YYYYMM")

    OF DATES

    SELECT to_char (to_date ('15-' |: P_MONTH |)) » -'|| ((: P_YEAR, 'MONTH-DD-YYYY')-90, "YYYYMM") as yrmth FROM DUAL

    I'm running out of ideas and I don't know why it does not work. If anyone has any suggestions or ideas, please let me know. I always mark answers correct and useful in my thread and I appreciate all your help.

    Best regards

    -Konrad

    So I thought to it. It seems that there is a bug/lag between the guest screen that appears when you enter SQL in the data model and parameter values, to at model/value data.

    Here's how I solved my problem.

    I have created a new data model and first created all my settings required in the data model (including the default values without quotes, i.e. APRIL instead "Of APRIL") and then saved.

    Then I stuck my sql query in the data model and when I clicked ok, I entered my string values in the message box with single quotes (i.e. "in APRIL' instead of APRIL)

    After entering the values of string with single quotes in the dialog box, I was able to retrieve the columns in the data model and save.

    In the data tab, is no longer, I had to enter the values in single quotes, but entered values normally instead, and the code worked.

    It seems the box prompted to bind the values of the variables when the SQL text in a data model expects strings to be wrapped in single quotes, but no where else. It's a big headache for me, but I'm glad that I solved it, and I hope this can be of help to other institutions.

    See you soon.

  • nested subquery / invalid identifier

    I need to create a SQL report quite complex, and I encountered the following problem. Imagine two simple tables - say table_a table_b:
    create table table_a (id integer, primary key (id));
    
    create table table_b (id integer, a_id integer references table_a(id), primary key (id)); 
    Say that I need to run a query which (a) selects all lines from table_a and (b) all related table_b lines. It's something like that
    SELECT a.*,
        (SELECT COUNT(*) FROM table_b WHERE a_id = a.id) AS cnt
    FROM table_a a
    It works fine, but I need to do more complex operations on table_b (CONNECT BY, etc.) so I need nest the Subselects and move the "allocation a_id = a.id" condition "deeper" - something like this:
    SELECT a.*,
        (SELECT COUNT(*) FROM
            (SELECT * FROM table_b WHERE a_id = a.id)
        ) AS cnt
    FROM table_a a
    Again - this is just a simplified example, I need to perform more complex processing.

    But it turns out that it returns "ORA-00904: invalid identifier" suddenly, exception, as Oracle does not have the "a.id' in the query more. How to solve this problem? How to convince Oracle to use the value of the outer query?

    Published by: TomasVondra on 24.11.2009 03:26

    Correlation query down 1 level. You have a buggy version, I guess!

    http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:1853075500346799932

  • Pivot gives invalid identifier query

    I am trying to create my first pivot query. I have two tables:

    CREATE TABLE "SKIP"."ORDERS"    
    (
      "CATG" VARCHAR2(30),
       "PART_NR" VARCHAR2(30),
       "PART_REV" VARCHAR2(30),
       "CUST_ID" NUMBER,
       "ORDER_DT" DATE )
    ;
    
    
    CREATE TABLE "SKIP"."CUSTOMERS"    
    (
      "STATE" VARCHAR2(30),
       "CUST_ID" NUMBER    )
    ;
    
    

    I want to create a PivotTable with years above and some of the numbers on the side. I had a problem from the beginning when I tried it. It seems that you can't use a function on the clause, which forbids me to use

    PIVOT (COUNT (PART_NR) to extract (year of the ORDERS.) ORDER_DT))

    I don't remember the exact error, he gave me, but I found a "possible solution" with the query nested that I have below

    SELECT * FROM
    (SELECT PART_NR, YR FROM (
      (SELECT ORDERS.CATG || '-' || ORDERS.PART_NR || ORDERS.PART_REV AS PART_NR, extract (year from ORDERS.ORDER_DT) AS "YR"
      FROM ORDERS, CUSTOMERS
      where
      CUSTOMERS.STATE = "VA"
      and 
      ORDERS.CUST_ID = CUSTOMERS.CUST_ID
      )
    )
    PIVOT (COUNT(PART_NR) FOR YR IN (
      2002,
      2003,
      2004,
      2005,
      2006,
      2007,
      2008,
      2009,
      2010,
      2011,
      2012,
      2013
      )
    )
    )
    ORDER BY PART_NR
    

    But now, I get an error: 'Year': invalid identifier

    I tested the two nested queries (beginning with SELECT PART_NR, YR OF) and who did indeed get the two columns PART_NR and year, so the problem must be in the PIVOT.

    Any ideas?

    Hello

    You probably mean COUNT (*) instead of COUNT (part_nr) and use SELECT * in the subquery, which is the PIVOT.

    There is a column called GOING? If this isn't the case, you probably want to single quotes, not double - quote, in line 6.

    2 external queries can be combined; You can make an ORDER BY in the query even as PIVOT.

    If I had copies of sample size of your tables, and the results you wanted Sinc sample data, then I could test and show you exactly.

    Whenever you have a problem, please post a small example data (CREATE TABLE and only relevant columns, INSERT statements) of all the tables involved, so that people who want to help you can recreate the problem and test their ideas.

    Also post the results you want from this data, as well as an explanation of how you get these results from these data, with specific examples.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002

Maybe you are looking for