A parsing sql problem?
Hi allI'm on the OracleXE 11 GR 2 and have the following conditions for the release of the select statement:
Tables:
GARAGE
======
ID GARAGE_NAME
--- -----------
1 GARAGE_1
2 GARAGE_2
PERSONS
=======
ID GARAGE_ID NAME
--- --------- -----
1 1 NAME1_1
2 1 NAME1_2
3 1 NAME1_3
4 1 NAME1_4
5 1 NAME1_5
6 1 NAME1_6
7 2 NAME2_1
8 2 NAME2_2
9 2 NAME2_3
10 2 NAME2_4
CARS
====
ID GARAGE_ID CAR
--- --------- -----
1 1 CAR1_1
2 1 CAR1_2
3 1 CAR1_3
4 1 CAR1_4
5 2 CAR2_1
6 1 CAR2_2
7 1 CAR2_3
8 1 CAR2_4
9 1 CAR2_5
10 1 CAR2_6
The power required is:
GARAGE_ID GARAGE_NAME CAR PERSON
--------- ----------- ------ -------
1 GARAGE_1 CAR1_1 NAME1_1
1 GARAGE_1 CAR1_2 NAME1_2
1 GARAGE_1 CAR1_3 NAME1_3
1 GARAGE_1 CAR1_4 NAME1_4
1 GARAGE_1 NAME1_5
1 GARAGE_1 NAME1_6
2 GARAGE_2 CAR2_1 NAME2_1
2 GARAGE_2 CAR2_2 NAME2_2
2 GARAGE_2 CAR2_3 NAME2_3
2 GARAGE_2 CAR2_4 NAME2_4
2 GARAGE_2 CAR2_5
2 GARAGE_2 CAR2_6
How can I achieve this output?What is a parsing SQL problem?
Dear community, I need your help!
Kind regards
Looks like than just an outer join...
But how are you going to jining cars and people - from the name?
Or something like that?
with c as
(
select c.garage_id,c.car,g.garage_name g_name,
row_number() over(partition by c.garage_id order by c.id) rn
from cars c,garage g
where c.garage_id = g.id
),
p as
(
select p.garage_id,p.name p_name,g.garage_name g_name,
row_number() over(partition by p.garage_id order by p.id) rn
from persons p,garage g
where p.garage_id = g.id
)
select nvl(p.garage_id,c.garage_id) garage_id,
nvl(p.g_name,c.g_name) garage_name,
car,p_name person
from c
full outer join p on
(c.garage_id = p.garage_id and c.rn = p.rn);
GARAGE_ID GARAGE_NAME CAR PERSON
--------- ----------- ------ -------
1 GARAGE_1 CAR1_1 NAME1_1
1 GARAGE_1 CAR1_2 NAME1_2
1 GARAGE_1 CAR1_3 NAME1_3
1 GARAGE_1 CAR1_4 NAME1_4
1 GARAGE_1 NAME1_5
1 GARAGE_1 NAME1_6
2 GARAGE_2 CAR2_1 NAME2_1
2 GARAGE_2 CAR2_2 NAME2_2
2 GARAGE_2 CAR2_3 NAME2_3
2 GARAGE_2 CAR2_4 NAME2_4
2 GARAGE_2 CAR2_5
2 GARAGE_2 CAR2_6
12 rows selected
If this isn't what you want, please explain the logic to get to your exit.
Published by: JAC on November 17, 2012 15:15
Tags: Database
Similar Questions
-
Parsing sql - cursor parent and child
Hi all
What is the parent and child when parsing sql cursor?
Thank you
JohnWell, as Anand mentioned you could yourself. Here's a demo of the workaround based. Based on the change of environment, the sliders would be created and will not be shared that I made using the change of parameter of optimizer_mode. This is done in 11201 with the setting optimizer_features_enable on 10201.
SQL> drop table t purge; Table dropped. SQL> select sql_text from V$sqlarea where sql_text like 'select * from t%'; SQL_TEXT -------------------------------------------------------------------------------- select * from t SQL> alter system flush shared_pool; System altered. SQL> select sql_text from V$sqlarea where sql_text like 'select * from t%'; no rows selected SQL> save a Created file a.sql SQL> select * from t; select * from t * ERROR at line 1: ORA-00942: table or view does not exist SQL> create table t(a char); Table created. SQL> select * from t; no rows selected SQL> select sql_text from V$sqlarea where sql_text like 'select * from t%'; SQL_TEXT -------------------------------------------------------------------------------- select * from t SQL> select * from T; no rows selected SQL> select sql_text from V$sqlarea where sql_text like 'select * from t%'; SQL_TEXT -------------------------------------------------------------------------------- select * from t SQL> select sql_text from V$sqlarea where sql_text like 'select * from t%' or sql_text like 'select * from T%'; SQL_TEXT -------------------------------------------------------------------------------- select * from t select * from T SQL> select sql_text,version_count, executions from V$sqlarea where sql_text like 'select * from t%' or sql_text like 'select * from T%'; SQL_TEXT -------------------------------------------------------------------------------- VERSION_COUNT EXECUTIONS ------------- ---------- select * from t 1 1 select * from T 1 1 SQL> column sql_text format a40 SQL> / SQL_TEXT VERSION_COUNT EXECUTIONS ---------------------------------------- ------------- ---------- select * from t 1 1 select * from T 1 1 SQL> select * from T; no rows selected SQL> select sql_text from V$sqlarea where sql_text like 'select * from t%' or sql_text like 'select * from T%'; SQL_TEXT ---------------------------------------- select * from t select * from T SQL> select sql_text,version_count, executions from V$sqlarea where sql_text like 'select * from t%' or sql_text like 'select * from T%'; SQL_TEXT VERSION_COUNT EXECUTIONS ---------------------------------------- ------------- ---------- select * from t 1 1 select * from T 1 2 SQL> alter session set optimizer_mode=first_rows; Session altered. SQL> select * from T; no rows selected SQL> select * from t; no rows selected SQL> select sql_text,version_count, executions from V$sqlarea where sql_text like 'select * from t%' or sql_text like 'select * from T%'; SQL_TEXT VERSION_COUNT EXECUTIONS ---------------------------------------- ------------- ---------- select * from t 1 1 select * from test_sharing where id=:a 1 3 select * from test_sharing where id=1 1 0 select * from test_sharing where id=99 1 0 select * from T 2 3 SQL> select sql_text, child_number, optimizer_mode, plan_hash_value from V$sql where sql_text like 'select * from t%' or sql_text like 'select * fro SQL_TEXT CHILD_NUMBER OPTIMIZER_ PLAN_HASH_VALUE ---------------------------------------- ------------ ---------- --------------- select * from t 0 FIRST_ROWS 1601196873 select * from test_sharing where id=:a 0 ALL_ROWS 3492249339 select * from test_sharing where id=1 0 ALL_ROWS 3492249339 select * from test_sharing where id=99 0 ALL_ROWS 2354865636 select * from T 0 ALL_ROWS 1601196873 select * from T 1 FIRST_ROWS 1601196873 6 rows selected. SQL> alter session set optimizer_mode=first_rows_1; Session altered. SQL> select * from t; no rows selected SQL> select * from T; no rows selected SQL> select sql_text, child_number, optimizer_mode, plan_hash_value from V$sql where sql_text like 'select * from t%' or sql_text like 'select * fro SQL_TEXT CHILD_NUMBER OPTIMIZER_ PLAN_HASH_VALUE ---------------------------------------- ------------ ---------- --------------- select * from t 0 FIRST_ROWS 1601196873 select * from test_sharing where id=:a 0 ALL_ROWS 3492249339 select * from test_sharing where id=1 0 ALL_ROWS 3492249339 select * from test_sharing where id=99 0 ALL_ROWS 2354865636 select * from T 0 ALL_ROWS 1601196873 select * from T 1 FIRST_ROWS 1601196873 6 rows selected. SQL> alter session set sql_trace=true; Session altered. SQL> alter session set optimizer_mode=first_rows_1; Session altered. SQL> select * from t; no rows selected SQL> select * from T; no rows selected SQL> select sql_text,version_count, executions from V$sqlarea where sql_text like 'select * from t%' or sql_text like 'select * from T%'; SQL_TEXT VERSION_COUNT EXECUTIONS ---------------------------------------- ------------- ---------- select * from t 2 3 select * from test_sharing where id=:a 1 3 select * from test_sharing where id=1 1 0 select * from test_sharing where id=99 1 0 select * from T 3 5 SQL> select sql_text, child_number, optimizer_mode, plan_hash_value from V$sql where sql_text like 'select * from t%' or sql_text like 'select * fro SQL_TEXT CHILD_NUMBER OPTIMIZER_ PLAN_HASH_VALUE ---------------------------------------- ------------ ---------- --------------- select * from t 0 FIRST_ROWS 1601196873 select * from t 1 FIRST_ROWS 1601196873 select * from test_sharing where id=:a 0 ALL_ROWS 3492249339 select * from test_sharing where id=1 0 ALL_ROWS 3492249339 select * from test_sharing where id=99 0 ALL_ROWS 2354865636 select * from T 0 ALL_ROWS 1601196873 select * from T 1 FIRST_ROWS 1601196873 select * from T 2 FIRST_ROWS 1601196873 8 rows selected. SQL> select sql_id,sql_text, child_number, optimizer_mode, plan_hash_value from V$sql where sql_text like 'select * from t%' or sql_text like 'selec SQL_ID SQL_TEXT CHILD_NUMBER OPTIMIZER_ ------------- ---------------------------------------- ------------ ---------- PLAN_HASH_VALUE --------------- 89km4qj1thh13 select * from t 0 FIRST_ROWS 1601196873 89km4qj1thh13 select * from t 1 FIRST_ROWS 1601196873 7gbgb5nzcdcf3 select * from test_sharing where id=:a 0 ALL_ROWS 3492249339 SQL_ID SQL_TEXT CHILD_NUMBER OPTIMIZER_ ------------- ---------------------------------------- ------------ ---------- PLAN_HASH_VALUE --------------- 0890tcnrf5jsv select * from test_sharing where id=1 0 ALL_ROWS 3492249339 7hg3cujy0ya0r select * from test_sharing where id=99 0 ALL_ROWS 2354865636 ahgbnyrbh7bp1 select * from T 0 ALL_ROWS 1601196873 SQL_ID SQL_TEXT CHILD_NUMBER OPTIMIZER_ ------------- ---------------------------------------- ------------ ---------- PLAN_HASH_VALUE --------------- ahgbnyrbh7bp1 select * from T 1 FIRST_ROWS 1601196873 ahgbnyrbh7bp1 select * from T 2 FIRST_ROWS 1601196873 8 rows selected. SQL> set pagesize 9999 SQL> / SQL_ID SQL_TEXT CHILD_NUMBER OPTIMIZER_ ------------- ---------------------------------------- ------------ ---------- PLAN_HASH_VALUE --------------- 89km4qj1thh13 select * from t 0 FIRST_ROWS 1601196873 89km4qj1thh13 select * from t 1 FIRST_ROWS 1601196873 7gbgb5nzcdcf3 select * from test_sharing where id=:a 0 ALL_ROWS 3492249339 0890tcnrf5jsv select * from test_sharing where id=1 0 ALL_ROWS 3492249339 7hg3cujy0ya0r select * from test_sharing where id=99 0 ALL_ROWS 2354865636 ahgbnyrbh7bp1 select * from T 0 ALL_ROWS 1601196873 ahgbnyrbh7bp1 select * from T 1 FIRST_ROWS 1601196873 ahgbnyrbh7bp1 select * from T 2 FIRST_ROWS 1601196873 8 rows selected. SQL> set linesize 200 SQL> / SQL_ID SQL_TEXT CHILD_NUMBER OPTIMIZER_ PLAN_HASH_VALUE ------------- ---------------------------------------- ------------ ---------- --------------- 89km4qj1thh13 select * from t 0 FIRST_ROWS 1601196873 89km4qj1thh13 select * from t 1 FIRST_ROWS 1601196873 7gbgb5nzcdcf3 select * from test_sharing where id=:a 0 ALL_ROWS 3492249339 0890tcnrf5jsv select * from test_sharing where id=1 0 ALL_ROWS 3492249339 7hg3cujy0ya0r select * from test_sharing where id=99 0 ALL_ROWS 2354865636 ahgbnyrbh7bp1 select * from T 0 ALL_ROWS 1601196873 ahgbnyrbh7bp1 select * from T 1 FIRST_ROWS 1601196873 ahgbnyrbh7bp1 select * from T 2 FIRST_ROWS 1601196873 8 rows selected. SQL> select child_number, child_address, stats_row_mismatch, optimizer_mode_mismatch 2 from v$sql_shared_cursor where sql_id='ahgbnyrbh7bp1'; CHILD_NUMBER CHILD_AD S O ------------ -------- - - 0 1A610050 N N 1 1F148DA4 N Y 2 1A630C90 Y N SQL>
You can see an inconsistency in the optimizer_mode resulting in another creation of child cursor. You can try to use the parameter cursor_sharing similar value and bind variables that would also cause child several sliders to create. For the view V$ sql_shared_cursor, check the docs.
HTH
Aman...PS: Please don't bump up to the thread. This is not support so people are not forced to update immediately. All are volunteers so assume that they would update the thread as and when they have / get time to do.
-
SQL +-PROBLEM OF QUERY IN MULTI TABLE
HAI ALL,
ANY SUGGESTION PLEASE?
SUP: SQL +-PROBLEM OF QUERY IN MULTI TABLE
SQL + QUERY DATA:
-----------
SELECT PATIENT_NUM, PATIENT_NAME, HMTLY_TEST_NAME, HMTLY_RBC_VALUE,
HMTLY_RBC_NORMAL_VALUE, DLC_TEST_NAME, DLC_POLYMORPHS_VALUE,
PATIENTS_MASTER1 DLC_POLYMORPHS_NORMAL_VALUE, HAEMATOLOGY1,
DIFFERENTIAL_LEUCOCYTE_COUNT1
WHERE PATIENT_NUM = HMTLY_PATIENT_NUM AND PATIENT_NUM = DLC_PATIENT_NUM AND PATIENT_NUM
= & PATIENT_NUM;
-----------
RESULT:
& PATIENT_NUM = 1
no selected line
---------
& PATIENT_NUM = 2
no selected line
------------
& PATIENT_NUM = 3
PATIENT_NUM 3
PATIENT_NAME KKKK
HMTLY_TEST_NAME HEMATOLOGY
HMTLY_RBC_VALUE 4
4.6 - 6.0 HMTLY_RBC_NORMAL
DLC_TEST_NAME LEUKOCYTE COUNT PREMIUM
DLC_POLYMORPHS_VALUE 60
DLC_POLYMORPHS_NORMAL_VALUE 40-65
-------------
-------------
REAL WILL BE:
& PATIENT_NUM = 1
PATIENT_NUM 1
PATIENT_NAME BBBB
HMTLY_TEST_NAME HEMATOLOGY
HMTLY_RBC_VALUE 5
4.6 - 6.0 HMTLY_RBC_NORMAL
-----------
& PATIENT_NUM = 2
PATIENT_NUM 2
PATIENT_NAME GEORGE
DLC_TEST_NAME LEUKOCYTE COUNT PREMIUM
DLC_POLYMORPHS_VALUE 42
DLC_POLYMORPHS_NORMAL_VALUE 40-65
---------------
& PATIENT_NUM = 3
PATIENT_NUM 3
PATIENT_NAME KKKK
HMTLY_TEST_NAME HEMATOLOGY
HMTLY_RBC_VALUE 4
4.6 - 6.0 HMTLY_RBC_NORMAL
DLC_TEST_NAME LEUKOCYTE COUNT PREMIUM
DLC_POLYMORPHS_VALUE 60
DLC_POLYMORPHS_NORMAL_VALUE 40-65
----------------------------
4 TABLES OF LABORATORY CLINIC FOR DATA ENTRY AND GET REPORT ONLY FOR THE TESTS CARRIED OUT FOR PARTICULAR
PATIENT.
TABLE1:PATIENTS_MASTER1
COLUMNS: PATIENT_NUM, PATIENT_NAME,
VALUES:
PATIENT_NUM
1
2
3
4
PATIENT_NAME
BENAMER
GIROT
KKKK
PPPP
---------------
TABLE2:TESTS_MASTER1
COLUMNS: TEST_NUM, TEST_NAME
VALUES:
TEST_NUM
1
2
TEST_NAME
HEMATOLOGY
DIFFERENTIAL LEUKOCYTE COUNT
-------------
TABLE3:HAEMATOLOGY1
COLUMNS:
HMTLY_NUM, HMTLY_PATIENT_NUM, HMTLY_TEST_NAME, HMTLY_RBC_VALUE, HMTLY_RBC_NORMAL_VALUE
VALUES:
HMTLY_NUM
1
2
HMTLY_PATIENT_NUM
1
3
MTLY_TEST_NAME
HEMATOLOGY
HEMATOLOGY
HMTLY_RBC_VALUE
5
4
HMTLY_RBC_NORMAL_VALUE
4.6 - 6.0
4.6 - 6.0
------------
TABLE4:DIFFERENTIAL_LEUCOCYTE_COUNT1
COLUMNS: DLC_NUM, DLC_PATIENT_NUM, DLC_TEST_NAME, DLC_POLYMORPHS_VALUE, DLC_POLYMORPHS_
NORMAL_VALUE,
VALUES:
DLC_NUM
1
2
DLC_PATIENT_NUM
2
3
DLC_TEST_NAME
DIFFERENTIAL LEUKOCYTE COUNT
DIFFERENTIAL LEUKOCYTE COUNT
DLC_POLYMORPHS_VALUE
42
60
DLC_POLYMORPHS_NORMAL_VALUE
40-65
40-65
-----------------
Thank you
RCS
E-mail:[email protected]
--------I think you want an OUTER JOIN
SELECT PATIENT_NUM, PATIENT_NAME, HMTLY_TEST_NAME, HMTLY_RBC_VALUE, HMTLY_RBC_NORMAL_VALUE, DLC_TEST_NAME, DLC_POLYMORPHS_VALUE, DLC_POLYMORPHS_NORMAL_VALUE FROM PATIENTS_MASTER1, HAEMATOLOGY1, DIFFERENTIAL_LEUCOCYTE_COUNT1 WHERE PATIENT_NUM = HMTLY_PATIENT_NUM (+) AND PATIENT_NUM = DLC_PATIENT_NUM (+) AND PATIENT_NUM = &PATIENT_NUM;
Published by: shoblock on November 5, 2008 12:17
the outer join brands became stupid emoticons or something. try hard -
To UPDATE/DELETE SQL problems
Once I created a connection to my local DB Table, I can INSERT as many times I want. Using this same Table DB, I can't put DAY/remove this line (the one I have just inserted). SELECT works very well and I have not received any SQL errors.
I am positive that all my SQL commands are typed correctly and works as I tested on other data in the same DB table that was created outside my request. It seems that as soon as my application has modified the information in this line, the line becomes locked
Any ideas? Thank you
I managed to solve the problem, guess I wasn't paying enough attention when I reread my INSERT queries, I put single quotes around the int index, so I need these quotes on other queries
-
How can I solve the RDP and SQL problems after cloning of a paralytic?
I got a job Server 2008 R2 system running SQL Server Enterprise 2012 all on an 8 G/4CPU VM and did a ' copy to ' VAPP Cloner.
The new VAPP has been on one VLAN separated. During the copy process, customizing of comments was shortlisted, and I gave the new virtual machine, a new name for the machine. I can access both VLAN via my WIndows 7 x 64 desktop client OpenVPN.
So far so good, I could use the vDC to log on the new machine of vApp using my previous administrator credentials.
I found myself with two problems though...
(1) none of my previous connections will work with SQL Server, when I try to launch SQL Server Management Studio. I get a message saying "Connection failed for user 'newmachine\user'" so maybe the MSN usr for duplicate users are not the same as the original sid user? I think that he could not tell the difference, if everything has been cloned and the machine name has changed.
(2) my RDP 7 Windows client does not connect unless I have configure the new server to allow "a MOP" instead of just "Network Level Authentication" that has been configured on the original server that I cloned from. When I activate "all RDP" I can RDP into the cloned fine system.
The cloned machine had the new name of the machine and a new SID assigned by the cloning process. The original and clone are on VLAN isolated and cannot see. Both not use areas and working groups.
If I leave the cloned server THAT RDP "NLA" value only as the original server, my Windows 7 client gets a message complaining that RDP does not support the NLA for the cloned machine. RDP works fine connecting to the original server that still has not specified NLA. The RDP instance that says I need enabled NLA, watch NLA is activated in the about box.
Someone at - he saw either of these issues? Any suggestions?
Thanks, Dave
Hi, my understanding is that sysprep does much more than simply by changing the SID of the box, it will also use the SID to regenerate the local MSN accounts system which is problably the origin of the problem, you're experiency. This is done for the security reasosns avoid guests who have accounts with the same sid on different machines. There is a tool called newsid that changes the SID of the server and let the system SID accounts because they were, but it has been known to have other issues but allow him to achieve what you want? I thiknk MS have retired it now, but you can always download on the net.
If you need get SQL running sysprep and want to automate the process to set up your DB and users following post useful:
-
form_check.php returns the Configuration of SQL problem
Hello, I'm hosting the MUSE outside BC and the shape cannot send e-mail. http:// /scripts/form_check.php < site > shows that there is a problem of Configuration of SQL. How to repair?
SQL is just unused (like many other technologies that are installed on your hosting problem).
Please refer to Troubleshooting Muse form used on the servers of third party Widgets>. Generally, the arguments are going to spam or the host has restrictions on what emails, you can send to. It is common for the default hosts only allow sending messages of form to an e-mail address on the same domain (monentreprise.com) as the Web site.
-
Body of function from PL/SQL query SQL - problem with where Cluase return
Hi all
I have problem with sub PL/SQL. Where clause does not filter the values even when I change the value: P7_INVESTIGATOR. I have marked with an asterisk for where clause where I want the values to filtered.
DECLARE
v_sql varchar2 (5000);
v_inv VARCHAR2 (100);
Start
v_inv: = UPPER(:P7_INVESTIGATOR);
v_sql: = ' select TBLCASES. INVESTIGATOR as an INVESTIGATOR,';
v_sql: = v_sql | "TBLCASES. CASENUMBER as CASENUMBER,';
v_sql: = v_sql | "TBLCASES. OPENDATE as OPENDATE,';
v_sql: = v_sql | "TBLCASES. ESTCOMPLETE as DATE_CIBLE,';
v_sql: = v_sql | "TBLCASES. STATUS of STATUS ';
v_sql: = v_sql | "TBLCASES. Case CODE case CODE as,';
v_sql: = V_sql | "TBLCASES. FAIR_HOTLINE as FAIRHotline,';
v_sql: = v_sql | "TBLCASES. NYSIG as NYSIGCase,';
v_sql: = v_sql | "TBLCASES. The REGION';
v_sql: = v_sql | "TBLCASES. PROGAREA as PROGArea ';
v_sql: = v_sql | ' from TBLCASES where 1 = 1';
**************************************************************
If v_inv <>null then
v_sql
: = v_sql | "and UPPER (trim (tblcases.investigator)) = UPPER (trim (v_inv))';
END IF;
***************************************************************
v_sql: = v_sql | "order by tblcases.investigator";
Return v_sql;
end;
Thank youwrote:
Or it is possible to write it this way:if v_inv is not null then v_sql := v_sql ||' and UPPER(trim(tblcases.investigator)) = UPPER(trim(:P7_INVESTIGATOR))'; END IF ;
In this case we will use bind variables and we all know that it is very important.
Lev
Of cause, it is the best option. and I strongly suggest the OP to use.
But it depends on how the sql is used later.
Without knowing that, we cannot be sure if the item is available here. -
SQL - problem starting Data Modeler
Hello
I created a relational model with Oracle SQL Developer maker data, with a few tables, and everything worked ok.
Yesterday, I made some changes to the model, add columns and another table, saved the template and closed the Data Modeler.
Today - when I tried to open the template, I get only an error 'some objects are not loaded correctly. See the log file for more details"
Shows that the newspaper at the bottom of the Data Modeler: ' Open Design: "model name" "and no details of what went wrong. No other details are provided and as far as I can see - and now I can't view the model at all.
Any ideas how to find the problem / fix in order to retrieve the created model?
Thank you
CoenraadYou must open the file ' a - erd2.xml ' (with text editor) and look for the name of your models - they are in such a construction:
Logic
....
You should not some special characters in the name of the party: <&>'.
'Name' in the example above makes sense (the text between the opening tag and closing name -Philippe
&> -
Hello
I am John and I am facing problem with the sql interface.
his does not work. How do I solve it
VinilVinil,
Yes, it might be.
1. I think you go to control panel-> administration-> sources ODBC tools.
2. not to do this, go to C:\WINDOWS\system32\odbcad32.exe and create a DSN system here.
3. now, try to do the same step in the opening of the data preparation editor and... to see the name of the newly created System DSN
I would like to know if it works.
Sandeep Reddy, Enti
HCC
http://hyperionconsultancy.com/ -
PL | SQL problem: PLS-00302:
Hello
I'm runing trouble a piece of PL/SQL. The problem is that I get an initialization error, but the variable cannot be initialized.set serveroutput on; declare cursor cust is select order_id, item_id from ph2 order by order_date, customer_id, ship_date, order_id, item_id for update of order_id, item_id; neworder_id ph2_item.order_id%type; multicust multi_site_cust.cust%type; newitem_id ph2_item.item_id%type; begin /*Initialising neworder_id */ select max(order_id)+1 into neworder_id from sales_order; newitem_id := 1; for c_rec in cust loop /*initilising multicust */ select customer into multicust from multi_ships_cust order by customer; update ph2_item p set p.order_id = ( case when c_rec.customer_id = multicust then neworder_id else neworder_id + 1 end ), p.item_id = ( case when c_rec.customer_id = multicust then newitem_id + 1 --else -- newitem_id end ) where current of cust; end loop; end; /
Evil in the definition of the cursor. You must select the customer_id in the definition of the cursor cust. check the code below
Set serveroutput on;
declare
client cursor is
Select order_id, item_id, customer_id ph2
order of order_date, customer_id, order_id item_id, ship_date
update the order_id, item_id;neworder_id ph2_item.order_id%type;
multicust multi_site_cust.cust%type;
newitem_id ph2_item.item_id%type;Start
/ * Initialization neworder_id * /.
Select
Max (order_id) + 1
in
neworder_id
Of
sales_order;newitem_id: = 1;
for c_rec looping cust
/ * initilising multicust * /.
Select
customer
in
multicust
Of
multi_ships_cust
order by
customer;Update
ph2_item p
set
p.order_id =
(
case
When
c_rec.customer_id = multicust
then
neworder_id
on the other
neworder_id + 1
end
),
p.item_id =
(
case
When
c_rec.customer_id = multicust
then
newitem_id + 1
-other
-newitem_id
end
)
the location being the customer.
end loop;
end;
/Published by: cdkumar on October 6, 2008 14:55
-
SQL problem - repetition of a higher number only
Just had a question in terms of the output shown below. I haveIf there is a way where I can repeat the value of the overdraft_amount column unlesss it rose?
Example - line no. 25 is more than line # 26, so he must repeat the highest value.Here's the logic that I'm trying to implement: (is it possible to do it in oracle sql? If yes how?)
If the previous value > current value
then keep repeating previous value
otherwise continue to repeat current value
end
Select acct.account_number, aday.day_key, acct.overdraft_amount
Of
ACCT DIM.account,
DIM.account_day aday,
WHERE aday.account_key = acct.account_key
and aday. DAY_KEY < = 20150331
and aday. DAY_KEY > = 20150101 ;
Maybe
with
data in the form of
(select 1 key, 1300 overdraft_amount of all the double union)
Select 2,1300 from all the double union
Select 3,1300 from all the double union
Select 4,1406 from all the double union
Select 5,1406 from all the double union
Select 6,1300 from union double all the
Select 7,1300 from all the double union
Select 8,1500 from all the double union
Select double 9,1500
)
Select key, overdraft_amount, max (overdraft_amount) on max_overdraft_amount (key control)
from the data
KEY OVERDRAFT_AMOUNT MAX_OVERDRAFT_AMOUNT 1 1300 1300 2 1300 1300 3 1300 1300 4 1406 1406 5 1406 1406 6 1300 1406 7 1300 1406 8 1500 1500 9 1500 1500 Concerning
Etbin
-
Construction of SQL problem or something else?
Hello, I'm strugling to 10.2.0.3 with a SQL, I would be grateful for some suggestions.
That's what I get when I run this sql:
and I table having partition named PART100730, when I make this selection, I get this partition name:SQL> select '''%'|| to_char(sysdate,'mmdd') ||'%''' from dual; '''%'||T -------- '%0730%'
but, when I do this sql, I get no lines, and I don't understand why.SQL> SELECT partition_name 2 FROM dba_tab_partitions 3 WHERE table_name = 'PART' 4 AND partition_name LIKE '%0730%' 5 ; PARTITION_NAME ------------------------------ PART100730 SQL>
: (SQL> SELECT partition_name 2 FROM dba_tab_partitions 3 WHERE table_name = 'PART' 4 AND partition_name LIKE '''%'|| (select to_char(sysdate,'mmdd') from dual) ||'%''' ; no rows selected
This can give you some tip!
SQL> select * from emp where ename like '''%'||(select ename from emp where empno=7902)||'%''' ; no rows selected SQL> ed Wrote file afiedt.buf 1* select * from emp where ename like '''%||(select ename from emp where empno=7902)||%''' SQL> / no rows selected SQL> select * from emp where ename like '%'||(select ename from emp where empno=7902)||'%'; EMPNO ENAME JOB MGR HIREDATE ---------- ----------------------------------- --------- ---------- --------- SAL COMM DEPTNO ---------- ---------- ---------- 7902 FORD ANALYST 7566 03-DEC-81 3000 20
-
I use the following SQL and it works very well for retrun me 5 random recordings of the entire database.
SELECT penpals.*, Round (((acos (sin ((-74.1192 * pi () / 180)) * sin ((lon * pi () / 180)) + cos ((-74.1192 * pi () / 180)) * cos ((lon * pi () / 180)) * cos (((40.9353-lat)*pi()/180)))*180/pi())*60*1.1515)) distance)))))
CORRESPONDENTS
LEFT JOIN geozip ON penpals.zip = geozip.zip
WHERE geozip.zip IS NOT NULL
ORDER BY RAND() LIMIT 5
The round function is used to calculate the miles between 2 zip codes in the United States, based on longitide and latitude set as a named column distance.
This works very well and gives me what I need. However if I add the following
AND distance < 26 after WHERE geozip.zip IS NOT NULL
I get the error
Unknown column 'distance' in ' where clause'
But if I try to ORDER OF the distance, it works for sorting.
Anyone have any ideas? Thank you.oO (VernMan)
> I use following SQL and it works very well for retrun me 5 files randomly
> of the entire database.
>
> SELECT penpals.*, Round (((acos (sin ((-74.1192 * pi () / 180)) * sin ((lon * pi () / 180))))))
> + cos ((-74.1192 * pi () / 180)) * cos ((lon * pi () / 180)) * cos (((40.9353 -
((> lat)*pi()/180)))*180/pi())*60*1.1515)) distance
> CORRESPONDENTS
> Geozip LEFT JOIN ON penpals.zip = geozip.zip
> Geozip.zip WHERE IS NOT NULL
> ORDER BY RAND() LIMIT 5
>
> The rounding function is used to calculate the miles between 2 postcodes in
> in the United States, based on longitide and latitude, defined as a named column distance.
>
> This works very well and gives me what I need. However if I add the following
> AND distance< 26="" after="" where="" geozip.zip="" is="" not="">
> I get error
> Unknown column 'distance' in ' where clause'
>
> but if I try to ORDER OF distance he works to sort.
>
> Anyone have any ideas? Thank youTry
SELECT...
Of...
WHERE THE...
HAVING distance<>
ORDER IN...Micha
-
SQL problem - comprehensive selection
All,
I have the SQL below which returns me the correct data, how I would return another (assignment ID) column in the selected table without the group by? also as table date tracking, which means that the person_id and Max hours are not sufficient to identify a line of uniquly, I can't use it as a sub select.
Select
person_id,
Max (normal_hours)
Of
per_all_assignments_f
where
SYSDATE between effective_start_date and effective_end_date
and assignment_status_type_id = 1
Group
person_id
I worked around in a circle with this one so I can miss obvious somethig. I need basically ID assignment in the assignment of the person (identified by the ID of the person) work the most hours (normal hours). This baiscaly me givies a primary assignment for each person based on the Max Normal_Hours
Hope someone can point me in the right direction
Concerning
Published by: SolomonHill on November 24, 2009 15:09Hello
To find the associated assignment_id Max (normal_hours):
select person_id, MAX(normal_hours), MIN (assignment_id) KEEP (DENSE_RANK LAST ORDER BY normal_hours) AS top_assingment_id from per_all_assignments_f where sysdate between effective_start_date and effective_end_date and assignment_status_type_id = 1 group by person_id
In case of tie, the above query will choose the lowest assignment_id that goes with the MAX.
For example, if all the lines to person_id = 98765:ASSIGNMENT_ID NORMAL_HOURS ------------- ------------ 123 20 234 20 345 20 456 15 123 10
then MAX (normal_hours) is 20, but what is the assignment_id that goes with 20? There are three different assignment_ids which have an equal right to the most hours. MIN in the above query is said that the lowest (123 in this example) one will be returned.
-
Hello
I'm trying to run the dynamic SQL string. It generates an error
ORA-00932: inconsistent data types: expected - was -.
Here is the code:
CREATE OR REPLACE PROCEDURE test_prc (d_output on sys_refcursor)
IS
l_sql VARCHAR2 (1000);
l_deptid NUMBER (10): = 30;
BEGIN
l_sql: = ' select empno, ename from emp where ename = "DISTRICT" and deptno =: l_deptid';
EXECUTE IMMEDIATE l_sql IN d_output USING l_deptid;
EXCEPTION
WHILE OTHERS THEN
dbms_output.put_line ('Err > ' |) SQLERRM);
END;
/
Set serveroutput on
declare
t sys_refcursor;
Start
test_prc (t);
end;
/
ERR > ORA-00932: inconsistent data types: expected - was -.
can you please tell me where I have to fix the code?
Thank you and best regards,
RSDHello
I think the output you get you want to switch to a ref cursor You can try this.
-not tested
EXECUTE IMMEDIATE l_sql IN d_output USING l_deptid;
BEGIN
Ref_cur OPEN FOR l_sql using l_deptid;-I hope this is your test program that you use no parameter for the SQL code.
Thank you
Maybe you are looking for
-
CONVERSION OF TABLE 1 D IN TABLE 1 D OF THE CLUSTER
I MADE A TABLE OF (16 LOCATIONS) USING THE ATTACHED VI. THEN DO A DEF TYPE OF IT SO I CAN USE IT SOMEWHERE ELSE. WHEN I CONNECT A TABLE 1 D 16 DBL FOR THAT CHART, I AM GETTING AN ERROR. (1. SOURCE TYPE IS CLUSTER OF 16.) (2 SOURCE TYPE IS 1 D TABLE O
-
Driver printer brother HL-2035.
Brother HL-2035 printer driver does not load on my Packard bell laptop running on XP Professional system. Need help to fix it please.
-
How can I get back Admin rights no one has them on the computer?
How can I get back Admin rights no one has them on the computer
-
Silverlight.config.exe. appears again msg then causes a gel I can not write the new message of Windows Live Essentials due to the demand of Silverlight.configuration.exe freeze my computer. How to replace this command?
-
The XPS 8900 accepts modules 2666 mhz? I think the stock modules are just 2133 mhz. I also guess you can't combine both correct?