Prefix with table name
I have a query which involves two tables with both have some common columns ..I thought that if we don't prefix column names with the table names we would get a "column ambigously defined" error so that we will know that we need to prefix that column name with the table name. But I am not getting this error and instead I am getting wrong results as a consequence of not prefixing the column name with the table name.
Is this usual? How do I avoid this?
user8117487 wrote:
I have a query which involves two tables with both have some common columns ..I thought that if we don't prefix column names with the table names we would get a "column ambigously defined" error so that we will know that we need to prefix that column name with the table name. But I am not getting this error and instead I am getting wrong results as a consequence of not prefixing the column name with the table name.
Is this usual? How do I avoid this?Column ambigously defined means that a similar column is present in the table. A simple case;
select emp_id from emp e, dept d
where e.emp_id=d.emp_id
Ex Senior DBA
It is not easy being a DBA
Similar Messages
-
DatabaseProcedure with return type prefixed with schema name
Hi (Paco)
I have a question about the DatabaseProcedure class. We are using Oracle proxy users for our database connections.
Everything is accessed via a database role that are granted to the logged on user. All our database objects, tables etc are protected with this database role.
When I want to call a database function/procedure I need to add the schema name as a prefix to the custom database object that we uses for parameters/return types.
So far so good. I can also define a parameter prefixed with schema name via the DatabaseProcedure.registerArrayType ...
But when I try to define a function call that uses this parameter I get an error saying "Declaration is not valid".
The problem is located to the PROCEDURE_DEFINITION regular pattern:
private static final Pattern PROCEDURE_DEFINITION = Pattern.compile("\\s* (FUNCTION|PROCEDURE) \\s+ ([\\w.$]+) \\s* (?:\\((.*?)\\))? \\s* (?:RETURN\\s+(\\w+))? \\s* ;? \\s*", CASE_INSENSITIVE | COMMENTS | DOTALL); The return type cannot be prefixed with the schema name.
Any good suggestions or workarounds?!
I actually did change the pattern runtime via reflection to make it work - but I really don't like this solution in the long run!
/Torben
Edited by: Zonic on 2013-05-07 10:52Hi Torben,
I think I have a workaround for the issue that might work for you. If you look at the source of <font face="courier">DatabaseProcedure.registerArrayType</font> you find that it actually calls <font face="courier">DatabaseProcedure.registerCustomParamType</font>.
public static void registerArrayType(String name)
registerCustomParamType(name, Types.ARRAY, Array.getORADataFactory(), name);
}As a workaround you could replace your calls to <font face="courier">DatabaseProcedure.registerArrayType</font> with calls to <font face="courier">DatabaseProcedure.registerCustomParamType</font> as follows.
// Instead of DatabaseProcedure.registerArrayType("NAME.WITH.DOTS") call:
DatabaseProcedure.registerCustomParamType("anyNameWithoutDots", Types.ARRAY, Array.getORADataFactory(), "NAME.WITH.DOTS"); // Don't forget to use uppercase here.
DatabaseProcedure dp = DatabaseProcedure.define("procedure my.procedure(param1 in out anyNameWithoutDots)");
DatabaseProcedure.ParamType type = dp.getParamDef(0).getType();
System.out.println(type.getName() + " is " + type.getTypeName()); // ANYNAMEWITHOUTDOTS is NAME.WITH.DOTSThis way you don't have to use the "illegal" name in the DatabaseProcedure definition.
Regards,
Paco van der Linden -
Problem with writing a procedure with table name as an input parameter
Hi all,
I am writing a procedure with table name as an input parameter:
below is the code
create or replace procedure prc(in_tbl in varchar2)
as
begin
execute immediate ' truncate table tlb ';
insert into tbl
select a,b,c from in_tbl;
end;user579585 wrote:
Hi all,
I am writing a procedure with table name as an input parameter:
below is the code
create or replace procedure prc(in_tbl in varchar2)
as
begin
execute immediate ' truncate table tlb ';
insert into tbl
select a,b,c from in_tbl;
end;You'll also need to use dynamic sql for the insert:
execute immediate 'begin insert into tbl select a,b,c from '||in_tbl||'; end'; -
Problem with table name lengths.
Has anyone experienced with table name length problem?
When tables are created with schema registration, and the name is longer than 14 characters, the table is created. But when I "select * from xxxx_xxxx_xxxx_xxxx" it says that the table doesn't exist.
What's the max length of a table name? Or is this a problem with XDB?
Thanks,
BenjaminFound the problem.
All table names must be all capitalized and seperated with underscore.
Is there something I need to set in oracle? or is this a bug? The tables are created but can't be accessed because of the case of table name... that doesn't make sense. -
Dynamic SQL Statement with table name
Dear all
i like to have a SQL statement with a dynamic tablename. Is this possible? If yes, how?
should be something like "select * from <mytablename>"
Thank you
HerbertYes this is possible. use the below reference code for this.
data: g_tablename type w_tabname,
gv_dref TYPE REF TO data.
FIELD-SYMBOLS: <g_itab> TYPE STANDARD TABLE.
gv_tabname = p_tablename (take table name form selection screen or as per ur requirement)
CREATE DATA gv_dref TYPE TABLE OF (g_tabname).
ASSIGN gv_dref->* TO <g_itab>.
now use the below select query to fetch the data
SELECT * FROM (gv_tabname) INTO TABLE <g_itab>.
Hope this will help -
OPENING CURSOR WITH TABLE NAME AS PERAMETER
hi all,
here i have a problem. please help me.
create or replace procedure MAX_ID
(COLUMN_NAME IN VARCHAR2,
TABLE_NAME IN VARCHAR2) IS
CURSOR MAX_CURSOR IS SELECT COLUMN_NAME FROM TABLE_NAME;
begin
END;
in the above procedure table name and column name are in parameters. I have to declare cursor with the in parameter values. How to solve this problem. Give me solution as soon as possible. Waiting for your valuable suggestions.
with regards,
valiHi,
You will need to use dynamic SQL to be able to do that. This one returns a single row but you may need to work more on this to achieve the results which you are looking for based on your requirement.
PROCEDURE get_data_dynamically_pr(pv_sqlstr VARCHAR2,pn_count IN OUT NUMBER) IS
ln_cursor NUMBER;
ln_rows NUMBER(5);
BEGIN
/* Retrieve the count from a table we passed */
ln_cursor := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(ln_cursor, pv_sqlstr,DBMS_SQL.NATIVE);
DBMS_SQL.DEFINE_COLUMN(ln_cursor, 1, pn_count);
ln_rows := DBMS_SQL.EXECUTE(ln_cursor);
IF DBMS_SQL.FETCH_ROWS(ln_cursor) = 0 then
RETURN;
END IF;
DBMS_SQL.COLUMN_VALUE(ln_cursor, 1, pn_count);
DBMS_SQL.CLOSE_CURSOR(ln_cursor);
EXCEPTION
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR (-20400,SQLERRM||'Exception raised in dynamic sql proc..');
END;
I hope this might be useful to you. -
Difference between with table name with * and without *
Hi..
I had seen some of the standard abap that the table name had *, like *ekpo. What is the meaning? What is the difference between with * and without * ?
Thanks and Regards,
RishikaHi rishika,
1. This is actually a facility provided in abap syntax.
2. It is usually checked while saving a record.
3. For eg.
If we have one variable
EKKO
and another *EKKO
(They both are same only, with same structure)
(but two different variables)
4. The functional meaning, for usage purpose,
of *EKKO is OLDEKKO.
5. While saving the transaction,
the data is saved only if there is any change
in the values.
IF EKKO <> *EKKO.
*--- SAVE
ELSE.
MESSAGE 'NO DATA CHANGED'
ENDIF.
6. We can aswell use any other variale
eg. oldekko
oekko
myekko
etc,
7. But for business meaning,
R/3 has the facility for *
1. we can use almost everywhere.
2. just copy paste
report abc.
TABLES : T001.
TABLES : *T001.
DATA : ITAB LIKE EKKO.
DATA : *ITAB LIKE EKKO.
DATA : NUM TYPE I.
DATA : *NUM TYPE I.
regards,
amit m. -
Problem with table name in procedure
Hi Team,
I have a procedure in which table name is stored in a variable.
I want to use this table_name in one select statement of a same procedure.
declare
v_table_name varchar2(30);
begin
v_table_name:='EMPLOYEE';
FOR cur IN
( select ename,empno,deptno from v_table_name )
loop
dbms_output.put_line(cur.ename);
end loop;
end;
Edited by: rajendra on Feb 26, 2012 9:29 AMsb92075 wrote:
you must utilize EXECUTE IMMEDIATEWhy? Plain cursor variable will do:
declare
v_table_name varchar2(30);
v_cur sys_refcursor;
v_ename varchar2(20);
v_empno number;
v_deptno number;
begin
v_table_name:='EMP';
open v_cur for 'select ename,empno,deptno from ' || v_table_name;
loop
fetch v_cur
into v_ename,
v_empno,
v_deptno;
exit when v_cur%notfound;
dbms_output.put_line(v_ename);
end loop;
close v_cur;
end;
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER
PL/SQL procedure successfully completed.
SQL> SY. -
How to Find Logical Database with table name
Shankar
Version 4.6x
If you need to find the logical database for a table name, you can used <b>SE36</b> - Logical Database Bulider.
Steps :-
Go to transaction <b>SE36</b>
Click <b>Extras -> Table usage</b>
Supply the Table name and hit enter.
A Display Logical Database will be shown on a pop-up windows.
Reward points if it is usefull ....
Girish -
HI Experts,
I need to give my new table name as z_xxx_xxxx_xxxxxx.
But iam not able to give this name and create a new table since.
The length is bigger.
and it is not allowing me to keep the undersocres in the second place.
Can any one adviceHi Karthick,
Check out the following links:
http://help.sap.com/saphelp_45b/helpdata/en/0d/d2f7d04a0c11d182b80000e829fbfe/content.htm
http://help.sap.com/saphelp_nw04/helpdata/en/9f/4a56b2185851468b39b719daa2d3aa/content.htm
Regards,
Rajesh K Soman
<b>Please reward points if found helpful</b> -
Sql Except query to Display mismatched records along with Table names
Hi
I am using below query to display mismatch records between two tables
SELECT * FROM table1
EXCEPT
SELECT * FROM table2
UNION
SELECT * FROM table2
EXCEPT
SELECT * FROM table1
This displays mismatched records like below
Sunil 1000 india
Sunil 1500 india
I would like to display even the table names in the result For ex;
Sunil 1000 india Table1
Sunil 1500 india Table2
Can you please help us in this regard.cnk_gr's query should work for you.
One change that I would make is to use UNION ALL, not UNION. UNION eliminates duplicate rows, which means SQL has to do additional work (sort the result and then check for duplicates).
So if you can have duplicates and don't want them in your result, then you would use UNION. And if you can have duplicates and you want the duplicates in the result, you would use UNION ALL. But in cases like this, where you know you cannot have
duplicates (because column 1 contains 'TABLE1' for every row in the first half and column 1 contains 'TABLE2' for every row returned from the second half of the query), you should always use UNION ALL. It will be more efficient.
Tom -
Mode for check data from R/3 (with tables name)
I have some table´s technicals names that will be check if the data loading in this is forwarding to BW.
Anyone can tell me what´s the procedure to know if data from some R/3´s table (standard) is being load into BW ????
Regards.In this instance - it's via datasource 0MATERIAL_TEXT
To find this out - I checked the description of the table - then based on experience knew it to be that datasource
Difficult to give you hard and fast rules for EVERY table!
This one was simpel it was a view on MAKT - others could be inside thousands of lines of function module reads, inside changepointer BADIs - anywhere! -
How Discoverer Reports cope with table name changes
I want to change the name of an oracle table that is queried by a number of Discoverer reports owned by various users.
I have been told that Discoverer might have the smarts to handle this without manual intervention of users having to open their reports and repoint them to the new tablename. Would someone be able to enlighten me?Thanks Guys for help.
Additionally I'd like to add for the purpose of the name change is business driven and therefore it is important that business (report writers) see the new name so.....
For each simple folder in the EUL there are there 3 attributes you need to be aware of:
(1) Folder Name (the name as seen in Discoverer)
(2) Identifier
(3) Physical Database Object name
(1) and (2) are used by a Disco workbook to resolve back to the physical object name.
Therefore, you can change either (1) or (2) [but not both] and still have the workbook resolving back to the physical object name on the folder (ie (3)).
In summation, I changed (1) and (3) while leaving (2) unchanged to resolve the whole glorious mess.... -
How to write a function with table name as parameter
I created a function like this:
create or replace function "GETNAME"
(did in NUMBER, dtable in VARCHAR2)
return VARCHAR2
is
dname varchar2(200);
begin
select lastname || ' ' || firstname
into dname from dtable
where id = did;
return dname;
end;
i got an error: table or view does not exist.
Could somebody tell me how to fix it?
Thanks,
Jenor by using a reference cursor: create or replace function dynamic_cursor (pTab varchar2)
return sys_refcursor as
c sys_refcursor;
begin
open c for 'select * from '|| pTab;
return c;
end;
SQL> exec :c := dnamic_cursor('emp');
SQL> exec :c := dynamic_cursor('emp');
PL/SQL procedure successfully completed.
SQL> print c;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7566 JONES MANAGER 7839 02-APR-81 2975 1000 20
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7788 SCOTT ANALYST 7566 09-DEC-82 3000 20
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 12-JAN-83 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7934 MILLER CLERK 7782 23-JAN-82 1300 10
7945 CINDY SALESMAN 7698 16-JAN-83 1800 30
7950 TINA SALESMAN 7698 18-JAN-83 1850 30
16 rows selected.
SQL> -
Prefixing the schema owner to the table name
I have entity objects in my JClient app that were created from tables owned by USER1. When I connect to my JClient app as USER2 the DML fails because the table names are not prefixed by the table owner (USER1). I don't want to use public synonyms and I don't want to customize my view objects just to prefix the table names with the table owner. How could I prefix all of the table names with the table/schema owner by default?
We have been using another approach. We change the "current schema" at the db session level. This avoids having to define public synonyms and having to fully qualify names. It also allows us to have the same application schema defined multiple times in a db instance, which is useful for testing.
While our real code is bit more complicated, basically we implement the afterConnect() and prepareSession() methods on an appication module with a call to our utility method:
protected void afterConnect() {
super.afterConnect();
setupSession('hr');
protected void setupSession(String currentSchema) {
try {
log.debug("Setting current schema to: " + currentSchema +
" via: call alter session set current schema " + currentSchema);
Statement stmt =
getDBTransaction().createStatement(DBTransaction.DEFAULT);
stmt.execute("alter session set current_schema=" + currentSchema);
stmt.close();
} catch (SQLException e) {
if (e.getErrorCode() == 1435) {
log.info("Couldn't set the current_schema to " + currentSchema +
" because it doesn't exist in the target db.");
} else {
log.error("Error setting current_schema in DB context!", e);
} catch (Exception e) {
log.error("Error setting current_schema in DB context!", e);
}
Maybe you are looking for
-
What is change order request ?
hi what is change order request ,is it change management in that case what is change management . can we change sales order information also ... thanks in advances ...
-
Do you own 100% of the copyright of the materials you create from using Adobe products?
Hi, I'm thinking of getting the CS6 Creative Suite or Master Collection (Student & Teacher License) for my new iMac. I do alot of original graphics, videos and illustrations, and plan to start making my own music using the different Adobe software. I
-
Business names, incorporating, and apple development account; etc.
Hello All, The apple development account I have is the "as an individual" type but I am planning to start a corporation in the near future (still distributing in the same way on the app store). When that happens is there anyway to change my existing
-
In Organiser, is it possible to display the fiename below the image thumbnail (RAW CR2 files)?
-
CD gets recognized but cannot import or play
When a CD is placed in the CD/DVD drive, iTunes recognizes it and populates the track names, lengths, album art and everything. If I attempt to play the CD, iTunes will skip quickly from track to track, in order, but not play any of the songs. If I a