SQL question: horizontally to group by
HelloI have a problem to find a way to display the result of a join table. Can someone please help?
SQL > select * from tab1;
GNAME SNO
---------- ----------
ABC 5
DEF 2
ABC 3
SQL > select * from tab2.
GNAME SNO
---------- ----------
ABC 10
XYZ 5
DEF 15
My output using a UNION ALL operation current:
SQL > select gname, sno1 count (*) Group of tab1 by gname
2 Union all the
3 select gname, sno2 count (*) of the tab2 group by gname.
SNO1 GNAME
---------- ----------
ABC 2
DEF 1
ABC 1
DEF 1
XYZ 1
The output I expect:
GNAME SNO1 SNO2
---------- ---------- ----------
1 2 ABC
1 1 DEF
0 1 XYZ
Thanks in advance.
Way the easiest would be to encapsulate a slightly modified version of your query in an external as query:
select gname, sum(sno1) sno1, sum(sno2) sno2
from (select gname, count(*) sno1 0 sno2
from tab1
group by gname
union all
select gname, 0 sno1, count(*) sno2
from tab2
group by gname);
John
Tags: Database
Similar Questions
-
Is there a limitation of length of sql in a record group?
Record group contains 4 by union funcion sql statement. When this sql statement longer than 4000 characters then the record group do not allow me to add an additional column to another.
My question is, is there a limitation of length of sql that record the group support?
Developer 10g suit.
Thanks in advance.
As you have discovered that there is a limit in the form designer, on what size the SQL statement may be in the property Query Group Record in your record group. Unfortunately, the forms for the Query Group property help topic Record does not that there is a limit or the limit.
If your request does not fit into the Group Record Query property, you can try to use the integrated Create_Group_From_Query() to fill in your group. Another option would be to create views in your database, and then select the view in the Query property group Record.
If you opt to try the method of Create_Group_From_Query(), just set your Group Record in the navigation of the object by using a SELECT statement (your column names) twice and then programmatically remove the Group and re-create it with the high - Create_Group_From_Query (). See the help topic for the function integrated for a code example.
Craig...
-
Hi all I have a basic sql question
Watch below two querries
I think as operator will not compare with all the values, but not the outcome it will compare with all values... When comparing with the value null, the result is automatically null1. select 1 from dual where 1 in (select 1 from dual union all select null from dual) It gives output as 1 but below one 2. select 1 from dual where 1 not in (select 2 from dual union all select null from dual) It gives output as no data found
I'm wrong
Please help me on this
and why performance wise in operator is more better than no of?
Thanks to all in advanceThanks for posting your explain plan command
Execution Plan ---------------------------------------------------------- Plan hash value: 3249215828 ----------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ----------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 2 | 6 | 4 (0)| 00:00:01 | | 1 | NESTED LOOPS | | 2 | 6 | 4 (0)| 00:00:01 | | 2 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 | | 3 | VIEW | VW_NSO_1 | 2 | 6 | 2 (0)| 00:00:01 | | 4 | SORT UNIQUE | | 2 | | 2 (0)| 00:00:01 | | 5 | UNION-ALL | | | | | | | 6 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 | |* 7 | FILTER | | | | | | | 8 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 | ----------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 7 - filter(NULL IS NOT NULL) 02:12:54 SQL> select 1 from dual where 1 not in (select 2 from dual union all select null from dual); Elapsed: 00:00:00.01 Execution Plan ---------------------------------------------------------- Plan hash value: 3291682568 ----------------------------------------------------------------- | Id | Operation | Name | Rows | Cost (%CPU)| Time | ----------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 4 (0)| 00:00:01 | |* 1 | FILTER | | | | | | 2 | FAST DUAL | | 1 | 2 (0)| 00:00:01 | | 3 | UNION-ALL | | | | | |* 4 | FILTER | | | | | | 5 | FAST DUAL | | 1 | 2 (0)| 00:00:01 | | 6 | FAST DUAL | | 1 | 2 (0)| 00:00:01 | -----------------------------------------------------------------
-
Apex SQL question - weeks of the month
I have a sql question.
I want to create a dynamic list.
If the user select may2009, then I want a dynamic list of show
04/27/2009-05/03/2009
05/04/2009-05/10/2009
05/11/2009-05/17/2009
05/18/2009-05/24/2009
05/25/2009-05/31/2009
If the user selects Jun 2009, then the list will be
06/01/2009-06/07/2009
06/08/2009-06/14/2009
06/15/2009-06/21/2009
06/22/2009-06/28/2009
06/29/2009-07/05/2009
Thank you.Using this SQL statement, you can get this list:
SELECT w_start || ' - ' || w_end d, w_start r FROM (SELECT (week_start_list + (LEVEL - 1) * 7) + 1 w_start, week_start_list + (LEVEL) * 7 w_end FROM (SELECT TO_CHAR (TRUNC (TO_DATE (:my_date, 'dd.mm.yyyy'), 'mm' ), 'IW' ) week_begin, TRUNC (TO_DATE (:my_date, 'dd.mm.yyyy'), 'mm' ) m_begin, TO_CHAR (TRUNC (TO_DATE (:my_date, 'dd.mm.yyyy'), 'mm'), 'd' ) day_month_begin, TO_CHAR (TRUNC (ADD_MONTHS (TO_DATE (:my_date, 'dd.mm.yyyy' ), 1 ), 'mm' ), 'IW' ) week_end, TRUNC (ADD_MONTHS (TO_DATE (:my_date, 'dd.mm.yyyy'), 1 ), 'mm' ) m_end, TO_CHAR (TRUNC (ADD_MONTHS (TO_DATE (:my_date, 'dd.mm.yyyy' ), 1 ), 'mm' ), 'd' ) day_month_end, TRUNC (TO_DATE (:my_date, 'dd.mm.yyyy'), 'mm' ) - TO_NUMBER (TO_CHAR (TRUNC (TO_DATE (:my_date, 'dd.mm.yyyy' ), 'mm' ), 'd' ) ) week_start_list, TRUNC (ADD_MONTHS (TO_DATE (:my_date, 'dd.mm.yyyy'), 1 ), 'mm' ) + TO_NUMBER (TO_CHAR (TRUNC (ADD_MONTHS (TO_DATE (:my_date, 'dd.mm.yyyy' ), 1 ), 'mm' ), 'd' ) ) - 1 week_end_list FROM DUAL) CONNECT BY LEVEL <= (SELECT TO_NUMBER (TO_CHAR (TRUNC (ADD_MONTHS (TO_DATE (:my_date, 'dd.mm.yyyy' ), 1 ), 'mm' ), 'IW' ) ) - TO_NUMBER (TO_CHAR (TRUNC (TO_DATE (:my_date, 'dd.mm.yyyy' ), 'mm' ), 'IW' ) ) FROM DUAL))
It is a question of SQL and has nothing to do with the Apex.
Denes Kubicek
-------------------------------------------------------------------
http://deneskubicek.blogspot.com/
http://www.Opal-consulting.de/training
http://Apex.Oracle.com/pls/OTN/f?p=31517:1
------------------------------------------------------------------- -
SQL help, how to group in column A and then get a higher frequency in column B?
Assuming that the following table, operation represents each type of operation of transaction
Employee table operation another column c
' < ' id1
' < ' id1
' < ' id2
' *' id3
id1 ' / '.
question, for each operation, which employee do the most? which employee do the 2nd most?
I thought I need to group by operation first, then get the frequency of the employee and get top 1, or at the top of page 2 of higher frequency.
But I'm struct and don't know how to write sql code.998408 wrote:
Assuming that the following table, operation represents each type of operation of transaction
Employee table operation another column c
'<'>'>
'<'>'>
'<'>'>
' *' id3
id1 ' / '.question, for each operation, which employee do the most? which employee do the 2nd most?
I thought I need to group by operation first, then get the frequency of the employee and get top 1, or at the top of page 2 of higher frequency.
But I'm struct and don't know how to write sql code.Welcome to OTN. OPS! Posted in the wrong forum. Just after in {forum: id = 75}. Before posting it close this thread as answered marking.
If someone answer is useful or appropriate, please mark accordingly. *
-
SQL question to get a top customer of the page
Hi all
I'm prasanna. I have a question about SQL, to get a customer based on name of the year and the customer. I wrote the request like this. But I got an error.
Select calendar_year, cust_first_name, max (sum (amount_sold)) in sale, the time the customers where sales.cust_id = customers.cust_id and times.time_id = sales.time_id of the calendar_year group, cust_first_name
The error is like this:
* Error from the 1 in the command line:
Select calendar_year, cust_first_name, max (sum (amount_sold)) in sale, the time the customers where sales.cust_id = customers.cust_id and times.time_id = sales.time_id of the calendar_year group, cust_first_name
Error in the command line: 1 column: 7
Error report:
SQL error: ORA-00937: not a function of simple-group
00937 00000 - 'not a single-group function. "
* Cause:
Action:
Thank you inadvace
Kind regards
Prasanna865016 wrote:
Your response, I had only one top customer with year, name of the client, amount_sold. But I need for each yearselect calendar_year, cust_first_name, total_amount_sold max_amount_sold from ( select calendar_year, cust_first_name, sum(amount_sold) total_amount_sold, row_number() over(partition by calendar_year order by sum(amount_sold) desc) rn from sales, times, customers where sales.cust_id=customers.cust_id and times.time_id=sales.time_id group by calendar_year, cust_first_name ) where rn = 1 /
I will give you a single customer by calendar_year.
SY.
-
Quick dash in Horizontal Alignment group
Hello Experts,
I have 4 dashboard which are grouped (for a single GO button) invite you... I want all 4 to be aligned horizontally by default it is pronistique.., I can't separate them because users want to have simple click for all 4.
I couldn't find all the options to make them Horizontal.
Is there a way to do this...?
Thank you
KiranHI Kiran,
Instead of creating individual guest & add in the dashboard page to create a single prompt for all 4 columns and drag in the dashboard page you will get the prompt horizontally.let know me if any questions... -
A few questions about resource groups
Oracle documentation says that the creation of Simple Plan of resources automatically adds SYS_GROUP to level 1 of the plan and the OTHER_GROUPS at level 3.
I checked SYS_GROUP and it seems that the SYSTEM is only the default member. What about SYS or SYSMAN or other dba (user) accounts? If a connect as SYS or with my own dba account to do administrative tasks will be to be considered a member of the SYS_GROUP or should I add "admin" users manually including DBSNMP SYS, SYSMAN, and so on...?
Second question. Documentation also indicates that there is, at level 3, OTHER_GROUPS catch-all group. I looked at integrated groups of servers by default and there is no OTHER_GROUPS there! Only four.
-AUTO_TASK_CONSUMER_GROUP
-DEFAULT_CONSUMER_GROUP
-LOW_GROUP
-SYS GROUP
Where's my OTHER_GROUPS?
Oracle 10.2.0.4, Linux x 86.mishomor wrote:
Oracle documentation says that the creation of Simple Plan of resources automatically adds SYS_GROUP to level 1 of the plan and the OTHER_GROUPS at level 3.I checked SYS_GROUP and it seems that the SYSTEM is only the default member. What about SYS or SYSMAN or other dba (user) accounts? If a connect as SYS or with my own dba account to do administrative tasks will be to be considered a member of the SYS_GROUP or should I add "admin" users manually including DBSNMP SYS, SYSMAN, and so on...?
Although the system is added to the group member, Sys sessions would be a part of it. I'm not sure, but I can't seem to find the note where his indeedmentioned the Sys and System would use it.
Second question. Documentation also indicates that there is, at level 3, OTHER_GROUPS catch-all group. I looked at integrated groups of servers by default and there is no OTHER_GROUPS there! Only four.
-AUTO_TASK_CONSUMER_GROUP
-DEFAULT_CONSUMER_GROUP
-LOW_GROUP
-SYS GROUPWhere's my OTHER_GROUPS?
Not sure where you looked, but I could find right away in my 11201 running on Win Xp professional.
SQL> l 1* select consumer_group from dba_rsrc_consumer_groups SQL> / CONSUMER_GROUP ------------------------------ DSS_GROUP DSS_CRITICAL_GROUP AUTO_TASK_CONSUMER_GROUP ORA$AUTOTASK_URGENT_GROUP BATCH_GROUP ORA$DIAGNOSTICS ORA$AUTOTASK_HEALTH_GROUP ORA$AUTOTASK_SQL_GROUP ORA$AUTOTASK_SPACE_GROUP ORA$AUTOTASK_STATS_GROUP ORA$AUTOTASK_MEDIUM_GROUP INTERACTIVE_GROUP OTHER_GROUPS <<<<<<<<<<<<<<<<<<<<<<<<<< DEFAULT_CONSUMER_GROUP SYS_GROUP LOW_GROUP ORA$APPQOS_0 ORA$APPQOS_1 ORA$APPQOS_2 ORA$APPQOS_3 ORA$APPQOS_4 ORA$APPQOS_5 ORA$APPQOS_6 ORA$APPQOS_7 ETL_GROUP 25 rows selected. SQL> select * from V$version; BANNER ------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production PL/SQL Release 11.2.0.1.0 - Production CORE 11.2.0.1.0 Production TNS for 32-bit Windows: Version 11.2.0.1.0 - Production NLSRTL Version 11.2.0.1.0 - Production SQL>
HTH
Aman... -
PL/SQL question (which is wrong)?
Hello
I read a book that has of the following statement
-------------------
DECLARE
type instructor_info is MADE
(name, instructor.first_name%type,
instructor.last_name%type last_name,
number of sections);
rv_instructor instructor_info;
BEGIN
Select rtrim (i.first_name),
RTrim (i.last_name),
Count (*)
the instructor,.
s section
in rv_instructor -.first_name, rv_instructor.last_name, rv_intructor.sections
where i.instructor_id = s.instructor_id
and i.instructor_id = 102
I.first_name group, i.last_name;
dbms_output.put_line (' instructor ' | rv_instructor.first_name |') '|| rv_instructor.last_name |', teaches ' | rv_instructor.sections | 'section (s)');
exception
When no_data_found then
dbms_output.put_line ('there no such instructor');
END;
-----------------
And the writer asks:
Explain what is declared in the previous example. Describe what happens to the record and explain how this translates into the output.
I look at the answers, and he says, that by operating, this example produces the following output:
Instructor Tom Wojick, teaches 9 item (s).
My question is that when I execute this example, he produced me the following error.
ORA-06550: line13, Column2:
PL/SQL: ORA-00933: SQL not correctly completed command
ORA-06550: framework8, Column2
PL/SQL: SQL statement ignored.
I tried the following:
Rv_instructor instructor_info % rowtype;
Or
In rv_instructor.first_name, rv_instructor.last_name, rv_intructor.sections
But the same error.
What's wrong?
Thank you very much.INTO clause would come before FROM clause.
Pass by ' this doc once...
http://download.Oracle.com/docs/CD/B19306_01/AppDev.102/b14261/selectinto_statement.htm#LNPLS01345
Kind regards
Prazy -
I am a newbie to SQL and I studied the book of Fundamentals SQL Server Oracle OCA 12 c, but a section on natural joins to confuse me.
Basically, the author says:
SELECT r.region_name, d.department_name, l.city, c.country_name
DEPARTMENTS d
NATURAL JOIN places l, c countries, regions r;
The natural join between DEPARTMENTS and LOCATIONS creates a provisional result, consisting of 27 lines since they are implicitly attached on the column of location_id. This set is then Cartesian-joined to the table of the COUNTRY as a join condition is not implicitly or explicitly specified. 27 interim lines are attached to 25 lines in the COUNTRY table, which gives a new temp results set with 675 (27 × 25) rows and three columns: DEPARTMENT_NAME, CITY and COUNTRY_NAME. This set is then attached to the REGION table. Once more, a Cartesian join occurs because column REGION_ID is absent from any join condition. The final result set contains rows and four columns (675 × 4) 2700.
I can understand because you evaluate joins from the left. But then he wrote:
The JOIN... USE and JOIN... ON the syntaxes are better suited to join multiple tables. The following query joins four tables using the natural join syntax:
SELECT country_id region_id, c.country_name, l.city, d.department_name
DEPARTMENTS d
NATURAL JOIN places l
NATURAL JOIN country c
NATURAL JOIN region r;
This query generates correctly 27 lines in the final results set since the required join columns are listed in the SELECT clause. The following query illustrates how the JOIN... CLAUSE is used to extract the same 27 lines. A join condition can reference columns only in its scope. In the following example, the join of DEPARTMENTS slots can not reference columns in the COUNTRIES or REGIONS of tables, but the join between the COUNTRIES and REGIONS may refer to any column of four tables involved in the query.
This second method of the part of the natural writing joined confuses me. I don't understand the logic behind the 2nd series of States of Natural Join. For me, it seems that the first series and the 2nd set look alike, but they are apparently not.
Can someone tell me the differences?
Thank you!!
Hello
The more important thing to learn more about NATURAL JOIN is: never use it. If you add new columns, joins can get different results. I've never heard of someone uisng NATURAL JOIN apart from a manual or a question like yours.
There are a lot of things in Oracle that take the time to learn and are useful. All the time you spend learning things is better spent on them.
-
Hi all
This is regarding the approval of invoice AP I need in my project where the user selects the users/people approval when creating the invoice based on logic. There may be any number of users who could be part of the approval group.
Approval users information is stored in a table with a single Bill.
When the user initiates invoice approval, approval of the Bill should go to all the people/users selected in the invoice.
I created the dynamic of approval group which is the result of a java class. This java class implements IDynamicApprovalGroup. (what is the oracle Developer Guide).
I called PL/SQL to java class package to get all the details of users of custom for the current invoice table.
I used the DriverManager.getConnection method by hard coding (JDBC URL, Username, Pwd) connection details that works perfectly fine.
But I don't want to hard-code the connection details because it will change in bodies SIT/UAT/PROD.
Please ask you to guide me if there is no solution for the information of connection without hard coding it.
Following code used to get the connection details
try {}
Class.forName ("oracle.jdbc.driver.OracleDriver");
System.out.println ("= class loaded");
}
catch (ClassNotFoundException ex) {}
System.out.println ("= class loading error");
ex.printStackTrace ();
}
Fitting out = null;
CallableStatement cstmt = null;
Try
{
connection = DriverManager.getConnection ("jdbc:oracle:thin:@xxhostname:1521/SID", "FUSION", "*");
Connection = GetConnection ();
System.out.println ("= connection =" + connection);
prepare the call
cstmt = connection.prepareCall ("{call XX_AP_INV_DYN_APPROVAL_PKG. {GET_GROUP_PARTICIPANTS (?,?)} ») ;
cstmt.setString (1, '12345'); ID on invoice
Exit of the register
cstmt.registerOutParameter (2, java.sql.Types.VARCHAR);
Call the stored procedure
cstmt. Execute();
System.out.println ("= procedure being executed");
approvalGroupMembers = cstmt.getString (2).split("#");
System.out.println ("= output:" + cstmt.getString (2));
}
catch (Exception ex) {}
ex.printStackTrace ();
}
Finally
{
Try
{
If (cstmt! = null)
close the callable statement
{
cstmt. Close();
cstmt = null;
}
System.out.println ("= stmt closed");
}
catch (SQLException ex)
{
System.out.println ("= stmt close err");
ex.printStackTrace ();
}
Try
{
If (connection! = null)
close the connection
{
Connection.Close;
connection = null;
}
System.out.println ("= closed conn");
}
catch (SQLException ex)
{
System.out.println ("= Close conn err");
ex.printStackTrace ();
}
}
Thank you
Dipak.
HI Dembélé - you should be able to call the provider database from the java class. Documentation is here. However, you need to specify the name of the data provider that is the same in all environments. Do you know what it is? If it's not I'll take a look and get back to you.
__
Peter Maurer
Relationship with the developers of Applications in fusion
-
SQL * PLUS connects with SQL >; question
People,
I'm confused on the command. / sqlplus with Oracle database.
According to my understanding,. / sqlplus connected with SQL > using option 3: sysdba, sysoper, sysasm.
I connect with SQL > to run the rel853.sql script to create a table PSOPRDEFN but a field "OPERPSWDSALT" did not appear in the table PSOPRDEFN although it is in the Create Table statement.
I connect with SQL * in the directory/home/user/OracleDB_Home/bin as below:
$ export SYSTEM_PASS = AccessId/mypass$ export ORACLE_HOME = / home/user/OracleDB_Home
$ export ORACLE_SID = HRCS90
$. / lsnrctl start LISTENER
$. / AccessId/mypass sqlplus as sysdba
SQL > startup
SQL > @/opt/PT8.53/scripts/rel853.sql
SQL > select OPERPSWDSALT in the AccessId.PSOPRDEFN;
It returns: "OPERPSWDSALT": invalid identifier.
I checked the table PSOPRDEFN that the OPERPSWDSALT field did not appear in the table PSOPRDEFN.I tried the sysoper option as below:
$. / sqlplus AccessId/mypass as sysoper
SQL > startup
SQL > @/opt/PT8.53/scripts/rel853.sql
SQL > select OPERPSWDSALT in the AccessId.PSOPRDEFN;
It returns: "OPERPSWDSALT": invalid identifier.
The sysoper error is the same thing with sysdba error.
I tried the sysasm option as below:
$. / sqlplus AccessId/mypass as sysasm
He returned: connection refused.
Someone told me this connection as SYS causes this error. If not a sysdba, sysoper, or sysasm, use the command. / sqlplus AccessId/mypass cannot connect with SQL >.
My question is:
First of all, why is what OPERPSWDSALT did not appear in the PSOPRDEFN table while it is in the CREATE TABLE statement?
Seocond, if not use SYS which is one of the 3 options, how to run the command. / sqlplus AccessId/mypass to connect with SQL > so that CREATE TABLE PSOPRDEFN correctly?Thank you.
user8860348 wrote:
People,
Hello. Thanks much for the reply. I just do the commands below:
$ export SYSTEM_PASS = AccessId/mypass
$ export ORACLE_HOME = / home/user/OracleDB_Home
$ export ORACLE_SID = HRCS90
$. / lsnrctl start LISTENER
$. / AccessId/mypass sqlplus as sysdba
SQL > show user;
Its release: the USER is "SYS".
SQL > connect AccessId/mypass
Its output:
Error: ORA - 01034:ORACLE not available
ORA-27101: shared memory realm does not exist
64 - Linux_x86 error: no such file or directory.
As we see above, unable to connect to the Oracle database AccessId.
My question is:
What to do on AccessId, so that it can connect to the Oracle database?
Thank you.
so much for the use that you refuse to actually use COPY it PASTE & so that we can see the whole session.
In the past, you did
> SQL > startup
Maybe the database is out of order & must be started.
do exactly as below (line by line)
ID
sqlplus
/ as sysdba
startup
connect AccessId/mypass
COPY the results from above then PASTE all back here
-
Oracle PL SQL Question to get some data to oracle tables descrepancy
Version of database
Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64 bit Production
PL/SQL Release 9.2.0.8.0 - Production
CORE Production 9.2.0.8.0
AMT for HP - UX: 9.2.0.8.0 - Production Version
NLSRTL Version 9.2.0.8.0 - Production
created a few sample data
drop table tab1 purge;
create table tab1 (DEPT_ID COMP, qc_subtype_id char (4), EQUIP_CODE varchar2 (20), create_time date);
Insert into tab1 values(13,'1026','HEMORYA011',sysdate);
Insert into tab1 values(13,'1012','HEMORYA011',sysdate);
Insert into tab1 values(95,'1026','HEMORYA121',sysdate);
Insert into tab1 values(95,'1012','HEMORYA121',sysdate);
----------------------
Insert into tab1 values(13,'1026','HEMORYA014',sysdate);
Insert into tab1 values(13,'1012','HEMORYA005',sysdate);
Insert into tab1 values(13,'1012','HEMORYA013',sysdate);
Insert into tab1 values(95,'1012','HEMORYA013',sysdate);
Insert into tab1 values(95,'1012','HEMORYA148',sysdate);
commit;
I need to get a query to get the records of the gap
Dept HEMORYA014 13 lack 1012
HEMORYA005 dept 12 lack 1026
Dept HEMORYA013 13 lack 1026
The dept 95 lack 1026 HEMORYA013
The dept 95 lack 1026 HEMORYA148
I want to show the latter on the report
Thanks in advance.Thanks for posting a unit test.
I hope it will work for you, but maybe you will need to set the WHERE clause (add additional predicates).SQL> select equip_code 2 from ( select equip_code 3 , count(distinct qc_subtype_id) 4 from tab1 5 group by equip_code 6 having count(distinct qc_subtype_id)<2 7 ) 8 order by equip_code; EQUIP_CODE -------------------- HEMORYA005 HEMORYA013 HEMORYA014 HEMORYA148
-
Hi expert,
When I ran after SQL, error message reads "table or view does not exist" pointing to the table "dba_tab_cols" and "dba_all_tables". There is no other question for this statement, because if I changed table "user_tab_cols" and "user_all_tables", it works well.
declare
v_old_table DBA_tab_columns.table_name%type;
v_where Varchar2 (4000);
Boolean v_first_col: = true;
type rc is ref cursor;
c rc;
v_rowid varchar2 (20);
Val varchar2 (50): = "Test note";
Start
for r in)
Select
t.*
Of
dba_tab_cols t, dba_all_tables a
where t.table_name = a.table_name
and t.data_type like '% CHAR % '.
and a.owner = 'QA'
order by t.table_name loop)
If v_old_table is null then
v_old_table: = r.table_name;
end if;
If v_old_table <>r.table_name then
v_first_col: = true;
-dbms_output.put_line ('search' | v_old_table);
Open c for ' select rowid from ' ' |. ' v_old_table | '" ' || v_where;
extract the c in v_rowid;
loop
When the output c % notfound;
dbms_output.put_line (' rowid: ' | v_rowid |) "in" | v_old_table);
extract the c in v_rowid;
end loop;
v_old_table: = r.table_name;
end if;
If v_first_col then
v_where: = 'where ' | r.column_name | "as" %' | Val | '%''';
v_first_col: = false;
on the other
v_where: = v_where | "or" | r.column_name | "as" %' | Val | '%''';
end if;
end loop;
end;
But if I choose these DBA tables in the toad sql Editor, it works well, I am currently using my own credentials, not the administrator credentials. why he get different effects running in these two ways?
Thank you very much>
Hello
When I ran after SQL, error message reads "table or view does not exist" pointing to
Table 'dba_tab_cols' and 'dba_all_tables '. There is no other question for this statement, becauseIf I changed table "user_tab_cols" and "user_all_tables", it works well.
But if I choose these DBA tables in the toad sql Editor, it works well, I am currently using my own
credentials, not the administrator credentials. why he get different effects running in these two ways?You answered your own question - you know that you have the administrator privileges when you
Open a session under your own credentials - but your id user obviously does TOAD.You use SQL * for the query that fails?
BTW, you do not give us your version of Oracle - you must always tell us what it is
Please read the forum FAQ and also the thread "sticky" by BluShadow at the top of the list of positions
on the forum homepage. These forums are an excellent resource - you will get the best out of them if
you follow the instructions.HTH,
Paul...
Published by: Paulie July 24, 2012 16:40
-
SQL question for a beginner...
I have the following structure:
NUMBER OF PROCESSING_ITEM_ID
NUMBER OF PROJECT_ITEM_FK
START_TIME DATE
END_TIME DATE
NUMBER OF WORKSTATION_FK
examples of data
81,23,10-27-2010 08:00, 27/10/2010 10:00, 3
42,1,10-27-2010 08:00, 27/10/2010 11:00, 1
22,23,10-27-2010 13:00, 27/10/2010 17:00, 2
1,23,10-27-2010 15:00, 27/10/2010 16:00, 1
23,23,10-27-2010 17:00, 27/10/2010 20:00, 2
I'm trying to divide the data into lines of an hour. If this line we would be divided into:
81,23,10-27-2010 08:00, 27/10/2010 09:00, 3
81,23,10-27-2010 09:00, 27/10/2010 10:00, 3
third row would be divided into:
22,23,10-27-2010 13:00, 27/10/2010 14:00, 2
22,23,10-27-2010 14:00, 27/10/2010 15:00, 2
22,23,10-27-2010 15:00, 27/10/2010 16:00, 2
22,23,10-27-2010 16:00, 27/10/2010 17:00, 2
The statement that is made should display the data in this way...
John Brewer
City of SeattleQuestion delicate John, you should ask this in the SQL forums
This is the query
with temp AS ( SELECT 81 PROCESSING_ITEM_ID,23 PROJECT_ITEM_FK,TO_DATE('10-27-2010 08:00','MM-DD-YYYY HH24:MI') start_date,TO_DATE('10-27-2010 10:00','MM-DD-YYYY HH24:MI') end_date,3 WORKSTATION_FK from dual UNION ALL SELECT 22 PROCESSING_ITEM_ID,23 PROJECT_ITEM_FK,TO_DATE('10-27-2010 13:00','MM-DD-YYYY HH24:MI') start_date,TO_DATE('10-27-2010 17:00','MM-DD-YYYY HH24:MI') end_date,2 WORKSTATION_FK from dual ) ,time_span AS ( SELECT MAX( TO_NUMBER(TO_CHAR(end_date,'HH24')) - TO_NUMBER(TO_CHAR(start_date,'HH24')) ) TIME_SPAN FROM temp ) ,time_period_rows AS ( SELECT level-1 PERIOD FROM time_span connect by level <= TIME_SPAN ) SELECT T.PROCESSING_ITEM_ID,T.PROJECT_ITEM_FK,TO_CHAR(T.start_date+TR.PERIOD/24,'MM-DD-YYYY HH24:MI') start_time,TO_CHAR(T.start_date+(TR.PERIOD+1)/24,'MM-DD-YYYY HH24:MI') end_time ,T.WORKSTATION_FK FROM temp T ,time_period_rows TR WHERE PERIOD <= TO_NUMBER(TO_CHAR(end_date,'HH24')) - TO_NUMBER(TO_CHAR(start_date,'HH24')) ORDER BY T.PROCESSING_ITEM_ID,TR.PERIOD
Output
PROCESSING_ITEM_ID PROJECT_ITEM_FK START_TIME END_TIME WORKSTATION_FK 22 23 10-27-2010 13:00 10-27-2010 14:00 2 22 23 10-27-2010 14:00 10-27-2010 15:00 2 22 23 10-27-2010 15:00 10-27-2010 16:00 2 22 23 10-27-2010 16:00 10-27-2010 17:00 2 81 23 10-27-2010 08:00 10-27-2010 09:00 3 81 23 10-27-2010 09:00 10-27-2010 10:00 3 81 23 10-27-2010 10:00 10-27-2010 11:00 3
I used a view inline as data source ( temp ), you can change this to your table, name (then remove the display online)
Maybe you are looking for
-
help guys!
-
RAID 1 (with SAS9260-8i), ESXi 5.5
I photographed 8i controller, but when I try to add the 'storage' I see nothing connected to the hardware RAID controller. (This RAID controller is listed in the ESXi 5.5 compatibility list)I have just listed critical components of my version below,
-
Can't print PDF to office on a wireless printer
When I view a PDF and printing it is impossible. I select the button PRINT that opens to the top of my printer tool. I then go to the list of available printers. All that appears is the one who is wired to my office (most writer fax etc.), but my
-
Photoshop _ program error after installation of the Mavericks
Since I loaded the Mavericks on my APPLE I can't open a file of any file. So if I go in for open file, it will not open I get a message saying: "Could not complete your request because of a program error."I can however get the file with desktop and d