Help please SQL
Hi allPlease help me with this query:
I have data from a table like:
ID | emp_id | salary
1. 100. 200
2. 200 | 400
3. 300. 450
and I need to write a Sql to get the following result:
ID | emp_id | salary | C_Salary
1. 100. 200 | 200
2. 200 | 400. 600
3. 300. 450. 1050
Examples of data include:
with t as
(select 1 i_d, empi_d 100, 200 double sal)
UNION ALL
Select i_d 2, empi_d 200, 400 sal double
UNION ALL
Select 3 i_d, empi_d 300, 450 double sal)
Select * from t
Concerning
Rahul
Hello
Try like this
with t as
(select 1 i_d, empi_d 100, 200 double sal)
UNION ALL
Select i_d 2, empi_d 200, 400 sal double
UNION ALL
Select 3 i_d, empi_d 300, 450 double sal)
Select t.*, sum (sal) over (order by I_D) t C_Sal
Thank you & best regards
Srikkanth.M
Tags: Database
Similar Questions
-
Help please SQL... Adding a column of total accumulated in a table
Tonight... I have the task of adding a column of total cumulative to a table that contains a list of transactions. The table contains entries for several accounts.
for example
create the table adam_test1
(
account char (4),
date of entry_date,
amount number 4,
Balance number 4
);
insert into adam_test1 values ('1000', January 1, 2000 ", 50", null);
insert into adam_test1 values ('1000', January 2, 2000 ', 40', null);
insert into adam_test1 values ('1000', 3 January 2000', '-50', null ");
insert into adam_test1 values ('1000', January 4, 2000 ', 10', null);
insert into adam_test1 values ('1000', 5 January 2000', '-250', null ");
insert into adam_test1 values ('1000', January 6, 2000', '100', null);
insert into adam_test1 values ('1000', January 7, 2000 ", 50", null);
insert into adam_test1 values ('2000,' 1 January 2000 ', 30', null);
insert into adam_test1 values ('2000', January 2, 2000 ', 10', null);
insert into adam_test1 values ('2000', 3 January 2000', '-520', null ");
insert into adam_test1 values ('2000', January 4, 2000', '140', null);
insert into adam_test1 values ('2000', 5 January 2000', '-4', null ");
insert into adam_test1 values ('2000', January 6, 2000 "," 120", null);
insert into adam_test1 values ('2000', January 7, 2000 ', 57', null);
SQL > select * from adam_test1;
ACCO ENTRY_DAT BALANCE AMOUNT
---- --------- ---------- ----------
1000 1 JANUARY 00 50
1000 2 JANUARY 00 40
1000 3 JANUARY 00-50
1000 4 JANUARY 00 10
1000 5 JANUARY 00-250
1000 6 JANUARY 00 100
1000 7 JANUARY 00 50
2000 1 JANUARY 00 30
2000 2 JANUARY 00 10
2000 3 JANUARY 00-520
2000 4 JANUARY 00 140
2000 JANUARY 5, 00-4
2000-6 JANUARY 00 120
2000-7 JANUARY 00 57
.. I tried a few things to fill the values using rowid, but I was not able to get anything to work - ideas?
Thank you!
AdamUse MERGE:
merge into adam_test1 t1 using ( select rowid, sum(amount) over(partition by account order by entry_date) balance from adam_test1 ) t2 on (t1.rowid = t2.rowid) when matched then update set t1.balance = t2.balance / ACCO ENTRY_DAT AMOUNT BALANCE ---- --------- ---------- ---------- 1000 01-JAN-00 50 50 1000 02-JAN-00 40 90 1000 03-JAN-00 -50 40 1000 04-JAN-00 10 50 1000 05-JAN-00 -250 -200 1000 06-JAN-00 100 -100 1000 07-JAN-00 50 -50 2000 01-JAN-00 30 30 2000 02-JAN-00 10 40 2000 03-JAN-00 -520 -480 2000 04-JAN-00 140 -340 ACCO ENTRY_DAT AMOUNT BALANCE ---- --------- ---------- ---------- 2000 05-JAN-00 -4 -344 2000 06-JAN-00 120 -224 2000 07-JAN-00 57 -167 14 rows selected. SQL>
SY.
-
I have the table of 3 columns A, B, C. I want to store the sum of columns A B in the C column without using the DML statements. Can anyone help please how to do. ?
11.1 and especially you have virtual column
SQL> create table t 2 ( 3 a number 4 , b number 5 , c generated always as (a+b) virtual 6 ); Table created. SQL> insert into t (a, b) values (1, 2); 1 row created. SQL> select * from t; A B C ---------- ---------- ---------- 1 2 3
Before that, a front insert - trigger
SQL> create table t 2 ( 3 a number 4 , b number 5 , c number 6 ); Table created. SQL> create or replace trigger t_default before insert on t for each row 2 begin 3 :new.c := :new.a+:new.b; 4 end; 5 / Trigger created. SQL> insert into t (a, b) values (1, 2); 1 row created. SQL> select * from t; A B C ---------- ---------- ---------- 1 2 3
-
Under Update taking 2 h complete 3000 sets.
UPDATE ARR_TRANSACTIONS ARR
SET = NUMBER99
(SELECT ARR_1.NUMBER99
OF ARR_TRANSACTIONS ARR_1, ARR_HEADER BH
WHERE ARR_1.ARR_ID = BH. ARR_ID
AND BH. FLAG = "Y".
AND ARR_1.LINE_ID = ARR. ORIG_INV_LINE_ID
AND ARR_1.NUMBER9 IS NOT NULL
AND ROWNUM = 1)
WHERE ARR BATCH_ID = 26219
AND ARR. NUMBER99 IS NULL
I added more some condition where to reduce cost and its working fine. But I need to rise more than performance on SQL.
Please help with SQL.
I do not see the number of 3000 lines in the plan - so I guess that the optimizer does not compute with the correct numbers. Could generate the plan with dbms_xplan.display_cursor? This could tell us something about filter predicates and access.
In the given situation, I would check:
- is the access to the index in step 1 (filtered by the relevant conditions: this could be BATCH_ID = 26219) return actually 248 entries (or something similar)?
- Access table in step 2 returning 204 lines (or something similar) after applying the filters given? If the number of lines is much bigger then a Nested Loops is perhaps not a good idea.
To make this much simpler check, you could create a plan with statistics of content (RowSource) given that the plan containing the real and the number of estimated rows.
If the estimated cardinalities are not plausible the next question would be if the statistics are strong and up to date.
-
Erroneous comment. Help, please
I want to write a query that will have the departments table department_id and print the corresponding employee_id, last_name, manager_id in this Department into the employees table and print a message--no employee no existence for this Department in the employees table, whose employees do not exist in the employees table... I get this message in all the outputs. Help, please...
DECLARE
CURSOR cur_dept IS
SELECT department_id from departments;
R1 cur_dept % ROWTYPE;
CURSOR cur_emp (p_dept_id departments.department_id%TYPE) IS
SELECT employe_id, last_name, manager_id
Employees
WHERE department_id = p_dept_id;
R2 cur_emp % ROWTYPE;
BEGIN
OPEN cur_dept.
LOOP
SEEK cur_dept INTO r1;
When the OUTPUT cur_dept % NOTFOUND;
DBMS_OUTPUT. Put_line (' the department_id is:-' |) R1.department_id);
OPEN cur_emp (r1.department_id);
LOOP
SEEK cur_emp INTO r2;
IF FOUND THEN % cur_emp
DBMS_OUTPUT. Put_line (r2.employee_id | ',' |) R2.last_name | | ',' | R2.manager_id);
ON THE OTHER
DBMS_OUTPUT. Put_line (' no employees for ' |) R1.department_id);
EXIT;
END IF;
END LOOP;
CLOSE Cur_emp;
END LOOP;
close cur_dept;
END;
The output that is iam: -.
The department_id is:-10
200, Whalen, 101
No employee for 10
The department_id is:-20
201, hiba, 100
202, Fay, 201
No employees for 20
The department_id is:-30
No employee for 30
The department_id is:-40
No employee for 40
The department_id is:-50
124, Mourgos, 100
141, Rajs, 124
142, Davies, 124
143, gear, 124
144, Vargas, 124
No employee for 50
The department_id is:-60
103, Hunold, 102
104, Ernst, 103
107, Lorentz, 103
No employees for 60
The department_id is:-70
No employee for 70
The department_id is:-80
101, Kochhar, 100
149, Zlotkey, 100
174, Abel, 149
176, Taylor, 149
No employee for 80
The department_id is:-90
100, King,.
102, Haan, 100
No employee for 90
The department_id is:-100
No employee to 100
The department_id is:-110
205, Higgins, 101
206, Gietz, 205
No employee for 110
The department_id is:-120
No employee for 120
The department_id is:-130
No employee for 130
The department_id is:-140
No employee for 140
The department_id is:-150
No employee for 150
The department_id is:-160
No employee for 160
The department_id is:-170
No employee for 170
The department_id is:-180
No employee for 180
The department_id is:-190
No employee for 190
The department_id is:-200
No employee for 200
PL/SQL procedure successfully completed.
Try something like below (emp used, dept tables):
Set serveroutput ON
DECLARE
c number: = 0;
CURSOR cur_dept IS
SELECT deptno FROM dept;
R1 cur_dept % ROWTYPE;
CURSOR cur_emp (p_dept_id dept.deptno%TYPE) IS
SELECT ename, empno, mgr
WCP
WHERE deptno = p_dept_id;
R2 cur_emp % ROWTYPE;
BEGIN
OPEN cur_dept.
LOOP
SEEK cur_dept INTO r1;
EXIT WHEN cur_dept % NOTFOUND;
DBMS_OUTPUT. Put_line (' the department_id is:-' |) R1. DEPTNO);
OPEN cur_emp (r1.deptno);
LOOP
SEEK cur_emp INTO r2;
exit WHEN cur_emp % NOTFOUND;
c: = c + 1;
DBMS_OUTPUT. Put_line (r2.empno | ',' |) R2. Ename | | ',' | R2.Mgr);
END LOOP;
CLOSE Cur_emp;
IF C = 0 THEN
DBMS_OUTPUT. Put_line (' no employees for ' |) R1. DEPTNO);
END IF;
c: = 0;
END LOOP;
CLOSE Cur_dept;
END;
/
The department_id is:-10
7782, CLARK, 7839
7839, KING,.
7934, MILLER, 7782
The department_id is:-20
7369, SMITH, 7902
7566, JONES, 7839
7788, SCOTT, 7566
7876, ADAMS, 7788
7902, FORD, 7566
The department_id is:-30
7499, ALLEN, 7698
7521, WARD, 7698
7654, MARTIN, 7698
7698, BLAKE, 7839
7844, TURNER, 7698
7900, JAMES, 7698
The department_id is:-40
No employee for 40
PL/SQL procedure successfully completed.
-
Newspapers are not sent to the database of Dr. help, please
Hello
I have create a databas physics ensures the local site. the works of dataguard.
But the database pending cannot receive the journal when the standby database installs remotely and change IP, / etc/hosts, listener.ora and tnsnames.ora.
It seems that work waiting for network problem coz log shipping database to the local site.
Help, please.
message below
AIX 5300-12-04-1119 + Oracle 11.2.0.2
# Journal of primary database alerts. #########
******************************************************************
LGWR: Definition of 'active' from archive to destination LOG_ARCHIVE_DEST_2
******************************************************************
Wed Sep 09 18:40:13 2013
WARN: Cra1: termination pid 2916466 hooked to an IO operation
WARN: Cra1: termination pid 3350692 hooked to an IO operation
krsv_proc_kill: kill 1 process (process by index)
Wed Sep 09 18:40:24 2013
krsv_proc_kill: kill 1 process (process by index)
Arc1: Error 16198 done hung operation of e/s to LOG_ARCHIVE_DEST_2
Arc1: Default detected process ARCH
Arc1: Default detected process ARCH
ARC1: FROM PROCESS ARCH
Wed Sep 09 18:40:27 2013
ARC2 started with pid = 20, OS id = 2916468
ARC2: Started archiving
WARN: ARC2: termination pid 585944 hooked to an IO operation
Wed Sep 09 18:40:27 2013
ARC3 started with pid = 22, OS id = 3383458
ARC3: Started archiving
ARC1: FROM PROCESS ARCH COMPLETE
Reclaiming entered dead process FAL [pid 2916466]
krsv_proc_kill: kill 1 process (process by index)
WARN: ARC3: termination pid 585944 hooked to an IO operation
krsv_proc_kill: kill 1 process (process by index)
ARC2: Default detected process ARCH
ARC2: FROM PROCESS ARCH
Wed Sep 09 18:40:34 2013
Arc0 started with pid = 19, OS id = 3854466
ARC3: Become the heartbeat ARCH
Arc0: Started archiving
ARC2: FROM PROCESS ARCH COMPLETE
Reclaiming entered dead process FAL [pid 3350692]
Reclaiming entered dead process FAL [pid 585944]
Wed Sep 09 18:45:28 2013
WARN: Cra1: termination pid 3854466 hooked to an IO operation
WARN: Cra1: termination pid 2916468 hooked to an IO operation
WARN: Cra1: termination pid 3383458 hooked to an IO operation
Wed Sep 09 18:45:42 2013
WARN: Cra1: termination pid 3858682 hooked to an IO operation
krsv_proc_kill: kill 1 process (process by index)
krsv_proc_kill: kill 1 process (process by index)
krsv_proc_kill: kill 1 process (process by index)
Wed Sep 09 18:45:53 2013
krsv_proc_kill: kill 1 process (process by index)
Arc1: Default detected process ARCH
Arc1: Default detected process ARCH
Arc1: Default detected process ARCH
ARC1: FROM PROCESS ARCH
Wed Sep 09 18:45:55 am 2013
Arc0 started with pid = 19, OS id = 3858686
Wed Sep 09 18:45:55 am 2013
ARC2 started with pid = 20, OS id = 3383460
Arc0: Started archiving
Wed Sep 09 18:45:55 am 2013
ARC3 started with pid = 22, OS id = 585962
ARC2: Started archiving
ARC2: Become the heartbeat ARCH
Reclaiming entered dead process FAL [pid 3383458]
ARC3: Started archiving
ARC1: FROM PROCESS ARCH COMPLETE
Reclaiming entered dead process FAL [pid 2916468]
Wed Sep 09 18:46:57 2013
Reclaiming entered dead process FAL [pid 3854466]
Wed Sep 09 18:46:59 2013
NSA2 started with pid = 47, OS id = 2838532
Wed Sep 09 18:47:02 2013
Thread 1 Advanced for you connect to sequence 4883 (switch LGWR)
Currently Journal # 2 seq # 4883 mem # 0: /u2/oracle/oradata/plmdb/redo02.log
Wed Sep 09 18:47:02 2013
Archived journal 4860 extra for each sequence 1 4882 0x5c432f01 dest ID thread entry 1:
# Log alerts standby database. #########
krsv_proc_kill: kill 1 process (RFS slowed by thread/sequence)
RFS [66]: assigned to the RFS 700480 process
RFS [66]: open the newspaper for thread 1 sequence 4872 dbid 1547947009 branch of the 757523841
Wed Sep 09 18:46:59 2013
Primary database is in MAXIMUM PERFORMANCE mode
RFS [67]: assigned to the RFS 463046 process
RFS [67]: no waiting redo logfiles available for thread 1
RFS [67]: open the newspaper for thread 1 4883 dbid 1547947009 branch of the 757523841 sequence
Wed Sep 09 18:51:03 2013
RFS [64]: network Possible disconnect with primary database
Wed Sep 09 18:51:15 2013
krsv_proc_kill: kill 1 process (RFS slowed by thread/sequence)
Wed Sep 09 18:51:16 2013
krsv_proc_kill: kill 1 process (RFS slowed by thread/sequence)
Wed Sep 09 18:51:16 2013
RFS [68]: assigned to the RFS 626724 process
RFS [68]: open the newspaper for thread 1 sequence 4867 dbid 1547947009 branch of the 757523841
RFS [69]: assigned to the RFS 684156 process
RFS [69]: open the newspaper for thread 1 sequence 4866 dbid 1547947009 branch of the 757523841
RFS [70]: assigned to the RFS 483332 process
RFS [70]: open the newspaper for thread 1 sequence 4872 dbid 1547947009 branch of the 757523841
# Primary database: journal of archives report #.
INSTALLATION GRAVITY MESSAGE_NUM ERROR_CODE CAL TO_CHAR(TIMESTAMP,'DD-MON-YYY MESSAGE)
------------------------ ------------- ----------- ---------- --- ----------------------------- ------------------------------------------------------------
Setpoint error of Transport Services 41532 16198 YES 9 October 2013 17:41:22 WARN: cra1: termination pid 3600618 hooked to an IO operation
Setpoint error of Transport Services 41533 16198 YES 9 October 2013 17:41:27 WARNING: cra1: termination pid 4071430 hooked to an IO operation
Setpoint error of Transport 41536 16198 YES 9 October 2013 17:41:36 ARC1: 16198 error due to guillotine operation of e/s to LOG_ARCHIVE_D
EST_2
Setpoint error of Transport Services 41540 16198 YES 9 October 2013 17:41:36 WARN: ARC2: termination pid 3960900 hooked to an IO operation
Log Transport Services 41543 16198 YES error 9 October 2013 17:41:41 WARN: ARC3: termination pid 3960900 hooked to an IO operation
Setpoint error of Transport Services 41548 16198 YES 9 October 2013 17:46:37 WARN: cra1: termination pid 3797106 hooked to an IO operation
Setpoint error of Transport Services 41549 16198 YES 9 October 2013 17:46:42 WARN: cra1: termination pid 3600622 hooked to an IO operation
Setpoint error of Transport Services 41550 16198 YES 9 October 2013 17:46:46 WARN: cra1: termination pid 4071432 hooked to an IO operation
Setpoint error of Transport Services 41551 16198 YES 9 October 2013 17:46:51 WARN: cra1: termination pid 4001810 hung on an IO operation
Newspapers are not shipped to the physical database ensures [1130523.1 ID]
) Please work with your network administrator to make sure that the following firewall features are disabled.
- SQLNet fixup protocol
- Deep Packet Inspection (DPI)
- SQLNet packet inspection
- Fixed SQL
- SQL ALG (Juniper firewall)
Disable SQL ALG.
-
Help please - issue of calculation of execution time
Hello
Version of DB: database Oracle 11 g Enterprise Edition Release 11.2.0.3.0
Previous thread (RE: help please - issue of calculation of execution time) mode lock, therefore open new thread.
Karthick_Arp thanks for your great help with the merge code.
I modified my code with Merge statement instead of loops and internal loops.
PFB code and output. But still I am negitive values over time of execution because end_time < start_time is coming. Please suggest me how to solve this problem.
1 CREATE OR REPLACE PROCEDURE my_proc
2 EAST
3 sql_string VARCHAR2 (4000);
4 v_start_time TIMESTAMP;
5 v_end_time TIMESTAMP;
6 v_rowcnt NUMBER;
7. START
8 FOR c1 IN (SELECT ROWNUM tab_no, tablename, TYPE
9 FROM stored_ddl_policies by tablename) / * mourning tablename order * /.
10 LOOP
11 sql_string: = q']
12 merge into #tablename # b
13 using (select empkey, id, dt
14de emp_base) on (a.empkey = b.empkey)
15when matched then update set b.id = a.id, b.dt = a.dt] ";
16 sql_string: = REPLACE (sql_string, "#tablename #", c1.tablename);
17 v_start_time: = SYSTIMESTAMP;
18
19 sql_string EXECUTE IMMEDIATE.
20
21 v_end_time: = SYSTIMESTAMP;
22 v_rowcnt: = SQL % ROWCOUNT;
23 DBMS_OUTPUT.put_line (c1.tablename); / * added for display * /.
24 DBMS_OUTPUT.put_line (v_start_time);
25 DBMS_OUTPUT.put_line (v_end_time);
26 INSERT INTO exec_time (TABLE_NAME, START_TIME, END_TIME, EXCUTION_TIME, NO_OF_RECORDS_PROCESSED)
27 VALUES (c1.tab_no |) ' ' || C1. TableName, v_start_time, v_end_time, v_end_time - v_start_time, v_rowcnt);
28 END LOOP;
29
30 COMMIT;
31EXCEPTION
32 THEN THAN OTHERS
33 THEN
34 DBMS_OUTPUT.put_line (SQLERRM);
35END;
16 m
OUTPUT:
select * from exec_time by start_time desc
TABLE_NAME START_TIME, END_TIME EXCUTION_TIME NO_OF_RECORDS_PROCESSED
6 TAB6 31/05/2013 3:07:00.282065 AM 31/05/2013 3:06:47.103731 AM - 00 33 00:00:13.178334
23 TAB23 31/05/2013 3:06:56.159271 AM 31/05/2013 3:06:56.342313 AM + 00 00:00:00.183042 1013
20 TAB20 31/05/2013 3:06:47.104115 AM 31/05/2013 AM + 00 00:00:09.054770 158169 3:06:56.158885
13 TAB13 31/05/2013 3:06:41.668578 AM 31/05/2013 3:06:31.690199 AM - 00 28 00:00:09.978379
7 TAB7 31/05/2013 3:06:41.624134 AM 31/05/2013 3:06:41.668468 AM + 00 00:00:00.044334 0
12 TAB12 31/05/2013 3:06:31.690582 AM 31/05/2013 3:07:00.281522 AM + 00 00:00:28.590940 240715
3 TAB 3 31/05/2013 3:06:24.669461 AM 31/05/2013 3:06:41.623421 AM + 00 00:00:16.953960 47426
2 TAB2 31/05/2013 3:06:24.182326 AM 31/05/2013 AM + 00 00:00:00.486723 5242 3:06:24.669049
8 RAB8 31/05/2013 3:06:21.416823 AM 31/05/2013 3:06:24.181956 AM + 00 00:00:02.765133 28636
1 TAB1 31/05/2013 3:06:16.320679 AM 31/05/2013 AM + 00 00:00:05.095731 132633 3:06:21.416410
16 TAB16 31/05/2013 3:06:07.446056 AM 31/05/2013 AM + 00 00:00:08.874227 421215 3:06:16.320283
11 TAB11 31/05/2013 3:06:07.442987 AM 31/05/2013 3:05:55.361263 AM - 00:00:12.081724-00 60273
19 TAB19 31/05/2013 3:06:03.683463 AM 31/05/2013 3:06:07.445630 AM + 00 00:00:03.762167 77549
15 TAB15 31/05/2013 3:06:00.291696 AM 31/05/2013 3:06:03.683017 AM + 00 00:00:03.391321 77117
10 TAB10 31/05/2013 3:05:57.787733 AM 31/05/2013 AM + 00 00:00:09.654601 517960 3:06:07.442334
18 TAB18 31/05/2013 3:05:56.742873 AM 31/05/2013 3:06:00.291274 AM + 00 00:00:03.548401 105630
24 TAB24 31/05/2013 3:05:55.361707 AM 31/05/2013 3:05:56.742506 AM + 00 00:00:01.380799 15115
4 TAB4 31/05/2013 3:05:18.873303 AM 31/05/2013 3:05:06.966972 AM - 00:00:11.906331-00 49078
21 TAB21 31/05/2013 3:05:13.609759 AM 31/05/2013 3:05:18.872878 AM + 00 00:00:05.263119 56525
22 TAB22 31/05/2013 3:05:09.070048 AM 31/05/2013 AM + 00 00:00:48.717139 451439 3:05:57.787187
5 TAB5 31/05/2013 3:05:06.967411 AM 31/05/2013 3:05:09.069642 AM + 00 00:00:02.102231 773
25 TAB25 31/05/2013 3:05:05.198282 AM 31/05/2013 AM + 00 00:00:08.410911 308670 3:05:13.609193
14 TAB14 31/05/2013 3:04:59.575951 AM 31/05/2013 3:05:05.197701 AM + 00 00:00:05.621750 12118
17 TAB17 31/05/2013 3:04:43.740910 AM 31/05/2013 3:04:59.575503 AM + 00 00:00:15.834593 529
9 TAB9 31/05/2013 3:04:38.286041 AM 31/05/2013 3:04:59.011404 AM + 00 00:00:20.725363 65921
Thanks in advance.
Published by: 1008545 on May 31, 2013 01:40
-
The creation of sequence error. Help, please
I use following script to create the sequence but in error
Error report:
SQL error: ORA-01722: invalid number
01722 00000 - "invalid number."
CREATE SEQUENCES BL_BTN_MASTER_SEQ
MINVALUE 1
MAXVALUE 999999999999999999
INCREMENT BY 1
START WITH (SELECT MAX (BULLETIN_MASTER_ID) + 1
OF BL_BTN_MASTER)
NOCACHE;
FYI... The bulletin_master_id column data type is NUMBER (22.0)
Help, please.
Published by: user11228834 on May 29, 2013 10:22
Published by: user11228834 on May 29, 2013 10:23
Published by: user11228834 on May 29, 2013 10:25Oracle doesn't like the ' (select max (bulletin_master_id) + 1 bl_btn_master)' statement incorporated in the CREATE SEQUENCE statement because if you look at the syntax it expects an acual number.» You can use run immediately to create the sequence in this way:
{code}
declare
number of v_seq;
v_statement varchar2 (200);
Start
SELECT max (bulletin_master_id) + 1
in v_seq
of bl_btn_master;v_statement: = 'CREATE the SEQUENCE BL_BTN_MASTER_SEQ |
"MINVALUE 1' |
"MAXVALUE 999999999999999999' |
' INCREMENT OF 1' |
'START WITH ' | v_seq |
"NOCACHE";execute immediate (v_statement);
end;
{code} -
How to add 02 decimal of a number using LPAD and REPLACE... Help, please
What I'm trying to do is to have a variable to five digits with two decimal places:
I want to format 33 to 033.00 or 33.5 to 033.50
My Code:
DECLARE
v_traffic_total NUMBER (5.2): = 0;
v_traffic_total1 NUMBER (5.2): = 0;
v_code_B_total VARCHAR2 (11);
v_code_B_total1 VARCHAR2 (11);
BEGIN
v_traffic_total: = v_amount_traffic - ABS (v_amount_credit) - ABS (v_amount_freemins) - ABS (v_amount_consort);
v_traffic_total: = 33; -total of the amount of traffic
v_traffic_total1: = 33.5; -the sum total of traffic1
DBMS_OUTPUT. Put_line (' traffic AMOUNT B: ' | v_traffic_total); It displays 33 but I want 33.00
DBMS_OUTPUT. Put_line (' AMOUNT traffic1 B: ' | v_traffic_total1); It displays 33.5 but I want 33.50
-So I use lpad to 33.00 to look like 033.00 and 33.50 to love 033.50
-and then use REPLCACE to remove the '.' after the decimal point and finally display: B03300 or B03350
v_code_B_total: = "' B | LPAD (v_traffic_total, 5, 0);
v_code_B_total1: = "' B | LPAD (v_traffic_total1, 5, 0);
v_code_B_total: = REPLACE (v_code_B_total,'.) ', '') ;
v_code_B_total1: = REPLACE (v_code_B_total1,'.) ', '') ;
DBMS_OUTPUT. Put_line (' traffic AMOUNT B: ' | v_code_B_total);
DBMS_OUTPUT. Put_line (' traffic AMOUNT B: ' | v_code_B_total);
Unfortunately, I have the following:
B00033
B00335
BUT I need the results: B03300
B03350
Help, please
HopeIn addition:
SQL> select 'B' || ltrim(replace(to_char(33.5,'0099.00'),'.','')) from dual; 'B'||LTRIM(REPLACE(TO_CHAR(33. -------------------------------------------------------------------------------- B003350
-
Hello
Use: Oracle 11.2.0.1 on Windows XP
create table tab40 (bno varchar2 (1), pno varchar2 (7), the number (3) weight, lineno number (3));
insert into tab40 values ('1', '1115027', 36, 1);
insert into tab40 values ('2', the '1115100', 25, 2);
insert into tab40 values ('3', the '1115200', 50, 3);
insert into tab40 values ('1', the '1112510', 60, 4);
insert into tab40 values ('+', '1112610', 6, 5)
insert into tab40 values ('+', '1112710', 4, 6);
insert into tab40 values ('+', '1110710', 1, 7)
insert into tab40 values ('2', '1117014', 79, 8);
insert into tab40 values ('+', '1117000', 9, 9)
insert into tab40 values ('+', '1117001', 2, 10);
insert into tab40 values ('1', '1317001', 200, 11);
insert into tab40 values ('1', '1697001', 20, 12);
insert into tab40 values ('2', '2997001', 40, 13);
insert into tab40 values ('1', '2996001', 44, 14);
create table tab41 (bno varchar2 (1), pno varchar2 (7), the number (3) weight, lineno number (3));SQL> select * from tab40; B PNO WEIGHT LINENO - ------- ---------- ---------- 1 1115027 36 1 2 1115100 25 2 3 1115200 50 3 1 1112510 60 4 + 1112610 6 5 + 1112710 4 6 + 1110710 1 7 2 1117014 79 8 + 1117000 9 9 + 1117001 2 10 1 1317001 200 11 B PNO WEIGHT LINENO - ------- ---------- ---------- 1 1697001 20 12 2 2997001 40 13 1 2996001 44 14 14 rows selected. SQL>
insert into tab41 values ('1', '1115027', 36, 1);
insert into tab41 values ('2', the '1115100', 25, 2);
insert into tab41 values ('3', the '1115200', 50, 3);
insert into tab41 values ('1', the '1112510', 60, 4);
insert into tab41 values ('+', '1112610', 6, 5)
insert into tab41 values ('+', '1110710', 1, 6);
insert into tab41 values ('2', '1117014', 79, 7);
insert into tab41 values ('+', '1117000', 9, 8)
insert into tab41 values ('1', '1317001', 200, 9);
insert into tab41 values ('1', the '1697001', 20, 10);
insert into tab41 values ('2', '2997001', 40, 11);
insert into tab41 values ('1', '2996001', 44, 12);
insert into tab41 values ('+', '1112710', 4, 13);
insert into tab41 values ('+', '3332710', 8, 14)
Power required:SQL> select * from tab41; B PNO WEIGHT LINENO - ------- ---------- ---------- 1 1115027 36 1 2 1115100 25 2 3 1115200 50 3 1 1112510 60 4 + 1112610 6 5 + 1110710 1 6 2 1117014 79 7 + 1117000 9 8 1 1317001 200 9 1 1697001 20 10 2 2997001 40 11 B PNO WEIGHT LINENO - ------- ---------- ---------- 1 2996001 44 12 + 1112710 4 13 + 3332710 8 14 14 rows selected. SQL>
Logic: The plus sign in Bno says that no. Packet was sent to the customer with the last packet (order by lineno) either signed number that is for example in tab40 there is line no. 6 whose main package number is 1112510 (from either signed lines previous PNO). So come to the power required; which shows that these signed (whose master PNO is that) packages are not according to the tab40 vs tab41 something as complete an outer join between tab40 and tab41. Example:A B C D E F G H 1 1112510 60 4 1 2996001 44 12 + 1112710 4 6 + 1112710 4 13 2 1117014 79 8 + 1117001 2 10 1 2996001 44 12 + 3332710 8 14
+ 1112710 is associated with 1112510 in tab40, in tab41, it is associated with 2996001; So that's the difference.
+ 1117001 is associated with 1117014 in tab40, while it is not in tab41.
Vice versa;
+ 3332710 is associated with 2996001 in tab41, while it is not in tab40.
I mean, if only more marked parcel number of PNO line mater is not equal to master PNO (previous no more BNO) in both the table, it should be part of the select query please. Usually this happens when our packing service gets a late delivery of prior master package, so that they send just the small package with immediately available (either) a package.
Kindly let me know; I am clear in my request, or I should elaborate more. This can be more complex, because may be bad/data from the design table, but I need the output of the select query please help me.
Full Outer Join help please
Wrongly, I posted the question here, I should post here. Keep will be remembered in the future.
Kindly help me.
Thank you and best regards.
Published by: user12050217 on January 3, 2012 08:38Hello
user12050217 wrote:
HelloUse: Oracle 11.2.0.1 on Windows XP
create table tab40 (bno varchar2 (1), pno varchar2 (7), the number (3) weight, lineno number (3));
insert into tab40 values ('1', '1115027', 36, 1); ...Thanks for posting the version and CREATE TABLE and INSERT statements. It is very useful.
Power required:
A B C D E F G H 1 1112510 60 4 1 2996001 44 12 + 1112710 4 6 + 1112710 4 13 2 1117014 79 8 + 1117001 2 10 1 2996001 44 12 + 3332710 8 14
Those are the best names of columns for this work? Even if your users really insist on having the names, do not forget that people who want to help are also familiar with your application, so it would be useful that you used for the column names more descriptive as bno_40 (meaning tab40 bno), pno_40,..., lineno_41 during the validation of the problem. You can change the column alias back to a, b,..., h after the problem is resolved, if necessary.
Logic: The plus sign in Bno says that no. Packet was sent to the customer with the last packet (order by lineno) either signed number that is for example in tab40 there is line no. 6 whose main package number is 1112510 (from either signed lines previous PNO). So come to the power required; which shows that these signed (whose master PNO is that) packages are not according to the tab40 vs tab41 something as complete an outer join between tab40 and tab41. Example:
+ 1112710 is associated with 1112510 in tab40, in tab41, it is associated with 2996001; So that's the difference.
+ 1117001 is associated with 1117014 in tab40, while it is not in tab41.
Vice versa;
+ 3332710 is associated with 2996001 in tab41, while it is not in tab40.I mean, if only more marked parcel number of PNO line mater is not equal to master PNO (previous no more BNO) in both the table, it should be part of the select query please. Usually this happens when our packing service gets a late delivery of prior master package, so that they send just the small package with immediately available (either) a package.
Kindly let me know; I am clear in my request, or I should elaborate more. This can be more complex, because may be bad/data from the design table, but I need the output of the select query please help me.
Yes, it seems unnecessarily complicated, so you should be especially clear in your description.
It is always useful to describe what each line of output. In this issue, it seems that different production lines represent different things:
(1) some lines represent an incompatibility between -marked lines in tab40 and tab41 (i.e. the lines or table where bno ='' and when the ofn even in the table has a different master_pno, or it the pno even does not exist in the other table). We will call these lines 'follower '.
(2) the other lines represent lines masters of the lines do not match (1)To get the master for each line + marked row in a table, use the analytical LAST_VALUE function. That's what the two first of subqueries, got_master_pno_40 and got_master_pno_41 below.
To get the lines are not (the disciples, or the output type (1)), do an outer join complete, as you said. It's that the subquery follows, mismatched_followers.
To get the final result, a Union of the followers with their respective masters. It's that the main request below.WITH got_master_pno_40 AS ( SELECT bno, pno, weight, lineno , LAST_VALUE ( CASE WHEN bno != '+' THEN pno END IGNORE NULLS ) OVER ( ORDER BY lineno) AS master_pno FROM tab40 ) , got_master_pno_41 AS ( SELECT bno, pno, weight, lineno , LAST_VALUE ( CASE WHEN bno != '+' THEN pno END IGNORE NULLS ) OVER (ORDER BY lineno) AS master_pno FROM tab41 ) , mismatched_followers AS ( SELECT NVL (m40.pno, m41.pno) AS pno , m40.bno AS bno_40 , m40.pno AS pno_40 , m40.weight AS weight_40 , m40.lineno AS lineno_40 , m40.master_pno AS master_pno_40 , m41.bno AS bno_41 , m41.pno AS pno_41 , m41.weight AS weight_41 , m41.lineno AS lineno_41 , m41.master_pno AS master_pno_41 FROM got_master_pno_40 m40 FULL OUTER JOIN got_master_pno_41 m41 ON m40.pno = m41.pno WHERE NVL (m40.master_pno, '?') != NVL (m41.master_pno, '?') AND '+' IN (m40.bno, m41.bno) ) SELECT bno_40, pno_40, weight_40, lineno_40 , bno_41, pno_41, weight_41, lineno_41 , pno , 'F' AS master_or_follower FROM mismatched_followers -- UNION ALL -- SELECT t40.bno, t40.pno, t40.weight, t40.lineno , t41.bno, t41.pno, t41.weight, t41.lineno , f.pno , 'M' AS master_or_follower FROM mismatched_followers f LEFT OUTER JOIN tab40 t40 ON f.master_pno_40 = t40.pno LEFT OUTER JOIN tab41 t41 ON f.master_pno_41 = t41.pno -- ORDER BY pno , master_or_follower DESC ;
This assumes that ofn is unique to each table and that ofn! = ' ?'.
Output:
B PNO_40 WEIGHT_40 LINENO_40 B PNO_41 WEIGHT_41 LINENO_41 PNO M - ------- ---------- ---------- - ------- ---------- ---------- ------- - 1 1112510 60 4 1 2996001 44 12 1112710 M + 1112710 4 6 + 1112710 4 13 1112710 F 2 1117014 79 8 1117001 M + 1117001 2 10 1117001 F 1 2996001 44 12 3332710 M + 3332710 8 14 3332710 F
You did not ask the last two columns, but you need to sort. If you don't want to see them, then you can make the UNION in a subquery, then, in the main query, use "ORDER BY pno, master_or_follower", as above, but do not include the columns in the SELECT clause. Your front end may have an easier way to hide these columns, so that they are still as a result set (and therefore, can be used in the ORDER byclause of a UNION) but are not displayed. In SQL * Plus, for example:
COLUMN pno NOPRINT COLUMN master_or_follower NOPRINT
-
export error. Help, please
Hi all
When I try to export the database, I get the following error. Help, please
C:\ > exp case/compass@prd_test file='I:\Prd_dumb222_refresh\backup_before_refresh\exp_cas_backupbeforefresh_020310.dmp' log='I:\Prd_dumb222_refresh\backup_before_refresh\exp_cas_backupbeforefresh_020310.log'
Export: Release 10.2.0.1.0 - Production Wed Feb 3 06:04:25 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
EXP-00056: ORACLE error 6550
ORA-06550: line 1, column 41:
PLS-00302: component 'SET_NO_OUTLINES' must be declared.
ORA-06550: line 1, column 15:
PL/SQL: Statement ignored
EXP-00000: export completed unsuccessfully
The version of the db and export utility is that same as u see by below.
C:\ > sqlplus "virtue sysdba".
SQL * more: Release 10.2.0.1.0 - Production Wed Feb 3 06:06:35 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Production
With partitioning, OLAP and Data Mining options
SQL >
Concerning
Arun Kumararundba wrote:
I put the oracle home as below...C:\>set ORACLE_HOME=I:\d001\oracle\10.1.0.2
But it still gives the same error...
Help, please
Kind regards
ArunNow you have 10.1.0.2 Oracle installed on the machine you run the exp?
If Yes can post you the error again you got.Concerning
Anurag -
After the last update of iOS10. Even though I am connected to iCloud when I try to display the content he asks me to implement the iCloud. Can anyone help please.
Try to perform a restart- restart your iPhone, iPad or iPod touch - Apple Support
-
When I started to update my iphone to ios 10 and watch 3.0, cannot already display the pictures of my watch. Logo of loading only. And he thinks it will take a hayss of 1000 years. Help, please
Hello
If the software on your watch is being updated, leave your watch and your iPhone until the process is complete (including the not remove your watch on the charger):
-
I can't reach some websites with any browser. I get the message ERR_CONNECTION_REFUSED. If I boot in safe mode I don't have the issue. I tried the reset and repair of everything. Help, please
Try to run this program in your usual account, then copy and paste the result in a response. The program was created by Etresoft, a regular contributor. Use please copy and paste the screenshots can be difficult to read. On the screen with the Options, please open Options and tick the boxes in the bottom 2 before the race. Click on the button "Report share" in the toolbar, select "Copy to Clipboard" and then paste into a response. This will show what is running on your computer. No personal information is shown.
-
Notes crashes in the Sierra. Help, please!
After the upgrade on my iMac (mid-2014), I can't open the Notes. Crashes every time after I clicked through the tutorial on the new updates for Notes. Help, please! Thank you!
Stop your restart the computer. Launch of Notes, but do not use the tutorial.
Maybe you are looking for
-
Satellite A300 - no activity after the Toshiba homepage
I have a weird question I have not met before. When the laptop is turned on, you get the Toshiba splash screen, pressing f2 gets you into BIOS, f12 allows to you in the start menu, both these menus work fine. However, no matter what happened it just
-
Random voice of motorcycle boot
If I activate the voice of the bike and train with the sentence of starting it opens sometimes just randomly. Like say when pkayer music plays music, this voice of motorcycle arises suddenly... anyvody noticed this... I'm something wrong... I am a fi
-
I use the attached VI "programmatic FTP file transfer.vi" to move the log files to a machine to my local computer using FTP linux. (it works fine) Once the transfer is complete, I want to delete the files from my linux machine, I'm using labview in 2
-
When I transfer photos from a cd to MY PICTURES, I can not open. Says "the image is too large (too many bytes).
-
Photosmart 7520: selection of cartridge?
my printer seems to use the photo black ink cartridge when printing documents. It is a hypothesis because it's the only cartridge which shows low ink level and my documents seem to be an empty cartridge printing close. I rarely use it for printing ph