oracle11g

Transpose a query output

笑着哭i 提交于 2019-12-12 02:53:36
问题 I have a normal select query which results following output. select cid,x1,x2,x3,x4,fy from temp_table; cid x1 x2 x3 x4 fy ---------------------------- 6657 100 0 0 200 2014 6658 300 0 0 400 2015 6659 500 0 0 600 2016 I want it to rewrite it print following output. 2014 2015 2016 ------------------------- x1 100 300 500 x2 0 0 0 x3 0 0 0 x4 200 400 600 How can this be achieved? 回答1: Here is a way to do this with just subqueries and aggregation: select name, sum(case when fy = 2014 then x end)

Unpivot on view is not working in Oracle

妖精的绣舞 提交于 2019-12-12 02:49:31
问题 I have the below query select distinct cd, nm, case when parent=cd then 0 else parent end as parent, lvl from ( select * from mytable unpivot ( (cd, nm, parent) for lvl in ((CD_1, NM_1, CD_1) as 1,(CD_2, NM_2, CD_1) as 2,(CD_3, NM_3, CD_2) as 3,(CD_4, NM_4, CD_3) as 4, (CD_5, NM_5, CD_4) as 5) ) ) order by lvl; If mytable is a table this is working fine. Basically my source is a view , if replace the mytable with my view its throwing an error ORA-00933 : SQL command not properly ended. Any

Trivial PL/SQL block generating frustrating PLS-00103 error

只谈情不闲聊 提交于 2019-12-12 02:43:53
问题 I may be going a bit insane, but I keep getting a PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following... error. I have pared my program down to the following: BEGIN NULL; END; / Which I am running within AquaData Studio. This produces: [Error] Script lines 1-2 ... ORA-06550: line 2, column 8: PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following...; Script line 2, statement line 2, column 8 I write a decent amount of PL/SQL and

could not load library for oracle_fdw

岁酱吖の 提交于 2019-12-12 02:42:50
问题 I am facing issue while creating oracle_fdw. I have copied oracle_fdw.dll to postgres lib folder * both .sql file and control file to shrared/extension now when I connect to psql with superadmin user & make an query create extension oracle_fdw; I am getting response ERROR: could not load library "D:/postgresdb/lib/oracle_fdw.dll": The specified procedure could not be found. 回答1: From the error it seems that the oracle_fdw library is not available in the lib folder of postGreSQL installation

SQL: Exception to an otherwise sorted result set

冷暖自知 提交于 2019-12-12 02:34:51
问题 Using Oracle 11g I want a single exception to an otherwise sorted table select fruit as popluar_choices from menu order by fruit /* Exception put 'grapefruit' at top of list */ Desired Result popular_choices ----------- grapefruit apple fig kiwi lemon pear It's similar to this post: How to apply non standard SQL column sort order? 回答1: select fruit as popluar_choices from menu order by case fruit when 'grapefruit' then 0 else 1 end, fruit 回答2: SELECT fruit AS popular_choices FROM menu ORDER

ORA-00934: Group function not allowed here || Selecting MIN(Salary) of highest paid dept

微笑、不失礼 提交于 2019-12-12 02:29:31
问题 O community, do you know how I could select the department_ID, and lowest salary of the department with the highest average salary? Or how to eliminate the'ORA-00934: group function not allowed here' issue? Would I need to use two subqueries? So far, this is what I've come up with, trying to get the department_ID of the highest paid department: SELECT department_ID, MIN(salary FROM employees WHERE department_ID = (SELECT department_ID FROM employees WHERE salary = MAX(salary)); Thank you,

Oracle sql query needs to change based on timezone

爱⌒轻易说出口 提交于 2019-12-12 02:17:51
问题 I have a sql query to obtainrecords for a date range. My query works find byut when I analyzed data, I found that the records are retirved base don GMT timezone value, thus making the restults incorrect. I get my time from a unix epoch value in database. SELECT tableA.columnA,tableB.columnB FROM tableA INNER JOIN tableB ON tableA.aId = tableB.aId WHERE (to_date('1970-01-01 00:00:00 +10:00','yyyy-MM-dd hh24:mi:ss') + (tableB.epochValue/60/60/24/1000)) > to_date('--FROM_DATE--', 'yyyy-MM-dd

ORA-00904 Invalid Identifier. Query works in 12c but not in 11g

自闭症网瘾萝莉.ら 提交于 2019-12-12 02:14:56
问题 I have a LINQ query, trying to execute it on oracle 11g. The same query executes perfectly fine on 12c but it gives following error on 11g. ORA-00904: "Extent1"."ID": invalid identifier 00904. 00000 - "%s: invalid identifier" *Cause: *Action: Following is the generated SQL. Just showing the specific part of query which is giving error, SELECT "Extent1".ID, ( SELECT "top".ADMIT_DATE FROM ( SELECT "Project7".ADMIT_DATE FROM ( SELECT "Extent7".ADMIT_DATE FROM SYS.Table2 "Extent7" WHERE "Extent1"

Cannot connect my RDS Oracle instance to a PHP server

蓝咒 提交于 2019-12-12 01:57:02
问题 I have an Oracle database set up on Amazon RDS and am trying to connect to it in PHP. I am fairly sure my connection string is correct because I connected using sqlplus and am able to retrieve data. The server is an Amazon Linux server, however I have also tried to connect using a different server and get the error: Is there any more set up that I need to do in either the server or the database server, I have just started using AWS and am not sure if anything else needs to be done. ORA-12154:

ORA-00911: Invalid Character via ODBC, Adhoc SQL - within comments?

点点圈 提交于 2019-12-12 01:56:14
问题 When executing the following statement (as an example) I get an error ORA-00911: Invalid character "/* it is the end of the world */\nSELECT 1 FROM MyTable;" Other comments are fine. What's the problem? We use comments to annotate our Ad-Hoc SQL. (Oracle11gR2, Windows ) This does not happen via SQL Plus or SQL Developer. 回答1: If a comment includes the whole word end then the Oracle driver (or server) appears to be interpreting this badly. If you remove the end word within the comment, the