Need help SQL
Hi Friends,
Having a table containing these three values in different records (any combination) for
a single primary id.
Oracle DB 10g EE Release 10.2.0.3.0 - 64bi
EXAMPLE
123 AAA
123 AAA
124 AAA
124 AAA
124 BBB
125 AAA
125 BBB
125 CCCNeed to identify in which group does that primary key belong and I need to assign a value for that.
Currently I have a function for this req and am calling it from my SELECT query and it takes more time.
Can it be done in any other way. Please advice.
Marlon
Hi, If you are using Oracle 11g then, below sql gives your desired output.
with t as
select 123 Val1, 'AAA' Val2 from dual union all
select 123, 'AAA' from dual union all
select 124, 'AAA' from dual union all
select 124, 'AAA' from dual union all
select 124, 'BBB' from dual union all
select 125, 'AAA' from dual union all
select 125, 'BBB' from dual union all
select 125, 'CCC' from dual
select val1,val2,length(val2)-length(replace(val2,','))+1
from
select val1,listagg(val2,',') within group (order by val1) val2
from (select distinct val1,val2 from t)
group by val1)
/If you are working on 9i, u can use the below sql
with t as
select 123 Val1, 'AAA' Val2 from dual union all
select 123, 'AAA' from dual union all
select 124, 'AAA' from dual union all
select 124, 'AAA' from dual union all
select 124, 'BBB' from dual union all
select 125, 'AAA' from dual union all
select 125, 'BBB' from dual union all
select 125, 'CCC' from dual
select val1,val2,length(val2)-length(replace(val2,','))+1
from
select val1,
rtrim (xmlagg (xmlelement (e, val2 ||',')).extract ('//text()'), ',') val2
from (select distinct val1,val2 from t)
group by val1)
/
Similar Messages
-
Need help-SQL with result format suppressing duplicate values
I am trying to write a SQL which would select data from the below tables(in reality i have many other tables also) but I wanted to know how do i get the data in the format given below.
The scenario is :-A training_plan can N no. of OBJECTIVES and EACH objective has N no.of activities
Insert into TEST_TRAINING_PLAN
(TPLAN_ID, TPLAN_NAME, TPLAN_DESC, T_PERSON_ID
Values
('111', 'test_name', 'test_name_desc', '****')
Objectives table:-
Insert into TEST_TRAINING_OBJECTIVE
(T_OBJECTIVE_ID, T_OBJECTIVE_NAME,T_owner)
Values
('10', 'objective1', '1862188559')
Objective and Training Plan relationship table where TPLAN_ID is the foreign key.
Insert into TEST_TP_OBJECTIVE
(TPLAN_TOBJ_ID, TPLAN_ID, T_OBJECTIVE_ID,
REQUIRED_CREDITS)
Values
('1', '111', '10',5)
Objective and Activity relationship table where T_OBJECTIVE_ID is the foreign key from the TEST_TRAINING_OBJECTIVE table.
Insert into TEST_TRAIN_OBJ_ACTIVITY
(TOBJ_TRAIN_ACTIVITY, T_OBJECTIVE_ID, ACTIVITY_ID, IS_REQUIRED, STATUS,
ACTIVITY_TYPE, ITEM_ORDER, IS_PREFERRED)
Values
('1000', '10', 'selfstudy event', SS1, NULL,
'Event', 0, 0);
Insert into TEST_TRAIN_OBJ_ACTIVITY
(TOBJ_TRAIN_ACTIVITY, T_OBJECTIVE_ID, ACTIVITY_ID, IS_REQUIRED, STATUS,
ACTIVITY_TYPE, ITEM_ORDER, IS_PREFERRED)
Values
('1001', '10', 'SQLcourse', 1, NULL,
'Course', 1, 0);
Insert into TEST_TRAIN_OBJ_ACTIVITY
(TOBJ_TRAIN_ACTIVITY, T_OBJECTIVE_ID, ACTIVITY_ID, IS_REQUIRED, STATUS,
ACTIVITY_TYPE, ITEM_ORDER, IS_PREFERRED)
Values
('1002', '10', 'testSQL', 1, NULL,
'test', 2, 0);
COMMIT;
firstname emplid Tplan name Number of activities/credits completed(for TP) Objective Name Number of required activities/Credits (for objective) Number of activities/credits completed(for objective) activity name activity completion status
U1 U1 TP1 5
OBJ1 4 3 C1 PASSED
C2 PASSED
C3 WAIVED
T1 ENROLLED
T2 ENROLLED
OBJ2 3 2
S1 ENROLLED
S2 PASSED
T3 WAIVED
U1 U1 TP2 C4 INPROGRESS
50 OBJ11 50 30 C11 PASSED
**The second row where we have another training_plan record and accordingly all objectivesand their objective.**similarly ,i need to display many Training_plan records in such tabular format.Please help with the SQL query to select and display data in the above format
If you want to suppress duplicate values in some of your results columns
I am using toad 9.1 using Oracle 10g version 2Hi,
You can use the BREAK command to suppress duplicate values.
http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/ch12009.htm#SQPUG030
(scroll down for an example)
It's a 'SQL*Plus-ism', not sure if TOAD's capable to handle it.
Simple example:
HR%xe> break on department_name
HR%xe> select l.department_name
2 , e.last_name
3 , e.first_name
4 from departments l
5 , employees e
6 where e.department_id = l.department_id;
DEPARTMENT_NAME LAST_NAME FIRST_NAME
Executive King Steven
Kochhar Neena
De Haan Lex
IT Hunold Alexander
Ernst Bruce
Austin David
Pataballa Valli
Lorentz Diana
Finance Greenberg Nancy
Faviet Daniel
Chen John
Sciarra Ismael
Urman Jose Manuel
Popp Luis
Purchasing Raphaely Den
Khoo Alexander
Baida Shelli
Tobias Sigal
Himuro Guy
Colmenares Karen
Shipping Weiss Matthew
Fripp Adam
Kaufling Payam
Vollman Shanta
Mourgos Kevin
Nayer Julia
Mikkilineni Irene
Landry James
Public Relations Baer Hermann
Accounting Higgins Shelley
Gietz William
106 rijen zijn geselecteerd. -
Hi,
I have two tables(production & sales). I want to generate monthly statement. The followings are the sample data.
PRODUCTION:
DATE MATERIAL WEIGHT AMOUNT
01/12/2008 Item1 300 6000
03/12/2008 item2 250 3500
07/12/2008 item3 700 6500
12/12/2008 item1 200 4000
20/12/2008 item3 400 9600
25/12/2008 item1 250 5000
Sales:
SAL_Date Sal_Material sal_weight SAL_Amount
12/12/2008 item3 270 2300
15/12/2008 item1 200 4000
20/12/2008 item2 250 3500
20/12/2008 item1 100 2000
23/12/2008 item1 100 2000
27/12/2008 item3 200 3500
I want to generate monthly statement like the following....
Required Report:
Date Production Sales
Weight - Amount Weight - Amount
01/12/2008 300 6000 0 0
02/12/2008 0 0 0 0
03/12/2008 250 3500 0 0
04/12/2008 0 0 0 0
07/12/2008 700 6500 0 0
12/12/2008 200 4000 270 2300
31/12/2008 0 0 0 0
i don't know, how to generate sequential date...
Could you please tell me the query?
Thanks & RegardsSQL> with prod
2 as
3 (
4 select to_date('01/12/2008','dd/mm/yyyy') dt, 'Item1' material, 300 weight, 6000 amount from dual union all
5 select to_date('03/12/2008','dd/mm/yyyy'), 'item2', 250, 3500 from dual union all
6 select to_date('07/12/2008','dd/mm/yyyy'), 'item3', 700, 6500 from dual union all
7 select to_date('12/12/2008','dd/mm/yyyy'), 'item1', 200, 4000 from dual union all
8 select to_date('20/12/2008','dd/mm/yyyy'), 'item3', 400, 9600 from dual union all
9 select to_date('25/12/2008','dd/mm/yyyy'), 'item1', 250, 5000 from dual
10 ), sales
11 as
12 (
13 select to_date('12/12/2008','dd/mm/yyyy') dt, 'item3' material, 270 weight, 2300 amount from dual union all
14 select to_date('15/12/2008','dd/mm/yyyy'), 'item1', 200, 4000 from dual union all
15 select to_date('20/12/2008','dd/mm/yyyy'), 'item2', 250, 3500 from dual union all
16 select to_date('20/12/2008','dd/mm/yyyy'), 'item1', 100, 2000 from dual union all
17 select to_date('23/12/2008','dd/mm/yyyy'), 'item1', 100, 2000 from dual union all
18 select to_date('27/12/2008','dd/mm/yyyy'), 'item3', 200, 3500 from dual
19 ),find_date
20 as
21 (
22 select dt st, last_day(dt) ed
23 from (select distinct trunc(dt,'month') dt from prod
24 union
25 select distinct trunc(dt,'month') dt from sales)
26 ),day_list
27 as
28 (
29 select (level-1)+st dt
30 from find_date
31 connect by level <= (ed - st)+1
32 )
33 select d.dt, t.p_weight, t.p_amount, t.s_weight, t.s_amount
34 from day_list d
35 left join
36 (select decode(p.dt,null,s.dt,p.dt) dt,
37 sum(p.weight) p_weight, sum(p.amount) p_amount, sum(s.weight) s_weight, sum(s.amount) s_amount
38 from prod p
39 full outer join sales s
40 on p.dt = s.dt
41 and p.material = s.material
42 group by decode(p.dt,null,s.dt,p.dt)) t
43 on d.dt = t.dt
44 order by d.dt
45 /
DT P_WEIGHT P_AMOUNT S_WEIGHT S_AMOUNT
01-DEC-08 300 6000
02-DEC-08
03-DEC-08 250 3500
04-DEC-08
05-DEC-08
06-DEC-08
07-DEC-08 700 6500
08-DEC-08
09-DEC-08
10-DEC-08
11-DEC-08
DT P_WEIGHT P_AMOUNT S_WEIGHT S_AMOUNT
12-DEC-08 200 4000 270 2300
13-DEC-08
14-DEC-08
15-DEC-08 200 4000
16-DEC-08
17-DEC-08
18-DEC-08
19-DEC-08
20-DEC-08 400 9600 350 5500
21-DEC-08
22-DEC-08
DT P_WEIGHT P_AMOUNT S_WEIGHT S_AMOUNT
23-DEC-08 100 2000
24-DEC-08
25-DEC-08 250 5000
26-DEC-08
27-DEC-08 200 3500
28-DEC-08
29-DEC-08
30-DEC-08
31-DEC-08
31 rows selected. -
Need Help in Splitting a String Using SQL QUERY
Hi,
I need help in splitting a string using a SQL Query:
String IS:
AFTER PAINT.ACOUSTICAL.1..9'' MEMBRAIN'I would like to seperate this string into multiple lines using the delimeter .(dot)
Sample Output should look like:
SNO STRING
1 AFTER PAINT
2 ACOUSTICAL
3 1
4
5 9" MEMBRAIN
{code}
FYI i am using Oracle 9.2There's this as well:
with x as ( --generating sample data:
select 'AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN' str from dual union all
select 'BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN' str from dual)
select str,
row_number() over (partition by str order by rownum) s_no,
cast(dbms_xmlgen.convert(t.column_value.extract('//text()').getstringval(),1) as varchar2(100)) res
from x,
table(xmlsequence(xmltype('<x><x>' || replace(str,'.','</x><x>') || '</x></x>').extract('//x/*'))) t;
STR S_NO RES
AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN 1 AFTER PAINT
AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN 2 ACOUSTICAL
AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN 3 1
AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN 4
AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN 5 9" MEMBRAIN
BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN 1 BEFORE PAINT
BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN 2 ELECTRIC
BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN 3 2
BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN 4
BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN 5 45 caliber MEMBRAIN
{code} -
Need help in using sleep function in pl/sql
Hi,
need help:
I have a condition where i want to validate total_pass=total_fail and
I want to use the sleep function in a pl/sql where i want to wait for 2 minutes ie.checking
whether total_pass=total_fail based upon class_id .
I have the data in the table as:
CLASS_ID TOT_PASS TOT_FAIL
1 10 10
2 5 4
3 6 6
4 7 5
Any help will be needful for meI'm not quite sure what you are lookg for here, but whatever it is, your code as posted won't do it. You will never break out of the WHILE r_Class.Tot_Pass = r_Class.Tot_Fail loop, since these values will never change because you never get the next record form the cursor.
From your original data, it looks like your cursor will return multiple rows which implies to me that you want to fetch the first row from the cursor, check if tot_pass = tot_fail, if they are equal, sleep for two minutes then get the next row. This does not make sense to me. Once the select in the cursor is executed, the data it returns will not change due to Oracle's read consistency model, so there seems to me no point in the sleep.
The other alternative I can see is that you want to check all the returned rows, and if tot_pass = tot_fail for one of the rows (or possibly for all of the rows), then you want to sleep and try again.
If you can explain in words what it is you are trying to accomplish, someone will be able to point you to a solution.
John -
Need help to redesign legacy SQL Script
Hello Experts,
I have the below code which produces a CREATE TRIGGER statement. as of now this does for updating. I need to re-design this code to add for inserting and deleting as well. I just need help in the structuring wise. I can build the logic for inserting and updating inside. I want to know how i can continue to get for "inserting" and "deleting" as well.
you will understand my question better if you go through main code, present output and required output format below.
I know this is a bad design first of all. but the below code is a legacy one. so i cant change the entire structure of the code :-( all i can do is to continue designing it to add new changes. Hence sought help from you all.
please help
SQL CODE:
WITH audit_tables
AS
(SELECT object_name,
MIN (column_id) min_col,
MAX (column_id) max_col
FROM user_objects o,
user_tab_columns c
WHERE o.object_name = 'CHR_VAL_DESC_A_T'
AND o.object_name = c.table_name
GROUP BY object_name
SELECT txt
FROM (
SELECT ' CREATE OR REPLACE TRIGGER ' || REPLACE(object_name,'_A_T') || '_ADT_TRG' || CHR(13) ||
' AFTER INSERT ' || CHR(13) ||
' OR UPDATE ' || CHR(13) ||
' OR DELETE ' || CHR(13) ||
' ON ' || REPLACE(object_name,'_A_T','_T') || CHR(13) ||
' FOR EACH ROW ' || CHR(13) ||
' DECLARE ' || CHR(13) ||
' BEGIN ' || CHR(13) ||
' IF updating THEN ' || CHR(13) ||
' INSERT INTO ' || object_name || CHR(13) ||
' (' txt, object_name, 1 disp_order, 0 column_id
FROM audit_tables
UNION ALL
SELECT txt, object_name, disp_order, column_id
FROM (SELECT
CASE
WHEN max_col = column_id THEN
' '||column_name
ELSE
' '||column_name || ','
END AS txt, object_name, 2 disp_order, column_id
FROM audit_tables t,
user_tab_columns C
WHERE c.table_name = t.object_name
ORDER BY c.column_id ASC)
UNION ALL
SELECT ' )' || CHR(13) ||
' VALUES ' || CHR(13) ||
' (', object_name, 3 disp_order, 0
FROM audit_tables t
UNION ALL
SELECT txt, object_name, disp_order, column_id
FROM (SELECT
CASE
WHEN max_col = column_id THEN
CASE
WHEN SUBSTR(column_name,1,2) = 'N_' THEN
' :NEW.'||decode(substr(column_name,1,2),'N_',substr(column_name,3))||');'
WHEN SUBSTR(column_name,1,2) = 'O_' THEN
' :OLD.'||decode(substr(column_name,1,2),'O_',substr(column_name,3))||');'
WHEN min_col = column_id THEN
' 1'
WHEN column_id = 2 THEN
' ''I'''
WHEN column_id = 3 THEN
' SYSDATE'
ELSE
' :NEW.'||column_name||');'
END
ELSE
CASE
WHEN SUBSTR(column_name,1,2) = 'N_' THEN
' :NEW.'||decode(substr(column_name,1,2),'N_',substr(column_name,3))||','
WHEN SUBSTR(column_name,1,2) = 'O_' THEN
' :OLD.'||decode(substr(column_name,1,2),'O_',substr(column_name,3))||','
WHEN min_col = column_id THEN
' 1'||','
WHEN column_id = 2 THEN
' ''I'''||','
WHEN column_id = 3 THEN
' SYSDATE' ||','
ELSE
' :NEW.'||column_name||','
END
END AS txt,object_name, 4 disp_order, column_id
FROM audit_tables t,
user_tab_columns c
WHERE c.table_name = t.object_name
ORDER BY c.column_id ASC)
UNION ALL
SELECT 'END '||REPLACE(object_name,'_A_T') || '_ADT_TRG;' || CHR(13),
object_name, 5 disp_order, 0
FROM audit_tables)
ORDER BY object_name, disp_order, column_id
PRESENT OUTPUT:
CREATE OR REPLACE TRIGGER CHR_VAL_DESC_ADT_TRG
AFTER INSERT
OR UPDATE
OR DELETE
ON CHR_VAL_DESC_T
FOR EACH ROW
DECLARE
BEGIN
IF updating THEN
INSERT INTO CHR_VAL_DESC_A_T
TXN_ID,
TXN_TYP,
ADT_DTTM,
CHR_VAL_DESC_ID,
CHR_VAL_ID,
LANG_ID,
DESC_ID,
O_CHR_VAL_DESC,
N_CHR_VAL_DESC,
O_TRANS_STATE,
N_TRANS_STATE,
CRTD_BY,
CRTD_DTTM,
O_UPD_BY,
N_UPD_BY,
O_UPD_DTTM,
N_UPD_DTTM,
O_LOCK_NUM,
N_LOCK_NUM
VALUES
1,
'I',
SYSDATE,
:NEW.CHR_VAL_DESC_ID,
:NEW.CHR_VAL_ID,
:NEW.LANG_ID,
:NEW.DESC_ID,
:OLD.CHR_VAL_DESC,
:NEW.CHR_VAL_DESC,
:OLD.TRANS_STATE,
:NEW.TRANS_STATE,
:NEW.CRTD_BY,
:NEW.CRTD_DTTM,
:OLD.UPD_BY,
:NEW.UPD_BY,
:OLD.UPD_DTTM,
:NEW.UPD_DTTM,
:OLD.LOCK_NUM,
:NEW.LOCK_NUM);
END CHR_VAL_DESC_ADT_TRG;
REQUIRED OUTPUT FORMAT:
CREATE OR REPLACE TRIGGER TRIGGER_NAME
AFTER INSERT
OR UPDATE
OR DELETE
ON TABLE_NAME
FOR EACH ROW
DECLARE
BEGIN
IF updating THEN
INSERT TABLE_NAME
list of column names
VALUES
IF inserting THEN
INSERT TABLE_NAME
list of column names
VALUES
IF deleting THEN
INSERT TABLE_NAME
list of column names
VALUES
END TRIGGER_NAME;can anyone please help?
i tried adding with inserting and updating also..but when i tried to add deleting part the final output not comes in proper structure.
WITH audit_tables
AS
(SELECT object_name,
MIN (column_id) min_col,
MAX (column_id) max_col
FROM user_objects o,
user_tab_columns c
WHERE o.object_name IN ('CHR_VAL_DESC_A_T', 'CHR_VAL_A_T')
AND o.object_name = c.table_name
GROUP BY object_name
SELECT txt
FROM (
SELECT ' CREATE OR REPLACE TRIGGER ' || REPLACE(object_name,'_A_T') || '_ADT_TRG' || CHR(13) ||
' AFTER INSERT ' || CHR(13) ||
' OR UPDATE ' || CHR(13) ||
' OR DELETE ' || CHR(13) ||
' ON ' || REPLACE(object_name,'_A_T','_T') || CHR(13) ||
' FOR EACH ROW ' || CHR(13) ||
' DECLARE ' || CHR(13) ||
' BEGIN ' || CHR(13) ||
*' IF inserting THEN '* || CHR(13) ||
' INSERT INTO ' || object_name || CHR(13) ||
' (' txt, object_name, 1 disp_order, 0 column_id
FROM audit_tables
UNION ALL
SELECT txt, object_name, disp_order, column_id
FROM (SELECT
CASE
WHEN max_col = column_id THEN
' '||column_name
ELSE
' '||column_name || ','
END AS txt, object_name, 2 disp_order, column_id
FROM audit_tables t,
user_tab_columns C
WHERE c.table_name = t.object_name
ORDER BY c.column_id ASC)
UNION ALL
SELECT ' )' || CHR(13) ||
' VALUES ' || CHR(13) ||
' (', object_name, 3 disp_order, 0
FROM audit_tables t
UNION ALL
SELECT txt, object_name, disp_order, column_id
FROM (SELECT
CASE
WHEN max_col = column_id THEN
CASE
WHEN SUBSTR(column_name,1,2) = 'N_' THEN
' :NEW.'||decode(substr(column_name,1,2),'N_',substr(column_name,3))||');'
WHEN SUBSTR(column_name,1,2) = 'O_' THEN
' NULL'||');'
WHEN min_col = column_id THEN
' 1'
WHEN column_id = 2 THEN
' ''I'''
WHEN column_id = 3 THEN
' SYSDATE'
ELSE
' :NEW.'||column_name||');'
END
ELSE
CASE
WHEN SUBSTR(column_name,1,2) = 'N_' THEN
' :NEW.'||decode(substr(column_name,1,2),'N_',substr(column_name,3))||','
WHEN SUBSTR(column_name,1,2) = 'O_' THEN
' NULL'||','
WHEN min_col = column_id THEN
' 1'||','
WHEN column_id = 2 THEN
' ''I'''||','
WHEN column_id = 3 THEN
' SYSDATE' ||','
ELSE
' :NEW.'||column_name||','
END
END AS txt,object_name, 4 disp_order, column_id
FROM audit_tables t,
user_tab_columns c
WHERE c.table_name = t.object_name
ORDER BY c.column_id ASC)
UNION ALL
SELECT txt, object_name, disp_order, column_id
FROM(SELECT *' ELSIF updating THEN '* || CHR(13) ||
' INSERT INTO ' || object_name || CHR(13) ||
' (' txt, object_name, 5 disp_order, 0 column_id
FROM audit_tables
UNION ALL
SELECT txt, object_name, disp_order, column_id
FROM (SELECT
CASE
WHEN max_col = column_id THEN
' '||column_name
ELSE
' '||column_name || ','
END AS txt, object_name, 6 disp_order, column_id
FROM audit_tables t,
user_tab_columns C
WHERE c.table_name = t.object_name
ORDER BY c.column_id ASC)
UNION ALL
SELECT ' )' || CHR(13) ||
' VALUES ' || CHR(13) ||
' (', object_name, 7 disp_order, 0
FROM audit_tables t
UNION ALL
SELECT txt, object_name, disp_order, column_id
FROM (SELECT
CASE
WHEN max_col = column_id THEN
CASE
WHEN SUBSTR(column_name,1,2) = 'N_' THEN
' :NEW.'||decode(substr(column_name,1,2),'N_',substr(column_name,3))||');'
WHEN SUBSTR(column_name,1,2) = 'O_' THEN
' :OLD.'||decode(substr(column_name,1,2),'O_',substr(column_name,3))||');'
WHEN min_col = column_id THEN
' 1'
WHEN column_id = 2 THEN
' ''U'''
WHEN column_id = 3 THEN
' SYSDATE'
ELSE
' :NEW.'||column_name||');'
END
ELSE
CASE
WHEN SUBSTR(column_name,1,2) = 'N_' THEN
' :NEW.'||decode(substr(column_name,1,2),'N_',substr(column_name,3))||','
WHEN SUBSTR(column_name,1,2) = 'O_' THEN
' :OLD.'||decode(substr(column_name,1,2),'O_',substr(column_name,3))||','
WHEN min_col = column_id THEN
' 1'||','
WHEN column_id = 2 THEN
' ''U'''||','
WHEN column_id = 3 THEN
' SYSDATE' ||','
ELSE
' :NEW.'||column_name||','
END
END AS txt,object_name, 8 disp_order, column_id
FROM audit_tables t,
user_tab_columns c
WHERE c.table_name = t.object_name
ORDER BY c.column_id ASC)
UNION ALL
SELECT 'END IF;' || CHR(13) ||
'END '||REPLACE(object_name,'_A_T') || '_ADT_TRG;' || CHR(13),
object_name, 9 disp_order, 0
FROM audit_tables)
ORDER BY object_name, disp_order, column_id) -
NEED HELP IN SQL HOMEWORK PROBLEMS
I NEED HELP IN MY SQL HOMEWORK PROBLEMS....
I CAN SEND IT VIA EMAIL ATTACHMENT IN MSWORD....Try this:
SELECT SUBSTR( TN,
DECODE(LEVEL, 1, 1, INSTR(TN, '#', 1, LEVEL-1) + 1),
DECODE( INSTR(TN, '#', 1, LEVEL) , 0 ,
LENGTH(TN) + 1, INSTR(TN, '#', 1, LEVEL) )
- DECODE(LEVEL, 1, 1, INSTR(TN, '#', 1, LEVEL-1 ) + 1)
) xxx
FROM (
SELECT '234123#1254343#909823#908232#12345' TN FROM DUAL
CONNECT BY LEVEL <= LENGTH(TN) - LENGTH(REPLACE(TN,'#')) + 1
XXX
234123
1254343
909823
908232
12345
SELECT regexp_substr(tn, '[^#]+', 1, level) xx
FROM (
SELECT '234123#1254343#909823#908232#12345' TN FROM DUAL
CONNECT BY LEVEL <= LENGTH(TN) - LENGTH(REPLACE(TN,'#')) + 1
XX
234123
1254343
909823
908232
12345 -
Hi,
From the SQL statement below, i need help in explaining what does the line "WHERE ( lims_sys.result.result_template_id = lims_sys.result_template_limit.result_template_id (+))" do?
This statement was written by a vendor and now i have problem displaying some new data. Only a portion of what i need is displayed.
SELECT "LIMS_SYS"."RESULT"."DESCRIPTION",
"LIMS_SYS"."RESULT_TEMPLATE_LIMIT"."NUMERIC_LIMIT",
"LIMS_SYS"."RESULT"."FORMATTED_RESULT",
"LIMS_SYS"."RESULT"."CONCLUSION",
"LIMS_SYS"."RESULT_USER"."U_RESULT_SEQUENCE" ,
"LIMS_SYS"."RESULT"."RESULT_ID"
FROM "LIMS_SYS"."RESULT",
"LIMS_SYS"."RESULT_TEMPLATE_LIMIT",
"LIMS_SYS"."RESULT_USER",
"LIMS_SYS"."ALIQUOT",
"LIMS_SYS"."SAMPLE",
"LIMS_SYS"."SDG",
"LIMS_SYS"."TEST"
WHERE ( lims_sys.result.result_template_id = lims_sys.result_template_limit.result_template_id (+)) and
( "LIMS_SYS"."RESULT"."RESULT_ID" = "LIMS_SYS"."RESULT_USER"."RESULT_ID" ) and
( "LIMS_SYS"."SDG"."SDG_ID" = "LIMS_SYS"."SAMPLE"."SDG_ID" ) and
( "LIMS_SYS"."SAMPLE"."SAMPLE_ID" = "LIMS_SYS"."ALIQUOT"."SAMPLE_ID" ) and
( "LIMS_SYS"."ALIQUOT"."ALIQUOT_ID" = "LIMS_SYS"."TEST"."ALIQUOT_ID" ) and
( "LIMS_SYS"."TEST"."TEST_ID" = "LIMS_SYS"."RESULT"."TEST_ID" ) and
( ( LIMS_SYS."SDG"."SDG_ID" = :sdg_id ) AND
( LIMS_SYS."RESULT"."STATUS" <> 'X' ) AND
( LIMS_SYS."RESULT"."REPORTED" = 'T' ) AND
( LIMS_SYS."RESULT_USER"."U_RESULT_CATEGORY" in ( 'Metal' , 'Mean Metal', 'Range Metal')) )
Thanks for all your help.Hi,
After WHERE .......... is indicates an OUTER Join condition.
In this type of join, system retrieves the data for matched and
as well as unmatched.
Example:
EMP table have a column DEPTNO with the data 10, 20, 30 (total rows=14)
DEPT table have a column DEPTNO with the data 10, 20, 30, 40, 50 (total rows=5)
If the WHERE clause contained EMP.DEPTNO(+) = DEPT.DEPTNO
then the output contain the data relative to 10, 20, 30, 40, 50 (total rows = 16)
i.e. 14 rows (with matching data) and 2 rows (with unmatching data)
Regards,
Sailaja -
Need Help/Advice with Photo Web Gallery coming from SQL Database
This is my first attempt at a database driven website. I assume what I am trying to accomplish should be fairly easy for more experienced but I am stuck at this point.
First, let me explain what I am trying to accomplish.
I want to create a thumbnail photo gallery displayed in columns and rows. I want to be able to hover over or click on the thumbnail image and have a lightbox script display the image over the thumb page. I am developing locally right now with intent to upload to the hosting site upon completion.
I am developing with ASP vbScript pages. I have an SQL database where the paths to the image thumbnails and pictures are stored in a table. On the gallery page, I have created a div tag to hold my image recordset. Within this div, I have inserted 3 absolute positioned divs to hold the pictureID, the pictureName and the image inserted as a datasource. I then inserted the information from the bindings panel of my recordset. Last, I used a horizontal looper extension from Tom Muck to get the thumbnails to display in columns and rows. Everything works up to this point just fine.
Now, I want to be able to hover or click on a thumnail image and have it displayed in a lightbox. I downloaded and used a javascript called Lightbox 2 which contains 3 javascript files and a css stylesheet. I inserted the files into the head tag like instructed to but could not get things to work properly. Here is where I need help. Currently, I am clicking on the thumbImage binding within the image Div and creating a link holder. I am then binding the larger pictureImage to it with the a.href selected in the bind to. I am then adding the command to call the lightbox javascript. Now, when I test my page, my thumbnail images do not show up (my alt text does in its place) but the links are in place and you can click on the alt text and it will return the correct larger image, but not in the lightbox, just in a new window with no styles.
Am I going about this correctly? Can you use lightbox scripts with data-driven galleries? Does anybody have any suggestions of what I may be doing wrong or missing? Are there better ways to go about accomplishing this?
Any help would be appreciated as this dynamic data thing has my head spinning. Although I know a database is needed to simplify the update and maintenance of the photos while allowing them to be searchable by keywords and tags also set up in the database.
ThanksAs I explained, I am developing locally a the moment. I will see about getting the databased moved up to the hosting server and then provide a link for an example.
In the mean time, can you or anyone else explain a way that you would go about displaying an image thumbnail photo gallery laid out in rows / columns, with any lighbox script that would overlay the larger image over the existing page instead of opening a new browser window?
I don't have to use the method I tried to describe.
In all of the lightbox examples I have looked at thus far, they give instructions on how to append that javascript to a single static image or a group of static images, not images from a datasource. That is where I am getting confused.
Don't know if this will help or not but please see code below:
Javascript and CSS positioned in head tag
<!--beginning of lightbox script with css -->
<link href="CSS/lightbox.css" rel="stylesheet" type="text/css" />
<script src="Scripts/protype.js" type="text/javascript"></script>
<script src="Scripts/scriptaculous.js?load=effects,builder" type="text/javascript"></script>
<script src="Scripts/lightbox.js" type="text/javascript"></script>
<!--end of lightbox script with css -->
Calling for javascript in the galleryimage div when hovering over thumbnail image
<!--beginning of gallery div -->
<div id="gallery">
<p>
<!--beginning of galleryImage div -->
</p>
<table width="400" border="0" align="center" id="galleryNav2">
<tr>
<td width="100" align="center"><% If MM_offset <> 0 Then %>
<a href="<%=MM_moveFirst%>">First</a>
<% End If ' end MM_offset <> 0 %></td>
<td width="100" align="center"><% If MM_offset <> 0 Then %>
<a href="<%=MM_movePrev%>">Previous</a>
<% End If ' end MM_offset <> 0 %></td>
<td width="100" align="center"><% If Not MM_atTotal Then %>
<a href="<%=MM_moveNext%>">Next</a>
<% End If ' end Not MM_atTotal %></td>
<td width="100" align="center"><% If Not MM_atTotal Then %>
<a href="<%=MM_moveLast%>">Last</a>
<% End If ' end Not MM_atTotal %></td>
</tr>
</table>
<p> </p>
<table align="center" id="HorzLooper">
<%
startrw = 0
endrw = HLooper1__index
numberColumns = 5
numrows = 5
while((numrows <> 0) AND (Not rs_ssfGallery.EOF))
startrw = endrw + 1
endrw = endrw + numberColumns
%>
<tr align="center" valign="top">
<%
While ((startrw <= endrw) AND (Not rs_ssfGallery.EOF))
%>
<td><div id="galleryImage">
<div id="galleryThumb"><a href="images/pic/<%=(rs_ssfGallery.Fields.Item("picture_url").Value)%>"rel="lightbox"><img src="images/thumb/<%=(rs_ssfGallery.Fields.Item("thumb_url").Value)%>" alt="<%=(rs_ssfGallery.Fields.Item("alt_url").Value)%>" /></a></div>
<div id="galleryImageID"><%=(rs_ssfGallery.Fields.Item("picture_ID").Value)%></div>
<div id="galleryImageFamily"><%=(rs_ssfGallery.Fields.Item("family").Value)%></div>
</div></td>
<%
startrw = startrw + 1
rs_ssfGallery.MoveNext()
Wend
%>
</tr>
<%
numrows=numrows-1
Wend
%>
</table>
<p> </p>
<table width="400" border="0" align="center" id="galleryNav">
<tr>
<td width="100" align="center"><% If MM_offset <> 0 Then %>
<a href="<%=MM_moveFirst%>">First</a>
<% End If ' end MM_offset <> 0 %></td>
<td width="100" align="center"><% If MM_offset <> 0 Then %>
<a href="<%=MM_movePrev%>">Previous</a>
<% End If ' end MM_offset <> 0 %></td>
<td width="100" align="center"><% If Not MM_atTotal Then %>
<a href="<%=MM_moveNext%>">Next</a>
<% End If ' end Not MM_atTotal %></td>
<td width="100" align="center"><% If Not MM_atTotal Then %>
<a href="<%=MM_moveLast%>">Last</a>
<% End If ' end Not MM_atTotal %></td>
</tr>
</table>
<!--end of galleryImage div -->
</div>
<!--end of gallery div -->
Thanks for any help or suggestions. -
I'm new to SQL Server Integration Services and I need help on how to begin learning SSIS. Is there any training for it besides msdn?
Check this thread where people have already given their suggestion on learning SSIS
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/f2cc1cf3-204d-454a-a189-47df87a3aa23/i-want-to-learn-ssis?forum=sqlintegrationservices
I would suggest to go for You tube videos (type learn SSIS or begin SSIS step by step) you will get lot of good tutorials to start with.
Happy Learning!!
If this post answers your query, please click "Mark As Answer" or "Vote as Helpful". -
I need help on This SQL problem ASAP :)
Hi All,
I need help on this....
I have a table...
Say table name: one
with these values
premnum status
1234 C
1234 F
1234 P
1234 F
5678 C
5678 F
5678 P
9112 C
9112 F
9112 P
9112 F
3456 C
3456 F
3456 P
7890 C
7890 P
7890 F
Now, I want to output only those premnum with status = 'C' and those premnum with Status 'F' having a count > 1 (with two status = 'F')
So the output would be something like this
premnum status
1234 C
1234 F
1234 F
5678 C
9112 C
9112 F
9112 F
3456 C
7890 C
I really need help on this asap...
I need the SQL statement on this....
Thank you in advance. :)
Edited by: 804697 on Oct 23, 2010 9:45 PMHi,
you can use the following query.
CREATE TABLE PREM_TEST ( premnum NUMBER , STATUS VARCHAR2(1));
INSERT INTO PREM_TEST VALUES(1234 ,'C');
INSERT INTO PREM_TEST VALUES(1234 ,'F');
INSERT INTO PREM_TEST VALUES(1234 ,'P');
INSERT INTO PREM_TEST VALUES(1234 ,'F');
INSERT INTO PREM_TEST VALUES(5678 ,'C');
INSERT INTO PREM_TEST VALUES(5678 ,'F');
INSERT INTO PREM_TEST VALUES(5678 ,'P');
INSERT INTO PREM_TEST VALUES(9112 ,'C');
INSERT INTO PREM_TEST VALUES(9112 ,'F');
INSERT INTO PREM_TEST VALUES(9112 ,'P');
INSERT INTO PREM_TEST VALUES(9112 ,'F');
INSERT INTO PREM_TEST VALUES(3456 ,'C');
INSERT INTO PREM_TEST VALUES(3456 ,'F');
INSERT INTO PREM_TEST VALUES(3456 ,'P');
INSERT INTO PREM_TEST VALUES(7890 ,'C');
INSERT INTO PREM_TEST VALUES(7890 ,'P');
INSERT INTO PREM_TEST VALUES(7890 ,'F');
SELECT PREMNUM , STATUS
FROM PREM_TEST
WHERE STATUS = 'C'
OR (PREMNUM , STATUS ) IN ( SELECT PREMNUM , STATUS
FROM PREM_TEST
WHERE STATUS = 'F'
GROUP BY PREMNUM , STATUS
HAVING COUNT(*) > 1
PREMNUM S
1234 C
1234 F
1234 F
5678 C
9112 C
9112 F
9112 F
3456 C
7890 C
9 rows selected. -
Need help with SQL Query with Inline View + Group by
Hello Gurus,
I would really appreciate your time and effort regarding this query. I have the following data set.
Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*20.00*-------------19
1234567----------11223--------------7/5/2008-----------Adjustment for bad quality---------44345563------------------A-----------------10.00------------19
7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765--------------------I---------------------30.00-------------19
Please Ignore '----', added it for clarity
I am trying to write a query to aggregate paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number. When there are no multiple records I want to display the respective Description.
The query should return the following data set
Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*10.00*------------19
7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765-------------------I---------------------30.00--------------19
The following is my query. I am kind of lost.
select B.Description, A.sequence_id,A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
from (
select sequence_id,check_date, check_number, invoice_number, sum(paid_amount) amount, vendor_number
from INVOICE
group by sequence_id,check_date, check_number, invoice_number, vendor_number
) A, INVOICE B
where A.sequence_id = B.sequence_id
Thanks,
NickIt looks like it is a duplicate thread - correct me if i'm wrong in this case ->
Need help with SQL Query with Inline View + Group by
Regards.
Satyaki De. -
Need help pl/sql function body returning SQL query - Reports
I need help with Grouping by on a report that I developed in my application.
I have posted my Code in
Apex.oracle.com
workspace : c a s e _ m a n a g e m e n t
User Id : public
Password : public
I need help on Page 38 Reports.
I get blank lines when I do break by first , second and third columns on the reports attribute.
So I think I have to write "group by " or Distinct in side the SQL query. But not sure how to do it there.
Thank youIs this an APEX question, then try here:
Oracle Application Express (APEX)
Is this an Oracle Reports question, then try here:
Reports
Is this an SQL question:
Please provide sample data and expected output. Also please show what you have tried already. -
I am using Sybase as my back end database. I need help on my SQL statement regarding datetime. The datetime is store as a 9 digit integer in the database (...I believe it is a Decimal(30,6) format, let me know if I am wrong).
If I do this, "select * from mytable;" It works out fine (except I don't know what the date means e.g. 998919534)
If I do this, "select * from mytable where datetime_col < '9/5/2002' ; I got an error. I even tried '9/5/02 11:00 000 am' but it didn't help.
How do I specify a date or datetime in my query?
Thanks in advance.I execute the sql statement
select * from mytable where datetim_col < convert(datetime, '3/4/2002', 101) ;
I got mix result. I got an error message "cannot convert 10375584 to a date.
Yet, he statistics window of the I-sql says
"estimated 493 rows in query (I/O estimate 87)
PLan> mytable (seq)"
It looks like I my the SQL statement is correct and then the system can't display it in the Data window.
Any thought ? -
Hi,
Need help to write sql statement.
create table t_dt ( dt_start date, dt_end date, amount number);
insert into t_dt values('1-Jan-10','10-Feb-10',12);
insert into t_dt values('11-Feb-10','10-Mar-10',10);
insert into t_dt values('11-Mar-10','20-Apr-10',8);
insert into t_dt values('21-Apr-10','28-Jun-10',10);
insert into t_dt values('29-Jun-10','20-Sep-10',10);
insert into t_dt values('21-Sep-10','10-Oct-10',10);
insert into t_dt values('11-Oct-10','31-Dec-10',8);
insert into t_dt values('1-Jan-11','10-Feb-11',8);
insert into t_dt values('11-Feb-11','10-Mar-11',7);
insert into t_dt values('11-Mar-11','20-Apr-11',6);
insert into t_dt values('21-Apr-11','28-Jun-11',6);
insert into t_dt values('29-Jun-11','20-Sep-11',6);
insert into t_dt values('21-Sep-11','10-Oct-11',4);
insert into t_dt values('11-Oct-11','31-Dec-11',8);
Result should be like below..
dt_start dt_end Amount
1-Jan-10 10-Feb-10 12
11-Feb-10 10-Mar-10 10
11-Mar-10 20-Apr-10 8
21-Apr-10 10-Oct-10 10
11-Oct-10 10-Feb-11 8
11-Feb-11 10-Mar-11 7
11-Mar-11 20-Sep-11 6
21-Sep-11 10-Oct-11 4
11-Oct-11 31-Dec-11 8
Just to explain the example, take a row with start date as 21-Apr-10 in the above insert statements, since it has the same amount for next two rows (i.e. with start date '29-Jun-10' and '21-Sep-10') these 3 rows should be converted to represent only 1 row in the result and the start date and end date should be changed per the result shown above.
Thanks.Hello
I think this gives yuo what you need....
SELECT
MIN(dt_start),
MAX(dt_end),
amount
FROM
( SELECT
dt_start,
dt_end,
MAX(marker) OVER(ORDER BY dt_start) marker,
amount
FROM
Select
dt_start,
dt_end,
amount,
CASE
WHEN LAG(amount) OVER(ORDER BY dt_start) <> amount THEN
ROW_NUMBER() OVER(ORDER BY dt_start)
END marker
from t_dt
GROUP BY
amount,
marker
order by
MIN(dt_start)
MIN(DT_START) MAX(DT_END) AMOUNT
01-JAN-2010 00:00:00 10-FEB-2010 00:00:00 12
11-FEB-2010 00:00:00 10-MAR-2010 00:00:00 10
11-MAR-2010 00:00:00 20-APR-2010 00:00:00 8
21-APR-2010 00:00:00 10-OCT-2010 00:00:00 10
11-OCT-2010 00:00:00 10-FEB-2011 00:00:00 8
11-FEB-2011 00:00:00 10-MAR-2011 00:00:00 7
11-MAR-2011 00:00:00 20-SEP-2011 00:00:00 6
21-SEP-2011 00:00:00 10-OCT-2011 00:00:00 4
11-OCT-2011 00:00:00 31-DEC-2011 00:00:00 8
9 rows selected.HTH
David
Edited by: Bravid on Feb 23, 2012 12:08 PM
Beaten to it by Frank! :-)
Maybe you are looking for
-
Vertical text in jTable headers
Hi, I have got a jTable with quite a bit of columns in it. Is there any way I can write the text - vertically in the header (first) row. Please let me know if you have got any suggestions. Thanks. halosys.
-
Internal DVD disappears including from ATA and Burning in Mac info
I have an open ticket on this issue, my internal DVD appears and disappears. I'm not sure if this is a loose internal connection or a firmware issue. If it is a loose connection, I guess that I will have to send it back to Apple for repair. I underst
-
Hello Every One, I created an Info-set and attached the user group to it. Now when the user uses this query, he should only be able pull the data for the organization to which he belongs. For example, if he belongs to company code 1000, he should o
-
Follow on documents for SC in ECS scenario in SRM 5.0
Hi all, We are on SRM 5.0,ECS.Is it possible that we can have the PO created,Invoice posted and then GR done in SRM?How is this sequence determined and what are the relevat settings to restrict this...i.e. I would like to have the PO done and then w/
-
Having problem with the sync on iPhone 6, anyone know the solution
Why is iPhone 6 taking so long to sync?