JOIN the SQL clause
HelloI have a small question:
INNER JOIN can be written with just the keyword JOIN?
For example,.
INNER JOIN table_b b ON a.col = b.col
OR
JOIN table_b b ON a.col = b.col
Thank you
Yes it is JOIN table_b b WE a.col = b.col or INNER JOIN table_b b ON a.col = b.col
Published by: orant575 on June 28, 2009 13:27
Tags: Database
Similar Questions
-
any case when and the sql clause
Hello:
What follows is my sql clause:
SELECT T.*, b.name
OF dbtest1 t
LEFT OUTER JOIN dbtest b ON t.NO = b.empno
WHERE t.ChineseName like '% "| : ChineseName | ' %' AND b.name like "%" | : name | » %'
ORDER BY t.ChineseName
The main problem is that I want to check the b.name if it is null, it can be passed as function NVL, so I try using case when, but it does not work.
When there are the b.name in where clause, the columns of result will not include data without b.name (or implies the b.name is NULL); And that
the result data are not entirely accurate.
is it possible to use the case when it is implemented in the following code snippet:
-case when b.name is not NULL then b.name like "%" | : name | » %'
Else b.name = NULL (b.name = b.name does not seem to work on the analysis of data zero)
end
Thank you very much.962769 wrote:
The main problem is the table is the form of the cross, and the like clause will filter the
data without a name. Basically, it should show the empty columns, however, it won't.
so, when I test the sql code, I fhound Like "%" | b.Name | ' %' will not get the data when the original dbtest1 table data
has no id corresponding to the BD test. It seems pointless to go the LEFT OUTER JOIN.Thank you
WHERE t.ChineseName like '%'||:ChineseName||'%' AND ( b.name like '%'||:name||'%' or b.empno is null )
-
outer join on query with the GOLD clause
Hi all, I have a problem outerjoining a clause or a request with
Here's my data
as you can see I am attaching the table 1 and table 2. I join with txt1, if txt1 is null, then join by txt2, if null, then reach by txt3 and so on.WITH table1 AS ( SELECT 'test' txt1, 'pak' txt2, 'ced' txt3, 'su' txt4 FROM dual UNION ALL SELECT null txt1, 'pak' txt2, 'ced2' txt3, 'su2' txt4 FROM dual UNION ALL SELECT null txt1, NULL txt2, 'ced3' txt3, 'su3' txt4 FROM dual UNION ALL SELECT null txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL SELECT 'text5' txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL SELECT null txt1, NULL txt2, null txt3, null txt4 FROM dual ) ,table2 AS ( SELECT 111 pid, 'test' txt1, 'pak4' txt2, 'ced' txt3, 'su' txt4 FROM dual UNION ALL SELECT 222 pid, 'test1' txt1, 'pak' txt2, 'ced2' txt3, 'su2' txt4 FROM dual UNION ALL SELECT 333 pid, 'test2' txt1, 'pak3' txt2, 'ced3' txt3, 'su4' txt4 FROM dual UNION ALL SELECT 444 pid, 'test2' txt1, 'pak3' txt2, 'ced4' txt3, 'su3' txt4 FROM dual ) SELECT b.pid, a.* from table1 a, table2 b WHERE (a.txt1 = b.txt1 OR a.txt1 IS NULL AND a.txt2=b.txt2 OR Nvl(a.txt2, a.txt1) IS NULL AND a.txt3 = b.txt3 OR Nvl(a.txt2, a.txt1) IS NULL AND a.txt3 IS NULL AND a.txt4 = b.txt4 )
the above produces this output code
This output is partially correct. only 4 lines were in display and two has been left outPID TXT1 TXT2 TXT3 TXT4 === ==== === ==== ==== 111 test pak ced su 222 pak ced2 su2 333 ced3 su3 444 su3
I tried to use the outer join, but oracle will complain that I can't use outerjoin with the GOLD clause.SELECT 'text5' txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL SELECT null txt1, NULL txt2, null txt3, null txt4 FROM dual
can someone modify my query to display the output below?
PID TXT1 TXT2 TXT3 TXT4 === ==== === ==== ==== 111 test pak ced su 222 pak ced2 su2 333 ced3 su3 444 su3 NULL NULL NULL NULL NULL test5
Not sure you can do it with the style of the Oracle of outer joins, but open ANSI style joins is simple, in fact exactly as you had it.
SQL> set null null; SQL> WITH table1 AS ( 2 SELECT 'test' txt1, 'pak' txt2, 'ced' txt3, 'su' txt4 FROM dual UNION ALL 3 SELECT null txt1, 'pak' txt2, 'ced2' txt3, 'su2' txt4 FROM dual UNION ALL 4 SELECT null txt1, NULL txt2, 'ced3' txt3, 'su3' txt4 FROM dual UNION ALL 5 SELECT null txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL 6 SELECT 'text5' txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL 7 SELECT null txt1, NULL txt2, null txt3, null txt4 FROM dual), 8 table2 AS ( 9 SELECT 111 pid, 'test' txt1, 'pak4' txt2, 'ced' txt3, 'su' txt4 FROM dual UNION ALL 10 SELECT 222 pid, 'test1' txt1, 'pak' txt2, 'ced2' txt3, 'su2' txt4 FROM dual UNION ALL 11 SELECT 333 pid, 'test2' txt1, 'pak3' txt2, 'ced3' txt3, 'su4' txt4 FROM dual UNION ALL 12 SELECT 444 pid, 'test2' txt1, 'pak3' txt2, 'ced4' txt3, 'su3' txt4 FROM dual) 13 SELECT b.pid, a.* 14 from table1 a 15 LEFT JOIN table2 b 16 ON (a.txt1 = b.txt1 OR 17 a.txt1 IS NULL AND a.txt2=b.txt2 OR 18 Nvl(a.txt2, a.txt1) IS NULL AND a.txt3 = b.txt3 OR 19 Nvl(a.txt2, a.txt1) IS NULL AND a.txt3 IS NULL AND a.txt4 = b.txt4); PID TXT1 TXT2 TXT3 TXT4 ---------- ------ ------ ------ ------ 111 test pak ced su 222 null pak ced2 su2 333 null null ced3 su3 444 null null null su3 null text5 null null su3 null null null null null
John
-
Outer joins and null in the 'where' clause condition
Hi people,
Please help me on this.
Here's my query.
with x
(select 'a' as a dual union all col1)
Select 'b' as col1 of union double all the
Select 'c' as double col1
),
y as
(
Select 'b' as col2 from dual Union all the
Select 'c' as col2 from dual Union all the
Select would be "as col2 from dual Union all the"
Select 'e' as col2 from dual
)
Select * x y right outer join
on x.col1 = y.col2 and y.col2 is null
Get all the lines of 'COL1' as null. Why like this?
Just add the condition to the WHERE clause for example
WITH x AS (SELECT 'a' AS col1 FROM dual UNION ALL SELECT 'b' AS col1 FROM dual UNION ALL SELECT 'c' AS col1 FROM dual ), y AS ( SELECT 'b' AS col2 FROM dual UNION ALL SELECT 'c' AS col2 FROM dual UNION ALL SELECT 'd' AS col2 FROM dual UNION ALL SELECT 'e' AS col2 FROM dual ) SELECT * FROM x LEFT OUTER JOIN y ON x.col1=y.col2 ----want to add "and y.col2 is null " condition to get value "a" where y.col2 is null
-
Syntax of UPDATE of Oracle with the JOIN and the WHERE clause
I need to update one of my paintings and can't seem to get the syntax right. I tried 4 different approaches, but does not have a chance. Any help would be greatly appreciated.
Attempt #1: Error: not correctly completed SQL command
UPDATE TESTDTA.F4941
SET TESTDTA.F4941.RSDSTN=TESTDTA.F4981.FHRTDQ,TESTDTA.F4941.RSUMD1=TESTDTA.F4981.FHUOM
FROM TESTDTA.F4941
INNER JOIN TESTDTA.F4981
ON TESTDTA.F4941.RSSHPN = TESTDTA.F4981.FHSHPN
WHERE TESTDTA.F4941.RSSHPN = 647143
AND TESTDTA.F4941.RSDSTN = 0
AND TESTDTA.F4941.RSADDJ > 110365
AND TESTDTA.F4981.FHCGC1 = 'DIS';Try #2: Error report: SQL error: ORA-00904: "TESTDTA." "" F4981 ". "' FHUOM ': invalid identifier 00904. 00000 - '% s: invalid identifier '.
UPDATE (SELECT TESTDTA.F4941
FROM TESTDTA.F4941
INNER JOIN TESTDTA.F4981
ON TESTDTA.F4941.RSSHPN = TESTDTA.F4981.FHSHPN
WHERE TESTDTA.F4941.RSSHPN = 647143
AND TESTDTA.F4941.RSDSTN = 0
AND TESTDTA.F4941.RSADDJ > 110365
AND TESTDTA.F4981.FHCGC1 = 'DIS')
SET TESTDTA.F4941.RSDSTN=TESTDTA.F4981.FHRTDQ,TESTDTA.F4941.RSUMD1=TESTDTA.F4981.FHUOMTry #3: Error report: SQL error: ORA-00904: "TESTDTA." "' F4941 ': invalid identifier 00904. 00000 - '% s: invalid identifier '.
UPDATE (SELECT *
FROM TESTDTA.F4941
INNER JOIN TESTDTA.F4981
ON TESTDTA.F4941.RSSHPN = TESTDTA.F4981.FHSHPN
WHERE TESTDTA.F4941.RSSHPN = 647143
AND TESTDTA.F4941.RSDSTN = 0
AND TESTDTA.F4941.RSADDJ > 110365
AND TESTDTA.F4981.FHCGC1 = 'DIS')
SET TESTDTA.F4941.RSDSTN=TESTDTA.F4981.FHRTDQ,TESTDTA.F4941.RSUMD1=TESTDTA.F4981.FHUOM;Try #4: Error: ORA-00925: Missing keyword 00925. 00000 - "missing IN the keyword"
MERGE TESTDTA.F4941
USING TESTDTA.F4981
ON (TESTDTA.F4941.RSSHPN = TESTDTA.F4981.FHSHPN
AND TESTDTA.F4941.RSSHPN = 647143
AND TESTDTA.F4941.RSDSTN = 0
AND TESTDTA.F4941.RSADDJ > 110365
AND TESTDTA.F4981.FHCGC1 = 'DIS'
)
WHEN MATCHED THEN
UPDATE SET TESTDTA.F4941.RSDSTN=TESTDTA.F4981.FHRTDQ
,TESTDTA.F4941.RSUMD1=TESTDTA.F4981.FHUOM;Finally managed to do work, adding DISTINCT to select. I have pasted the SQL error in Google to begin with. Laughing out loud!
Code snippet work for anyone who comes across this thread...
MERGE INTO TESTDTA. F4941 DST
USING (SELECT DISTINCT TESTDTA. F4941. RSSHPN,
TESTDTA. F4941. RSDSTN,
TESTDTA. F4941. RSUMD1,
TESTDTA. F4941. RSADDJ,
TESTDTA. F4981. FHSHPN,
TESTDTA. F4981. FHRTDQ,
TESTDTA. F4981. FHUOM,
TESTDTA. F4981. FHCGC1
OF TESTDTA. F4941
JOIN INTERNAL TESTDTA. F4981
ON TESTDTA. F4941. RSSHPN = TESTDTA. F4981. FHSHPN
WHERE - TESTDTA. F4941. RSSHPN = 647143 AND
TESTDTA. F4941. RSDSTN = 0
AND TESTDTA. F4941. RSADDJ > 110365
AND TESTDTA. F4981. FHCGC1 = 'SAY') CBC
on (DST. RSSHPN = SRC. FHSHPN)
When matched then update
SET DST. RSDSTN = SRC. FHRTDQ, SUMMER TIME. RSUMD1 = SRC. FHUOM;
Thanks to everyone who helped with this.
-
Oracle 11 g 2 Linux x86_64
Hi all
I do turn the PL/SQL block below, but get the error below. I know, the INTO clause can be used only when a single line will be returned. In this case, I know that it returns multiple lines, so why he asked to use the INTO clause?DECLARE
v_object VARCHAR2 (10): = "TABLE";
v_schema VARCHAR2 (30): = 'TEST ';
CURSOR tblsze_cur IS
SELECT table_name
FROM dba_tables
Owner WHERE = 'TEST '.
AND (IN) table_name
"T1"
"T2."
"T3");
BEGIN
FOR tbl_rec IN tblsze_cur
LOOP
Select * from
Table (dbms_space. OBJECT_GROWTH_TREND
(v_schema, tbl_rec.table_name, v_object)) ;
END LOOP;
END;
/
Select * from table (dbms_space. OBJECT_GROWTH_TREND
*
ERROR at line 21:
ORA-06550: line 21, column 3:
PLS-00428: an INTO clause in this SELECT statement
It would be something more like this (untested)...
Set serverout on
create type object_growth_trend_row as object)
validating TIMESTAMP,
space_usage NUMBER,
space_alloc NUMBER,
quality VARCHAR (20))
/Create type object_growth_trend_table as table of the object_growth_trend_row
/DECLARE
number of r;
We varchar2 (30): = 'SCOTT ';
TYPE nmtbl IS TABLE OF THE all_tables.table_name%TYPE;
tNom nmtbl;
tgrowth object_growth_trend_table;
CURSOR c1 IS
SELECT table_name
From all_tables
Owner WHERE we =
AND table_name in ('EMP', 'Department');
growth of cursor (tablename in varchar2) is
Select *.
table (dbms_space.object_growth_trend (tablename, 'TABLE'));
BEGIN
OPEN c1;
FETCH c1 COLLECT LOOSE tNom;
CLOSE c1;
BECAUSE me IN tNom. FIRST... tNom. LAST
LOOP
r: = 0;
dbms_output.put_line (' growth for table: ' | tname (i));
FOR g IN growth (tname (i))
LOOP
r: = r + 1;
dbms_output.put_line ('Timestamp: ' | g.timePoint |') Use: ' | g.space_usage);
END LOOP;
DBMS_OUTPUT. Put_line (' found lines: ' | r);
END LOOP;
END;
/I just tested this in my SYS schema (although you should not create objects in SYS.) and got...
For table growth: EMP
EXCEPTION in the treatment of the Charles - code:-14551 msg: ORA-14551: cannot perform a DML operation inside a query
Timestamp: 3 July 13 09.15.27.250000 use: 5332
Found lines: 1
For table growth: DEPT
EXCEPTION in the treatment of the Charles - code:-14551 msg: ORA-14551: cannot perform a DML operation inside a query
Timestamp: 3 July 13 09.15.27.282000 use: 4846
Found lines: 1
Not sure why it's up the DML operation... which seems inner exception to the dbms_space package. Even if I just run it directly in sys like this:
SQL > SELECT *.
2. IN the TABLE (dbms_space.object_growth_trend ('SYS', ' $', TAB 'TABLE'));AFTER SPACE_USAGE SPACE_ALLOC QUALITY
--------------------------------------------------------------------------- ----------- ----------- --------------------
3 JULY 13 09.19.01.956000 10342201 24117248 INTERPOLATED
4 JULY 13 09.19.01.956000 10342201 24117248 INTERPOLATED
JULY 5, 13 09.19.01.956000 10342201 24117248 INTERPOLATED
6 JULY 13 09.19.01.956000 10342201 24117248 INTERPOLATED
7 JULY 13 09.19.01.956000 10342201 24117248 INTERPOLATED
8 JULY 13 09.19.01.956000 10342201 24117248 INTERPOLATED
9 JULY 13 09.19.01.956000 10342201 24117248 INTERPOLATED
10 JULY 13 09.19.01.956000 10342201 24117248 INTERPOLATED
JULY 11, 13 09.19.01.956000 10342201 24117248 INTERPOLATED
12 JULY 13 09.19.01.956000 10342201 24117248 INTERPOLATED
13 JULY 13 09.19.01.956000 10342201 24117248 INTERPOLATED
14 JULY 13 09.19.01.956000 10342201 24117248 INTERPOLATED
15 JULY 13 09.19.01.956000 10342201 24117248 INTERPOLATED
16 JULY 13 09.19.01.956000 10342201 24117248 INTERPOLATED
17 JULY 13 09.19.01.956000 10342201 24117248 INTERPOLATED
18 JULY 13 09.19.01.956000 10342201 24117248 INTERPOLATED
19 JULY 13 09.19.01.956000 10342201 24117248 INTERPOLATED
20 JULY 13 09.19.01.956000 10342201 24117248 INTERPOLATED
21 JULY 13 09.19.01.956000 10342201 24117248 INTERPOLATED
22 JULY 13 09.19.01.956000 10342201 24117248 INTERPOLATED
23 JULY 13 09.19.01.956000 10342201 24117248 INTERPOLATED
24 JULY 13 09.19.01.956000 10342201 24117248 INTERPOLATED
25 JULY 13 09.19.01.956000 10342201 24117248 INTERPOLATED
26 JULY 13 09.19.01.956000 10342201 24117248 GOOD
27 JULY 13 09.19.01.956000 10342201 24117248 GOOD
28 JULY 13 09.19.01.956000 10342201 24117248 GOOD
29 JULY 13 09.19.01.956000 10342201 24117248 GOOD
30 JULY 13 09.19.01.956000 10342201 24117248 GOOD
31 JULY 13 09.19.01.956000 10342201 24117248 GOOD
1ST AUGUST 13 09.19.01.956000 10342201 24117248 GOOD
2 AUGUST 13 09.19.01.956000 10342201 24117248 GOOD
3 AUGUST 13 09.19.01.956000 10342201 24117248 PLANNED
4 AUGUST 13 09.19.01.956000 10342201 24117248 PLANNED
5 AUGUST 13 09.19.01.956000 10342201 24117248 PLANNED
6 AUGUST 13 09.19.01.956000 10342201 24117248 PLANNED
7 AUGUST 13 09.19.01.956000 10342201 24117248 PLANNED36 selected lines.
EXCEPTION in the treatment of the Charles - code:-14551 msg: ORA-14551: cannot perform a DML operation inside a query
... She still throws the exception.
Doesn't seem like a package of well designed if the types are provided only in the package and not as objects of database, which are required to be used in SQL based in pipeline.
-
Need help with the condition join in SQL
Hi all -
I need to ask for help with this query:
Create table user_tab_col_test (varchar2 (30) from table_name, column_name varchar2 (30), data_type varchar2 (30));
Insert into user_tab_col_test (table_name, column_name, data_type) values ('table1', 'column1', 'varchar2')
Insert into user_tab_col_test (table_name, column_name, data_type) values ('Column2', 'table1', 'varchar2')
Insert into user_tab_col_test (table_name, column_name, data_type) values ("Column3", 'table1', 'varchar2')
Insert into user_tab_col_test (table_name, column_name, data_type) values ('column4', 'table1', 'varchar2')
Insert into user_tab_col_test (table_name, column_name, data_type) values ("column1", "table2", 'varchar2')
Insert into user_tab_col_test (table_name, column_name, data_type) values ('table2', 'column2', 'varchar2')
Insert into user_tab_col_test (table_name, column_name, data_type) values ('table2', "Column3", 'varchar2')
Insert into user_tab_col_test (table_name, column_name, data_type) values ('table2', 'column4', 'varchar2')
Commit;
Create table all_cons_columns_test (varchar2 (30) from table_name, column_name varchar2 (30), constraint_name varchar2 (30))
Insert into all_cons_columns_test (table_name, column_name, constraint_name) values ("table1", "column1", "primary")
Insert into all_cons_columns_test (table_name, column_name, constraint_name) values ("table1", "column1", "secondary")
Commit;
This is my query and the current result:
Select u.table_name, u.column_name, c.constraint_name
Of user_tab_col_test u
Outer join all_cons_columns_test c left
On (u.table_name = c.table_name
AND U.COLUMN_NAME = C.COLUMN_NAME
AND C.CONSTRAINT_NAME IN ('main'))
order of U.table_name, U.COLUMN_NAME;
TABLE_NAME COLUMN_NAME, CONSTRAINT_NAME
------------------ --------------------- ----------------------------
Table1 primary Column1
Table1 Column2
Table 1 Column3
Table2 Column1
Table2 Column2
Three questions:
(1) I don't want to return results where table_name = "table1". I can't get this to work.
(2) is my proper request and this is the best way to return my desired results? For example, I want all of the columns of user_tab_col_test and I want to only display the constraint_name from all_cons_columns_test argument if the argument constraint_name = 'primary '.
(3) will be the synatx be the same if I need to join a third table to all_cons_columns_test?
Any advice/suggestions are appreciated-
John
Published by: user703358 on January 11, 2013 20:57
Published by: user703358 on January 11, 2013 21:48Hi, John,.
user703358 wrote:
Hi all -I need to ask for help with this query:
Create table user_tab_col_test (varchar2 (30) from table_name, column_name varchar2 (30), data_type varchar2 (30));
Insert into user_tab_col_test (table_name, column_name, data_type) values ('table1', 'column1', 'varchar2')
Insert into user_tab_col_test (table_name, column_name, data_type) values ('Column2', 'table1', 'varchar2')...Thanks for posting the CREATE TABLE and INSERT.
It is more useful if you post the code that can be run without modification. You did not semicolons after INSERTION instructions.Three questions:
(1) I don't want to return results where table_name = "table1". I can't get this to work.What have you tried? Post your best attempt.
Here's one way:SELECT u.table_name , u.column_name , c.constraint_name FROM user_tab_col_test u LEFT OUTER JOIN all_cons_columns_test c ON u.table_name = c.table_name AND u.column_name = c.column_name AND c.constraint_name IN ('primary') WHERE u.table_name = 'table1' -- ***** NEW ***** ORDER BY u.table_name , u.column_name ;
You would not put this condition in the clause; who controls what is considered as a match between the tables, and "u LEFT OUTER JOIN c" means show all lines of u, even if they do not have a match in the c.
(2) is my proper request and this is the best way to return my desired results? For example, I want all of the columns of user_tab_col_test and I want to only display the constraint_name from all_cons_columns_test argument if the argument constraint_name = 'primary '.
Basically, this application is very well.
It displays all the columns of user_tab_col_test; missing data_type. Just add u.data_type to the SELECT clause, or change the SELECT clauseSELECT u.* , c.constraint_name
(3) will be the synatx be the same if I need to join a third table to all_cons_columns_test?
Do you mean "" * add * one-third * column * to all_cons_columns_test '? "
It depends on what results you want. Post new CREATE TABLE and INSERT and instructions the results you want new data.
Most likely, the basic structure of what you've written will remain exactly the same. -
Reference SQL Loader Bind Variables in the when Clause
Support for SQL: SQL * Loader: version 8.0.6.3.0 (don't ask, it runs on Oracle EBS 11i...)
I have a case where my sample data looks like:
and another fileHD00100001002 SM00100002CHAPS 99999999999 20120906GBP0000000000001000000000001
Essentially, I need to apply another "IN" clause for each record of SM depends on the ack_type (char 13 on HD recording), either 1 or 2HD00100001001 SM00100002GBP0000000000001000000000001
I tried setting up the ack_type with a variable binding but find how to reference.
Example of control file:
The code above does not work, it is said that: ack_type is not recognized. Is there a way to do it, given the former character of the SQL Load version?-- $Header: test.ctl -- LOAD DATA REPLACE -- Record Type HD : File Header INTO TABLE test_table WHEN rec_id_no = 'HD' TRAILING NULLCOLS (rec_no RECNUM, hdr_line CONSTANT 'H', rec_id_no POSITION(1:2) CHAR, file_number POSITION(3:5) CHAR, sequence_number POSITION(6:10) CHAR, status POSITION(11:12) CHAR, ack_type POSITION(13:13) ":ack_type", co_id POSITION(14:21) CHAR, dept_id POSITION(22:24) CHAR, btch_no POSITION(25:36) CHAR, trans_id POSITION(37:42) CHAR) -- Record Type SM : File Summary INTO TABLE test_table WHEN rec_id_no = 'SM' and :ack_type = '1' TRAILING NULLCOLS (rec_no RECNUM, hdr_line CONSTANT 'L', rec_id_no POSITION(1:2) CHAR, file_number POSITION(3:5) CHAR, sequence_number POSITION(6:10) CHAR, ccy_code POSITION(11:13) CHAR, amount POSITION(14:26) CHAR, number_trans_ok POSITION(27:40) CHAR)
What is the database version 11i is running on? If 11 GR 2, this doc can help you in the use of the features that Dan mentions
How to use the 9i or 10g features in SQL * Loader for Apps? [423035.1 ID]
HTH
Srini -
error in pl/sql of the CASE clause.
Hello
I m not a sql progremmer. an interior according to the database worked for previous but not mentioned dates and may be for dates too.
Error is given after the following code.
We have 4 store-ID, that ID is to have values rest three IDs have values 0. Gets the ID having missed in FUND and error values. The cursor query works fine when executed alone.
kindly advice!
declare
ip_date varchar2 (30): =' 27-AUG-2011.
cursor dwn_cnt (param_date varchar2, param_hr number), select store b.aw_store_id, count (*) bv1to1.aw_user_dwnld_cnt count_dwn, b bv1to1.bv_user_profile where a.date_download between to_date(param_date||) e '|| param_hr |': 0 0:00 ', "HH24:MI:SS of MON-DD-YYYY") and to_date(param_date||) e '|| param_hr | (": 59: 59 ',' MON-DD-YYYY HH24:MI:SS') and a.user_id = b.user_id group by b.aw_store_id;
dwn_cnt_var dwn_cnt % rowtype;
type dwn_cnt_hr is table of number of pls_integer indexes;
dwn_cnt_hr_var dwn_cnt_hr;
Start
dbms_output.put_line ('US' |) ',' ||' DE'||','||' UK'||','||' FR'||','||' TIME ');
dbms_output.put_line(' ');
I'm in 0.23
loop
dwn_cnt_hr_var (0): = 0;
dwn_cnt_hr_var (103): = 0;
dwn_cnt_hr_var (104): = 0;
dwn_cnt_hr_var (105): = 0;
dwn_cnt_hr_var (200): = 0;
Open dwn_cnt (ip_date, i);
extract the dwn_cnt in dwn_cnt_var;
loop
box (dwn_cnt_var. Store)
When 0 then
dwn_cnt_hr_var (0): = dwn_cnt_var.count_dwn;
When there are 103 then
dwn_cnt_hr_var (103): = dwn_cnt_var.count_dwn;
When there are 104 then
dwn_cnt_hr_var (104): = dwn_cnt_var.count_dwn;
When 105 then
dwn_cnt_hr_var (105): = dwn_cnt_var.count_dwn;
When 200 then
dwn_cnt_hr_var (200): = dwn_cnt_var.count_dwn;
end case;
extract the dwn_cnt in dwn_cnt_var;
When the output dwn_cnt % notfound;
end loop;
dbms_output.put_line (dwn_cnt_hr_var (0) + dwn_cnt_hr_var (200) |) «, » || dwn_cnt_hr_var (103) | «, » || dwn_cnt_hr_var (105) | «, » || dwn_cnt_hr_var (104) | «, » || (i);
close dwn_cnt;
end loop;
end;
/
OUTPUT:-
US, UK, FR, HOUR
declare
*
ERROR on line 1:
ORA-06592: not found CASE when executing CASE statement
ORA-06512: at line 20
Elapsed time: 00:00:00.90
Rgds,
Abdallah.You need an ELSE clause:
... when 200 then dwn_cnt_hr_var(200):=dwn_cnt_var.count_dwn; else /* code here for what to do if none of the WHEN clauses are true */ end case; ...
-
JDeveloper does not support the SQL expert, cannot add query clause to view link
For developers who can know:
I use JDeveloper 10.1.3.4 and I have two tables, we're STUDENTS, the other is the PRICE, with a one-to-many relationship (a student may have several awards), and ID is the foreign key:
In the application, when a student (9999, JOHN) connects, the information above is displayed. I need to add up all the awards for the student and to display not only the elements of price, but also the total amount of all awards. To do this, I created another object to view named TotalAwards in the object entity the price just to get the total amount. The SQL code of the VO'sSTUDENTS ------------------------ ID NAME DOB ------------------------ 9999 JOHN 01/02/1990 | | | | AWARDS | ------------------------ | ID DESC AMOUNT | ------------------------ ----------- 9999 PELL 500 9999 PERKINS 800 9999 LOAN 900
Then, a link is created between the students and the TotalAwards, and use of the new link to the view is added to the application module. TotalAwards is now available in the data control palette to be drag-and - drop to pages.SELECT SUM(Awards.AMOUNT) AS TOTAL FROM AWARDS Awards
Problem occurs when the application is invoked. An error is caught before the application can begin. The error message indicates that "the ends or the link view do not specify an attribute.
It seems that the TOTAL 'SUM (Awards.AMOUNT) AS TOTAL' is not recognized as an attribute. I have reviewed the query clause in the display link to see if it is there, such as:
There is no such clause in the query clause page. And I can not add a no more, because the page is grayed out and disabled. I think maybe it's for the same reason: TOTAL is not recognized as an attribute of the price.Attribute Bind Variable ------------ -------------- Students.ID :Bind_Id WHEHE :Bind_Id = Awards.ID
How to get around the problem? Or are there other ways to summarize the total amount and view it in the browser?
Thank you very much for help!
NewmanHello
Here you have a solution for the TOTAL:
http://www.freewebalbum.com/blogs/faces/bjanko/blogs.jsp?blog=bjanko20070725180020Kind regards
Branislav
-
Pass Pl/sql table in the USING clause in the EXECUTE IMMEDIATE statement
Getting error when I try to pass the PL/SQL table in the USING clause in the EXECUTE IMMEDIATE statement:
Declare
result NUMBER;
TYPE values_tab IS TABLE OF NUMBER INDEX OF directory;
lv_tab values_tab;
lv_exp varchar2 (300);
lv_exec varchar2 (300);
BEGIN
lv_tab (1): = 5;
lv_tab (2): = 48;
lv_tab (3): = 7;
lv_tab (4): = 6;
lv_exp: = ': + b1: b2 + (: b3 *: b4)';
lv_exec: = 'SELECT'. lv_exp | ' THE DOUBLE '.
IMMEDIATE EXECUTION
lv_exec
IN
result
USING
lv_tab;
DBMS_OUTPUT. Put_line (result);
END;
/
Error on line 1
ORA-06550: line 20, column 12:
PLS-00457: expressions must be SQL types
ORA-06550: line 15, column 8:
PL/SQL: Statement ignored
I am trying to evaluate the expression ': + b1: b2 + (: b3 *: b4) "which is stored in the table. This table has different expressions (expressions about 300). I want to use the bind variable in the expression because each expression evaluated thousands of time may be more in some cases. If I use bind variable can he fill pool.
Is there a way I can pass parameters with the HELP of (IN) dynamically instead of write "help lv_tab (1), lv_tab (2), lv_tab (3), lv_tab (4)? As number of change of the input parameters depend on the expression in the table.
If it is possible please suggest any other ideas/approaches
Help, please...
Published by: satnam on June 11, 2009 11:50Well, you keep changing faster reqs that I can follow. In any case, assuming that N-th variable bind (left to right) corresponds to n-th collection item:
Declare result NUMBER; lv_tab values_tab := values_tab(); lv_exp varchar2(300); lv_exec varchar2(300); lv_i number := 0; BEGIN lv_tab.extend(4); lv_tab(1) := 5; lv_tab(2) := 48; lv_tab(3) := 7; lv_tab(4) := 6; lv_exp := ':5000135+:5403456+(:5900111*:5200456)'; lv_exec := lv_exp; While regexp_like(lv_exec,':\d+') loop lv_i := lv_i + 1; lv_exec := REGEXP_REPLACE(lv_exec,':\d+',':b(' || lv_i || ')',1,1); end loop; lv_exec := 'BEGIN :a := ' || lv_exec || '; END;'; DBMS_OUTPUT.PUT_LINE(lv_exec); EXECUTE IMMEDIATE lv_exec USING OUT result,IN lv_tab; DBMS_OUTPUT.PUT_LINE(result); END; / BEGIN :a := :b(1)+:b(2)+(:b(3)*:b(4)); END; 95 PL/SQL procedure successfully completed. SQL>
SY.
-
Join the table orders from clause
Hi all
Who is the effective way to join the tables in from clause. I have two tables first with 20 lakh records and second containing 10 lakh recods.
Who is the effective query 1 or 2. Please suggest me if you have an idea to rewrite the query.QUERY 1: SELECT T4.ID,T4.ISO_NAME FROM T,T4 WHERE T4.ISO_NAME LIKE '%US%' AND T.ID=T4.ID; QUERY 2: SELECT T4.ID,T4.ISO_NAME FROM T4,T WHERE T4.ID=T.ID AND T4.ISO_NAME LIKE '%US%'; T(ID IS PRIMARY KEY) (20 lakh records) T4 (ID IS PRIMARY KEY ) (10 lakh records) --------------------- ID ISO_NAME 100 US,UK,IN,BR 101 UK,US,BR,IN 102 BR,UK,US,IN Note: No index on ISO_NAME .
Kind regards
Rajasekhar
Published by: SuNRiZz68 on January 29, 2009 04:22In practical terms, Alex is right. Sometimes it matter what table is selected first, but does the CBO generally a very good job of deciding what you need to select the first (assuming that your statistics are up to date) but this is the situation you are trying to avoid as much as possible.
If you specify a table main command tables in the clause is not reliable and should be used - but think before using advice and don't do that when necessary.
Which table to select depends firstly on the join method in the execution plan. Nested loops joins perform better by selecting in the smaller table first, make a loop on the largest table. Joins the smaller set hash table in memory first, and then go through the larger table, perform searches in memory. He can't make any difference, what table is read using first the merger joins and sort.
Back to your original question. Using the cost-based optimizer, both queries will probably roll the same because newer versions of Oracle (9i, 10g) often transform queries for efficiency before the execution anyway. According to what do you or do not request should probably run a nested loop or hash join. With a small set of data creaing index and using a search of nested loops will probably be faster to avoid full table scans. the '%' in the LIKE clause leader would ignore an index on the ISO_NAME column in any case if a main column may be used in a composite index. All this is based on the approximation using the information provided; Tuning questions should always be tested to unexpected developments.
-
Problems of execution of a SQL function with a variable in the WHERE clause
Hello world!
I have programmed a function that returns a boolean value based on the result of the SQL. It's the function:
FUNCTION existe_secuencial (seq_name VARCHAR2) RETURN AS BOOLEAN
cursor c2 is SELECT FROM all_sequences WHERE upper (sequence_name) = sequence_name' | seq_name | ' ;
BEGIN
OPEN c2;
DBMS_OUTPUT. Put_line (nombre_seq);
Get c2 INTO kk;
If c2% NOTFOUND = True THEN
RETURNS false;
on the other
RETURNS true;
end if;
END existe_secuencial;
And I give the floor to the function of a procedure in this way:
IF existe_secuencial ("SEQ_ARQUETA") = True THEN
DBMS_OUTPUT. Put_line ('exists');
ON THE OTHER
DBMS_OUTPUT. Put_line ("' NOT exists");
END IF;
The probrem that this SQL is forced to return results because this sequence exists in the comic book, but is not, return me the FALSE value. What makes me mad is that if I change the second line of the function in this way:
> > cursor c2 is SELECT FROM all_sequences WHERE upper (sequence_name) sequence_name ="SEQ_ARQUETA";
It works find and return of sequence existing (real)
Can someone help me please, I'm quite desperate to find what is the problem with that because I do not understand why if I built the slider with a variable returns no results so that if I do write it works...
Thanks in advance!
Itziar
Frame you your variable in quotes, which makes the string literal ' |. ' seq_name | "rather than the content of the variable.
I think that something like this would be an improvement.
function existe_secuencial (seq_name VARCHAR2) return a Boolean value as
number of exist_check: = 0;
Start
Start
Select 1
in exist_check
of all_sequences
where upper (sequence_name) = upper (seq_name);
exception
When no_data_found then
null;
end;
return (exist_check = 1);
end existe_secuencial;
-
Hi all
Thank you very much for all the kind support so far.
I have two report (sql query)
I want to add both the sql query
1st sql query
2nd sql queryselect distinct(a.item_number) ,a.quantity - b.quantity from QUANTITY_ONHAND_ATP a,BACKLOG_ATP_LT_CW b where a.item_number = b.item_number order by item_number
In the 1st sql query I have 129 records and in the 2nd query sql, I have 14 records. I want to combine these two sql queries. If the item_number 1st sql query is not there in 2nd and then view it as to 1 sql only.select distinct(wb.item_number) ,wb.quantity - be.quantity ,c.quantity - d.quantity from BACKLOG_WEEK_BEFORE_ATP wb ,BACKLOG_ATP_ET_CW be ,BACKLOG_WEEK_AFTER_ATP c ,BACKLOG_ATP_GT_CW d where wb.item_number = be.item_number and c.item_number = d.item_number and wb.item_number = c.item_number and be.item_number = c.item_number and wb.item_number = d.item_number and be.item_number = d.item_number order by wb.ITEM_NUMBER
Any help how to do that.
Concerning
Published by: User_Apex on July 15, 2011 01:21Use the NVL function:
select q1.item_number, WEEK_BEFORE, nvl(CURRENT_WEEK,0) CURRENT_WEEK, nvl(WEEK_AFTER,0) WEEK_AFTER (...)
-
Session variable in the WHERE clause of the SQL statement
Hey all,.
I was wonering just if there is a way to set the WHERE clause of the query that the session variable? I have the following so far and have tried to go through a ton of tutorials, but it doesn't seem to work. Is it still possible? I don't know what follows is wrong, but can someone help me with changing the following code, or pointing me to a good tutorial? (I write it with PHP)
$query = "SELECT * from members where user_id = ' $_SESSION ['members']";
Thanks for your help.
$member = "-1";
If (isset($_SESSION['members'])) {}
$member = $_SESSION ['members'];}
$query = "SELECT * from members where user_id = $member;
Maybe you are looking for
-
My computer crashed and I restore my my hard drive recovered Thunderbird email, how do I restore my old emails (stored emails and accounts)? I found 2 folders (a local sub) & another under roaming which appear to contain my email stuff. How in Thunde
-
El Capitan. Date of last change sorting
In collaboration with El Capitan. Actually, the "Last modified" column displays the date that the file was last opened. If I open a file, but make no changes, not near "last modified" always show an earlier date? Me always changes to today's date, w
-
HP envy 15-j054ca: SSD and HDD on loptop
can I put SSDS as the main memory and external DRIVE as secondary drive? is it possible for my loptop? I want to buy SSD but I have only $150 budget, what SSD should I buy? Im a Gamer by the way so I think 240G of the SDS is not enough?
-
Hello I was wondering if its possible to configure a GPO for when users connect in their own workstations of it setting a lockout after a certain period of inactivity. I tried to define the parameters of the terminal on the domain GPO, but that seems
-
How to open a file seldomly?
How to open a file seldomly?