ora-00904

Oracle subquery does not see the variable from the outer block 2 levels up

瘦欲@ 提交于 2019-11-29 00:05:54
问题 I'd like to get in one query a post and the first comment associated with the post. Here is how I do it in PostgreSQL: SELECT p.post_id, (select * from (select comment_body from comments where post_id = p.post_id order by created_date asc) where rownum=1 ) the_first_comment FROM posts p and it works fine. However, in Oracle I'm getting an error ORA-00904 p.post_id: invalid identifier. It seems to work fine for one subselect, but I cannot get the comment with only one due to the fact that I

How to use Alias in Where clause?

若如初见. 提交于 2019-11-28 08:54:11
问题 I have this procedure: PROCEDURE P_LOAD_EXPIRED_ACCOUNT ( pDayDiff IN NUMBER, ExpiredCur OUT MEGAGREEN_CUR ) IS BEGIN OPEN ExpiredCur FOR SELECT ACCOUNT_NAME, SERVICE_TYPE, CASE WHEN SERVICE_TYPE = 1 THEN ADD_MONTHS(ACTIVATED_DATE,3) WHEN SERVICE_TYPE = 2 THEN ADD_MONTHS(ACTIVATED_DATE,6) WHEN SERVICE_TYPE = 3 THEN ADD_MONTHS(ACTIVATED_DATE,12) END AS EXPIRED_DATE FROM SUBSCRIBERS WHERE (EXPIRED_DATE - CURRENT_DATE) < pDayDiff; END; but SQL Developer generate this error: Error(20,10): PL/SQL:

How to use BOOLEAN type in SELECT statement

被刻印的时光 ゝ 提交于 2019-11-27 00:50:11
I have a PL/SQL function with BOOLEAN in parameter: function get_something(name in varchar2, ignore_notfound in boolean); This function is a part of 3rd party tool, I cannot change this. I would like to use this function inside a SELECT statement like this: select get_something('NAME', TRUE) from dual; This does not work, I get this exception: ORA-00904: "TRUE": invalid identifier As I understand it, keyword TRUE is not recognized. How can I make this work? You can build a wrapper function like this: function get_something(name in varchar2, ignore_notfound in varchar2) return varchar2 is begin

Is it possible to query a comma separated column for a specific value?

[亡魂溺海] 提交于 2019-11-26 17:58:07
I have (and don't own, so I can't change) a table with a layout similar to this. ID | CATEGORIES --------------- 1 | c1 2 | c2,c3 3 | c3,c2 4 | c3 5 | c4,c8,c5,c100 I need to return the rows that contain a specific category id. I starting by writing the queries with LIKE statements, because the values can be anywhere in the string SELECT id FROM table WHERE categories LIKE '%c2%'; Would return rows 2 and 3 SELECT id FROM table WHERE categories LIKE '%c3%' and categories LIKE '%c2%'; Would again get me rows 2 and 3, but not row 4 SELECT id FROM table WHERE categories LIKE '%c3%' or categories

Using &#39;case expression column&#39; in where clause

一曲冷凌霜 提交于 2019-11-26 14:37:40
SELECT ename , job , CASE deptno WHEN 10 THEN 'ACCOUNTS' WHEN 20 THEN 'SALES' ELSE 'UNKNOWN' END AS department FROM emp /* !!! */ WHERE department = 'SALES' This fails: ORA-00904: "%s: invalid identifier" Is there a way to overcome this limitation in Oracle 10.2 SQL ? How to use the 'case expression column' in where clause ? ypercubeᵀᴹ The reason for this error is that SQL SELECT statements are logically * processed in the following order: FROM : selection of one table or many JOINed ones and all rows combinations that match the ON conditions. WHERE : conditions are evaluated and rows that do

How to use BOOLEAN type in SELECT statement

自古美人都是妖i 提交于 2019-11-26 09:28:12
问题 I have a PL/SQL function with BOOLEAN in parameter: function get_something(name in varchar2, ignore_notfound in boolean); This function is a part of 3rd party tool, I cannot change this. I would like to use this function inside a SELECT statement like this: select get_something(\'NAME\', TRUE) from dual; This does not work, I get this exception: ORA-00904: \"TRUE\": invalid identifier As I understand it, keyword TRUE is not recognized. How can I make this work? 回答1: You can build a wrapper

Using &#39;case expression column&#39; in where clause

情到浓时终转凉″ 提交于 2019-11-26 08:53:19
问题 SELECT ename , job , CASE deptno WHEN 10 THEN \'ACCOUNTS\' WHEN 20 THEN \'SALES\' ELSE \'UNKNOWN\' END AS department FROM emp /* !!! */ WHERE department = \'SALES\' This fails: ORA-00904: \"%s: invalid identifier\" Is there a way to overcome this limitation in Oracle 10.2 SQL ? How to use the \'case expression column\' in where clause ? 回答1: The reason for this error is that SQL SELECT statements are logically * processed in the following order: FROM : selection of one table or many JOINed

ORA-00904: invalid identifier

笑着哭i 提交于 2019-11-26 01:38:00
问题 I tried to write the following inner join query using an Oracle database: SELECT Employee.EMPLID as EmpID, Employee.FIRST_NAME AS Name, Team.DEPARTMENT_CODE AS TeamID, Team.Department_Name AS teamname FROM PS_TBL_EMPLOYEE_DETAILS Employee INNER JOIN PS_TBL_DEPARTMENT_DETAILS Team ON Team.DEPARTMENT_CODE = Employee.DEPTID That gives the below error: INNER JOIN PS_TBL_DEPARTMENT_DETAILS Team ON Team.DEPARTMENT_CODE = Employee.DEPTID * ERROR at line 4: ORA-00904: \"TEAM\".\"DEPARTMENT_CODE\":

Using an Alias in a WHERE clause

此生再无相见时 提交于 2019-11-26 01:16:10
问题 I have a query which is meant to show me any rows in table A which have not been updated recently enough. (Each row should be updated within 2 months after \"month_no\".): SELECT A.identifier , A.name , TO_NUMBER(DECODE( A.month_no , 1, 200803 , 2, 200804 , 3, 200805 , 4, 200806 , 5, 200807 , 6, 200808 , 7, 200809 , 8, 200810 , 9, 200811 , 10, 200812 , 11, 200701 , 12, 200702 , NULL)) as MONTH_NO , TO_NUMBER(TO_CHAR(B.last_update_date, \'YYYYMM\')) as UPD_DATE FROM table_a A , table_b B WHERE