analytical sql question
Dear all,I have the following problem for the output table of the table entry below.
Do you have any idea to do this with the analytical help of sql?
p.s. I did using pure plsql block which is too slow to work with a large amount of data. Given below is just a sample, in real time, I have millions of rows of data.
Entry table:
VALUE OF TIME USER
1 X
2 X
3 B Y
4 B Y
5 X
5 X
6. A Y
7 B Y
7. A Y
Table of outputs:
VALUE OF START_TIME, END_TIME USER
1 2 A X
5 5 A X
6 7 A Y
3 4 B Y
5 5 B X
7 7 B Y
create table mytable (time,myuser,value) as
select 1 col1, 'A' col2, 'X' col3 from dual union all
select 2 col1, 'A' col2, 'X' col3 from dual union all
select 3 col1, 'B' col2, 'Y' col3 from dual union all
select 4 col1, 'B' col2, 'Y' col3 from dual union all
select 5 col1, 'A' col2, 'X' col3 from dual union all
select 5 col1, 'B' col2, 'X' col3 from dual union all
select 6 col1, 'A' col2, 'Y' col3 from dual union all
select 7 col1, 'B' col2, 'Y' col3 from dual union all
select 7 col1, 'A' col2, 'Y' col3 from dual union all
select 8 col1, 'A' col2, 'Y' col3 from dual;
select min(time),max(time),myuser,value
from (select time,myuser,value,
dense_rank() over(order by time)
-Row_Number() over(partition by myuser,value order by time)
as distance
from mytable)
group by myuser,value,distance
order by myuser,min(time);
MIN(TIME) MAX(TIME) M V
--------- --------- - -
1 2 A X
5 5 A X
6 8 A Y
3 4 B Y
5 5 B X
7 7 B Y
I used the sense of Tabibitosan B-)
window function
Tags: Database
Similar Questions
-
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 question, perhaps with the analytical functions?
I have a small problem:
I have a table with:
DAY_ID, PAGE_ORDER, SID, TIME, CONTENT.
I want only to the rank (min) of lines with the same content when there is more than
the one with the same content that follows.
The data are:
DAY PAGE_ORDER SID TIMES CONTENT
20150825 1 4711 25.08.15 06:38:43 / body/home
4711 2 20150825 25.08.15 06:39:10 home, aufmacher, Home, 42303938
20150825 3 4711 25.08.15 06:39:15 welcome, aufmacher, Home, 42303938
20150825 4 4711 25.08.15 06:39:20 home, aufmacher, Home, 42303938
20150825 5 4711 25.08.15 06:39:24 home, aufmacher, Home, 42303938
20150825 6 4711 25.08.15 06:39:32 home, aufmacher, Home, 42303938
20150825 7 4711 25.08.15 06:39:39 home/aufmacher/Home/42303938
20150825 8 4711 25.08.15 06:39:46 welcome, aufmacher, Home, 42303938
20150825 9 4711 25.08.15 06:39:49 home, aufmacher, Home, 42303938
4711 10 20150825 25.08.15 06:39:51 home, aufmacher, Home, 42303938
4711 11 20150825 25.08.15 06:41:17 pol/art/2015/08/24/paris
20150825 12 4711 25.08.15 06:42:36 / body/home
20150825 13 4711 25.08.15 07:06:09 / body/home
20150825 14 4711 25.08.15 07:06:36 reg/article/memo
I want as a result:
20150825 1 4711 25.08.15 06:38:43 / body/home
4711 2 20150825 25.08.15 06:39:10 home, aufmacher, Home, 42303938
4711 11 20150825 25.08.15 06:41:17 pol/art/2015/08/24/paris
20150825 12 4711 25.08.15 06:42:36 / body/home
20150825 14 4711 25.08.15 07:06:36 reg/article/memo
Who knows a good way?
Thank you very much
It sounds like a simple solution group. You group by content and maybe a few other columns such as the day and sid. So, you want to show some value of inside this group. Several different aggregate functions to do this.
Not tested, because of lack of tabe create and insert scripts
select day, sid, content ,min(page_order) as page_order ,min(times) as times -- if the first page_order also has the first time ,min(times) keep dense_rank first (order by page_order) as times2 -- this is needed in case the first page_order is at a later time from yourTable group by day, sid, content
If Solomon is right, and several identical content may exist (the example data show that). Then we can use the Tabibitosan method to create the groups.
with step1 as (select t1.*, row_number() over (partition by day, sid, content order by page_order) rn from yourTable ) select day, sid, content , page_order - rn as group_number , min(page_order) as page_order , min(times) as times -- if the first page_order also has the first time , min(times) keep dense_rank first (order by page_order) as times2 -- this is needed in case the first page_order is at a later time from step1 group by day, sid, content, page_order - rn order by day, sid, content, group_number;
-
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.
-
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
-
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 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.
-
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)
-
Hi all
I'm kinda new in the analytical work with query and have a moment difficult to achieve what I wanted.
Here is the script to create the table and insert data.
Insert the Script-create table temp_ar1 (lkey NUMBER, amount NUMBER ) ;
I'm trying to get the result that resemblesInsert into temp_ar1 values (1, -2.5); Insert into temp_ar1 values (1, -10); Insert into temp_ar1 values (1, 5); Insert into temp_ar1 values (2, 0); Insert into temp_ar1 values (2, -5); Insert into temp_ar1 values (2, 2); Insert into temp_ar1 values (2, -1); With main_table as ( select lkey,amount ,case when amount > 0 then 'positive' else 'negative' end col1 from temp_ar1 ) ,Temp_A as ( Select O.* ,Sum ( case when col1 = 'negative' then amount else null end ) Over (partition by col1,lkey) as sumcol1 ,Sum ( case when col1 = 'positive' then amount else null end ) Over (partition by col1,lkey) as sumcol2 from main_table O ) select lkey,amount,col1,sumcol1,sumcol2 from Temp_A order by lkey LKEY AMOUNT COL1 SUMCOL1 SUMCOL2 ---------- ---------- -------- ---------- ---------- 1 5 positive 5 1 -2.5 negative -12.5 1 -10 negative -12.5 2 -1 negative -6 2 2 positive 2 2 0 negative -6 2 -5 negative -6 7 rows selected.
So for each separate key, I should get only a line that has sumcol1 (which is the sum of a negative amount for this key) andlkey , sumcol1 , sumcol2 1 -12.5 5 2 -6 2
sumcol2 (which is the sum of the positive amount for this key)
Really appreciate your help on this matter.or, if you do not want to group by;
SQL> with Temp_A as 2 ( 3 select O.* 4 ,sum ( case when amount < 0 then amount 5 else null 6 end ) over (partition by lkey) as sumcol1 7 ,sum ( case when amount > -1 then amount 8 else null 9 end ) over (partition by lkey) as sumcol2 10 ,row_number() over (partition by lkey order by lkey) rn 11 from temp_ar1 O 12 ) 13 -- 14 select lkey,sumcol1,sumcol2 15 from Temp_A 16 where rn = 1 17 / LKEY SUMCOL1 SUMCOL2 ---------- ---------- ---------- 1 -12.5 5 2 -6 2
-
Sorry guys, didn't know where otherwise put this hope so much he is allowed to post here. I currently have a field in my database that stores the date and time, however, I write a statemenet sql and need to use only the date of the datetime object, which would be the correct syntext to sowould I should use to_char etc.?
Thank you.Not a question of forms, but a database.
But check this for format masks: http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/sql_elements004.htm
-
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 -
What kind of pl sql questions can you expect for a customer technical interview
Please notify all experienced professionals
What kind of questions can I expect in the customer facing interview technical I have to a PL SQL Developer with interview of performance tuning. The customer is primarily a financial project.
Yes of course I would essentially tell me about the projects that you been involved in based on who they ask the questions, basically I'm not very experienced 3 years and my experience involves performance limited tuning, to develop scripts to support front-end web applications.
What kind of questions (you do not need to enumerate the issues specifically, it would be useful that you could advise the areas where I should look into, all the links where I can read about the region suggest you also face a customer interview).
Example: Financial transaction processes much as treatment so I have to prepare for any question on the changing Table, blocking.
Also, I am aware of the Collections, external Tables. These would be discussed.
Any advice would be very helpful.
My experience does not imply strongly any financial experience and job specification does not state so I got through the 2 first interview series. It would be a disadvantage if I said that I have had no experience of finanicial, I guess just by hearing from some sources that the customer is finance.
I would be hired only if the customer agrees, so I need to deepen as much as possible, it's time to prepare for good trying to inform.
Kind regards.Rider wrote:
My experience does not imply strongly any financial experience and job specification does not state so I got through the 2 first interview series. It would be a disadvantage if I said that I have had no experience of finanicial, I guess just by hearing from some sources that the customer is finance.
Personally, when I interview candidates PL/SQL, the least important thing for me is real business knowledge. I want to rather a competent PL/SQL Developer who knows his stuff, a person having poor skills of PL/SQL and a good knowledge of the company.
We will pay that person for PL/SQL capabilities - and not knowledge of business (that of why we have analysts and managers of project and team leaders). Remember that the code ' + financial + "is no different code" + detail + "-the same language is used. The same concepts. The same methods to solve problems. As the problems you are dealing with a level of PL/SQL are technical - where business issues have already been processed by analysts and architects at a higher level.
I expect, however, that such a developer will resume business over time knowledge. But I don't see it as any kind of precondition.
-
Dynamic SQL question. What are these apostrophes for?
Here is a solution provided by Boneist in the two questions relating to a so-called simple dynamic SQL thread
When a tablename is extracted, it should be in single quotes as "DEPT". My question is about the quotes surrounding i.table_name (three quotes on the left) and 4 quotes on the right of the concatenationdeclare v_rs date; begin for i in (select table_name from user_tables) loop execute immediate 'select last_analyzed from user_tables where table_name = ''' || i.table_name||'''' into v_rs; dbms_output.put_line(i.table_name ||'----'||v_rs); end loop; end;
First quote on the left is the final quote from SELECT (' select last_analyzed)''' || i.table_name||''''
Second quote from left to right - I think this is the quote from beginning to the name of the table ("DEPT)
Quote from third starting on the left -?
I have not understant what 4 quotes on the right of the concatenation of c. I know one of them is the quotation from the end (right) for the name of the table (like DEPT')JOE_humble wrote:
When a tablename is extracted, it should be in single quotes as "DEPT". My question is about the quotes surrounding i.table_name (three quotes on the left) and 4 quotes on the right of the concatenationActually 4 quotes on the left quotation marks and 4 right...
execute immediate 'select last_analyzed from user_tables where table_name = ''' || i.table_name||'''' into v_rs; ^ ^^^ ^^^^ | ||| |||| \________________________________________________________/// \||/ | \| 4 quotes 4 quotes
Maybe better if you look at it like this...
Suppose we use a character # to indicate the beginning and the end of our strings...
execute immediate #select last_analyzed from user_tables where table_name = ''# || i.table_name||#''# into v_rs;
Now, you can see that we have two strings concatenated with the variable string representing the table name concatenated together.
Within each of these channels, we have two single quotes. When the parser crosses the two single quotes like this, in the string, which converts a quotation mark in the resulting string, rather than taking this means the end of the string itself.
-
When I used the updated syntax, return always seems to be the total number of rows in the table updated (not updated lines):
create table a18 (identification number, name varchar2 (10));
create table b18 (identification number, name varchar2 (10));
Insert in b18 values (1, 'A');
Insert in b18 values (2, 'B')
insert into A18 (id) values (1);
insert into A18 (id) values (11);
Select * from a18;
name identity
1
11
Select * from b18.
name identity
2B
2B
update of a18 set a18.name = (select b18.name from b18 where b18.id = a18.id)
2 lines update
Select * from a18
name identity
2B
11
Question: why it returns "2 rows updated" while it is only a line update?
I tested with SQL Server 2005/2008 and the behavior is the same (2 rows affected).
Published by: Modeler on May 19, 2009 16:59
Published by: Modeler on May 19, 2009 17:02Your UPDATE statement has no WHERE clause, then it will update with each row in the table. It is one of the lines is being updated at the same value that it had before the update. But you still incur any overhead due to update the block, writing appropriate UNDO and REDO the vectors, etc. for the line that you update without changing.
Justin
Maybe you are looking for
-
purchase could not be completed
Please help me I can't buy items
-
Satellite X 200-15 K - I want drivers for Windows 7
I waited for months and even you you created drivers for x 205 for the months of usa there is Windows 7 drivers (x 205 and x 200 are very similar) you did nothing for x 200. Don't tell me that x 200 is an old laptop, it is upscale and costs a lot of
-
2 questions: touchpad and recovery disk
I installed Windows seven and then proceed to installing the drivers of recovery disk, but everytime I start this it says it will restart my computer. After reboot, nothing happens and when I run it restarts again again and again... What can I do wit
-
I have a PC Media Center m7160n. The pc does not start upward in normal or safe mode. It happens to the normal login page, but when a user is selected, he painted the wallpaper as usual, but that's all. No icons or taskbar. If only the screen sav
-
How to install manually update K976321
I get the error code 646 whenever I try to install the update K976321 window. I tried to save it on my hard drive, but it wouldn't work. I was asked permission to the administrator each time, and I am the administrator. So, I ran out of options. H