PL/SQL :: Native Dynamic Sql
Jan 8, 2013
find the below scripts .
drop table test_arp;
create table test_arp
(
first_name varchar2(1000),
last_name varchar2(1000)
);
[Code]....
when i select the above table ,i will be getting the result as shown
first_name , last_name
CONTROL PANEL
ORACLE SEA
WILLIAMS
RAHUL KUMAR
I need to make a table which will be having the following data and structure
col1 col2 col3
CONTROL ORACLE RAHUL
.i.e , depending on the number of not null values in the first column (first_name), i will be creating a table dynamically ,which is going to have as many columns as the number of values and the naming convention is col1,col2,col...........
I designed the below procedure to CREATE OR REPLACE PROCEDURE ARP
AS
C NUMBER:=1;
BEGIN
FOR I IN (SELECT FIRST_NAME FROM TEST_ARP WHERE FIRST_NAME IS NOT NULL)
LOOP
IF C=1 THEN
[Code]...
But when i execute this code , i get the below error
ORA-00984: column not allowed here
ORA-06512: at "ARP", line 17
ORA-06512: at line 1
View 9 Replies
ADVERTISEMENT
Aug 13, 2012
Let me the difference between the DBMS_SQL and Execute immediate .
*) Which one is faster ?
*) Where to use DBMS_SQL and Execute immediate (correct usage of both)?
View 4 Replies
View Related
Sep 14, 2007
I would need to translate the Oracle PL/SQL procedure to SQL Server 2000 SP4.
This is a package (body) that needs to be translated into a form that SQL server 2000 can unserstand it.
AS
FUNCTION object_name_fix (sobjectstring IN VARCHAR2)
RETURN VARCHAR2
AS
[Code].....
View 1 Replies
View Related
Nov 8, 2010
I've been trying to setup ASM disks for two node cluster using ASMLib. It's a multipath environment
Quote:multipath -ll
mpath2 (36842b2b000528f8d0000029b4ccead44) dm-1 DELL,MD32xx
[size=280M][features=3 queue_if_no_path pg_init_retries 50][hwhandler=1 rdac][rw]
\_ round-robin 0 [prio=100][active]
\_ 1:0:0:1 sdc 8:32 [active][ready]
\_ round-robin 0 [prio=0][enabled]
\_ 1:0:1:1 sdl 8:176 [active][ghost]
[code]....
I've been following Metalink note 602952.1, 309815.1 and 605828.1
metalink note 602952.1 states Quote:Note: Keep in mind for ASMLIB disks you will need to use the /dev/dm-* disks instead of the /dev/mapper/mpath* devices since they are present in the partition table ==)> /proc/partitions and ASMLIB will look at that file during the disk discovering phase. If you do not use the disks located at /dev/dm-* then ASM will not be able to discover them. and to create ASM disks with Quote:/etc/init.d/oracleasm createdisk DISK1 /dev/dm-<disk><partition> Also further stating Quote:NOTE: When scanning, only the device names known by the kernel are scanned. With device-mapper, the kernel sees the devices as /dev/dm-XX. The /dev/mapper/XXX names are created by udev for human readability. Any configuration of ORACLEASM_SCANORDER or ORACLEASM_SCANEXCLUDE must use the dm prefix.My environment is RHEL5 and towards the end of the note it says Quote:Note: On release RH 5 the /dev/dm-N devices are not persistent, starting, these devices are no longer created by udev. So release RedHat 5 you can create the ASMLIB disks on the /dev/mpath/<partition> or /dev/mapper/<partition>
Example:
# /etc/init.d/oracleasm createdisk VOL1 /dev/mpath/sata01p1
Or
# /etc/init.d/oracleasm createdisk VOL1 /dev/mapper/mpath2p1
Therefore I created a ASM disk using /dev/mapper path and it is only visible on the node it was created. Even after scandisks on other node it is still not visible when listdisks/oracleasm-discover
I've also tried creating the asm disks with dm-12 option and the same, disk get created but not visible on the other node.
Moreover if I restart the oracleasm restart the disk disappears from the node that it was visible Quote:
[root@db2 ~]# /etc/init.d/oracleasm createdisk vol1 /dev/mapper/mpath6p1
Marking disk "vol1" as an ASM disk: [ OK ]
[root@db2 ~]# ls -l /dev/oracleasm/disks/*
brw-rw---- 1 oracle dba 253, 12 Nov 8 10:22 /dev/oracleasm/disks/VOL1
[root@db2 ~]# /etc/init.d/oracleasm scandisks
Scanning the system for Oracle ASMLib disks: [ OK ]
[code]....
But disk lable is there and could be seen from both nodes on the same partition Quote:
head /dev/mapper/mpath6p1
VOL1ORCLDISKVOL1
My suspicion is on multipath configuration. I've tried both (not at the same time) combinations given below.
Quote:ORACLEASM_SCANORDER="dm"
ORACLEASM_SCANEXCLUDE="mpath mapper sd sda sdb"
and
Quote:ORACLEASM_SCANORDER="mapper"
ORACLEASM_SCANEXCLUDE="mpath dm sd sda sdb"
But still the problem is there, (disks disappears when asm is restarted and never visible on the "other" node).
View 8 Replies
View Related
Aug 26, 2011
we can you java code natively with Oracle. But I didn't get how to decide when to use native java in oracle and when to use pl/sql.
View 5 Replies
View Related
Apr 8, 2013
I'm using dynamic sql (DBMS_SQL) to define columns of ref cursor. It works Ok but the problem is when i'm using PL/SQL CURSOR in the REF CURSOR. Then,I'm getting :
Error at line 3
ORA-00932: inconsistent datatypes: expected NUMBER got CURSER
ORA-06512: at "SYS.DBMS_SQL", line 1830
ORA-06512: at "TW.PRINT_REF_CURSOR", line 28
ORA-06512: at line 9
Here is my code:
set serveroutput on
exec DBMS_OUTPUT.ENABLE(1000000);
declare
l_cursor sys_refcursor;
begin
[code]....
Is there a solution or bypass?
View 3 Replies
View Related
Apr 28, 2013
I am new to Oracle PlSql. I found PlSql block do not allow us to write DDL as DML queries. "How come DDL are allowed to work in Dynamic SQL using EXECUTE IMMEDIATE".
how come this become possible in EXECUTE IMMEDIATE and not in simple PL/SQL block. What extra feature EXECUTE IMMEDIATE has and why it is designed like this?will be outout of below and why?
Test1 Table
--------------
AB
----
1010
DECLARE
[code]...
View 3 Replies
View Related
Jan 11, 2011
I want get dynamic column names and its corresponding values...Consider the below sample code
CREATE TABLE LECTURER1
( ID NUMBER(5,0),
FIRST_NAME VARCHAR2(20),
LAST_NAME VARCHAR2(20),
MAJOR VARCHAR2(30),
CURRENT_CREDITS NUMBER(3,0),
PRIMARY KEY (ID));
[code]....
get the dynamic column values.
View 7 Replies
View Related
Nov 17, 2011
How do I add a column (Status) to a select query based on the data returned.
Select Col1, Col2
from
Table 1, Table 2, Table 3
Where
Table 1.Key1 = Table 1.Key1 and
Table 2.Key1 = Table 3.Key1 and
Table 1.Col1 in ('xyz','yty','ttr')
Output Expected:
Col1 Col2 Col3(Status)
xyx 1mst Sucess
yty Null No Data Found
ttr Null No Data Found
The Col1 value yty and ttr does not exist in the database
View 2 Replies
View Related
Nov 22, 2011
I am using Oracle 10g. I ran a procedure which is in dynamic sql. Once the procedure gets completed, it comes up with a warning message -
"Warning: unable to execute Dynamic SQL for adj_id: 02773"
Is there anyway to suppress the above message.
View 2 Replies
View Related
Aug 18, 2011
I have to create a WHERE clause like :
SELECT * FROM wc_claims WHERE part_nbr in l_part_nbr ;
I have three tables:
table A has - user_id, supplier
table B has - supplier, part_nbr
table C , wc_claims, has part_nbr and 78 other columns.
what i need to do is when user logs in with his user_id, he should see only that info from table C, corresponding to his supplier, and the part_nbr.
SELECT supplier from table_A WHERE user_id = 'abc' ;
supp_abc
SELECT distinct part_nbr from table_B WHERE supplier = 'supp_abc' ;
partA, partB, partC,........partZZ
SELECT * FROM wc_claims WHERE part_nbr in (partA, partB, partC,........partZZ );
I have created a function :
create or replace Function wcl_partnbr ( p_supp IN varchar2 )
RETURN CLOB
IS
[Code].....
so that I can use that in the WHERE clause, because one supplier can have thousands of parts...so it works fine, if there are 200 part numbers for one supplier, but above that.. it doesnt.
View 15 Replies
View Related
Jul 9, 2010
I having below table :
EXAM2@orcl> desc search_table;
Name Null? Type
----------------------------------------- -------- ----------------------------
ROL NOT NULL VARCHAR2(7)
CNM NOT NULL VARCHAR2(30)
FNM NOT NULL VARCHAR2(30)
MNM NOT NULL VARCHAR2(30)
DOB NOT NULL DATE
YEAR NOT NULL NUMBER(4)
EXAM NOT NULL VARCHAR2(1)
MAIN_SUPP NOT NULL VARCHAR2(1)
In a dotnet application user is going to input/select all/any of the above column in where clause.If user has given value for rol column then ref cursor should be :
select * from search_table where rol like <given value>
endif
and/or
If user has given value for cnm column then ref cursor should be :
select * from search_table where rol like <given value> and/or cnm like <given value>
endif
I mean whatever value is being given; it should be part of where clause.For it i am going to :
EXAM2@orcl> CREATE OR REPLACE PACKAGE rollsearch AS
2 TYPE t_cursor IS REF CURSOR;
3 Procedure rol_cursor(c_rol in varchar2,c_cnm in varchar2,c_fnm in varchar2,
4 c_mnm in varchar2,d_dob in date,n_year in number,c_exam in varchar2,c_main_supp in varchar2,
5 io_cursor IN OUT t_cursor);
6 END rollsearch;
7 /
EXAM2@orcl> CREATE OR REPLACE PACKAGE BODY rollsearch AS
2 Procedure rol_cursor(c_rol in varchar2,c_cnm in varchar2,c_fnm in varchar2,
3 c_mnm in varchar2,d_dob in date,n_year in number,c_exam in varchar2,c_main_supp in varchar2,
4 io_cursor IN OUT t_cursor)
5 IS
6 v_cursor t_cursor;
7 sql varchar2(1000);
8 BEGIN
9
What should i write further; so that i may get ref cursor as whereed clause for given value. So that i may populate my datagrid view for that web form.
View 14 Replies
View Related
Apr 26, 2010
I have a stored procedure that updates a series of columns (set at varchar(500) just to ensure there is ample space for whatever data is inserted into it) .Once it has updated though I've wanted to trim the column width down to the maximum size of the column value. I determine the max size of the column length and use that in a pl/sql command to ensure the width isn't smaller than the largest data entry.
When I try to do this I get the following message:
ORA-01441: cannot decrease column length because some value is too big
Now after hunting this down it seems as though you cannot decrease the size of a column once data has been inserted into it.
Any success in reducing the column width of a table that has data in it?
Why do I need to do this? I am exporting this table from Oracle into a propriety application and I am trying to reduce teh size of the export table by removing any unecessary space the unused spaces in the column. This will benefit the local app in addition to reducing the impact on the filesystem storage.
View 7 Replies
View Related
Jul 21, 2011
I am working on an application that requires very dynamic access to data. Users will build queries through the interface and the queries will be stored in VARCHAR fields for later use. The function that later uses the query has no way of knowing the field names or data types used in the selection query.
This isn't an issue in any program language that I have used before but in this case, we want to do this in a package within Oracle rather than an external application.
how to reference a field by its location or position in the query.
We need to get the list of fields so we know what each field is named and we need to be able to get at its value dynamically as well. If possible, checking the data type would be useful too but that is less important in this case.If we were doing this in say PHP, we could simply reference the query row and use a command like...
foreach($myrow as $field=>$value)
and this would walk through each field in the row giving us the field name and its value.We need to do this same type of thing in our package.
View 1 Replies
View Related
Jul 26, 2004
I have column names stored in a table(say t1).
Inside a trigger I have to dynamically get the : old. values for only these columns.
This I need because during update trigger on a table (say t2) I am supposed pickup the coumn names stored in t1 and get the : old values of only these columns to insert into a new table .
View 5 Replies
View Related
Apr 26, 2012
I need to store a date that will always be x years before the current date. Is doing something like
select sysdate -x from dual
Going to result in any weird issues down the road? Also, because I haven't explicitly specified the date, when queried, will the value always be sysdate - x (What I want to happen) as opposed to dateRowWasCreated - x?
View 1 Replies
View Related
Jun 21, 2012
I wrote a simple procedure to copy the create timestamp and create user name to update timestamp and update user name of the same record. (See code below)
This works fine for a hard-coded table and primary key column. However, I cannot figure out how to get this to work with dynamic sql.
All my other procs, which don't use SELECT UPDATE FOR work fine with dynamic sql.
Proc that works:
CODECREATE OR REPLACE PROCEDURE proc_set_upd_columns
IS
CURSOR c1 IS
SELECT *
FROM mytable
FOR UPDATE
ORDER BY mycolumn;
c1rec c1%ROWTYPE;
[code].........
Partial proc that does NOT work:
CODECREATE OR REPLACE PROCEDURE LDEVORE.proc_set_upd_columns (
p_input_table_name IN VARCHAR2,
p_pk_id_col_name IN VARCHAR2)
IS
v_qry_str VARCHAR2(1000);
v_cursor_str VARCHAR2(1000);
v_create_tmstmp TIMESTAMP;
v_create_user_name VARCHAR2(30);
[code].......
View 3 Replies
View Related
Jan 2, 2012
finding out which instance is the resource master of a object.Also select * from V$GCSPFMASTER_INFO
returns zero rows.
Does this mean dynamic remastering is disabled???if so which instance will own a object?
View 1 Replies
View Related
Jan 23, 2012
i have creatd view,in which i need to show the entry of year in column wise,though the data is in row /record wise.By iteration i can manipulate the year in decode function like " (DECODE(a.Year,(select distinct max(year)-1 from BI_BALANCE_SHEET), a.Balance))",but is there any way to chachge the alias name /column name,here is the query
select
SUM(DECODE(a.Year,(select distinct max(year)-1 from BI_BALANCE_SHEET), a.Balance)) as year2010,
SUM(DECODE(a.Year,(select distinct max(year)from BI_BALANCE_SHEET) , a.Balance))as Year2011
from DEMO a
View 4 Replies
View Related
Jul 12, 2013
I do not know the table name but have a query that for sure returns the table name and I want to select a column value from the table into my PLSQL variable.
Here is the code :
DECLARE
v_VerTabName VARCHAR2(30);
v_Minor NUMBER(2);
[Code]....
But when I compile this I get ORA-00936 : Missing expression at the EXECUTE IMMEDIATE line.
View 3 Replies
View Related
Jun 11, 2013
I would like to use dynamic sql for an select query with where clause and then use the dynamic sql in pl/sql stored procedure. how to create dynamic sql (select query) and how to use it in pl/sql stored procedure.
View 4 Replies
View Related
Aug 6, 2008
I am using Oracle Form 6i. I have created pdf file from oracle report. On view button, I have written:
host('C:Program FilesAdobeReader 8.0ReaderAcroRd32.exe C:dailypending.pdf');
I don't want to set this path on every machine. I want to set its dynamic path so that on which even I machine, I run the applicaiton, it will directly find AcroRd32.exe from any drive either C: or D: or anything else...
It might be Acrobat Reader 9.0 or 8.0 whatever version will be installed on client machine...I want to set path according to that..So that whatever version it would be, it doesnt affect the application..
View 4 Replies
View Related
Aug 28, 2007
I want to create dynamic Lov. How can I create it? For practice I create a LOV at design time
RECORD_GROUP_QUERY value:
SELECT * FROM
EMP.
THEN I write some code in WHEN-BUTTON-PRESSED Trigger to replace RECORD_GROUP_QUERY at run time. Code is:
........
v_rg_id:=CREATE_GROUP_FROM_QUERY('TEST','SELECT * FROM DEPT');
........
After this I found a error at run time which is FRM-41826: Cannot replace group; columns don't match LOV.
View 6 Replies
View Related
Jun 26, 2010
How to create dynamic views? I need literature on dynamic views.
View 5 Replies
View Related
Oct 15, 2013
I need to have columns dynamically defined in my SQL based on the column values in the table.
Selct emp_no,dept_no,grade from emp;
emp_no dept_no grade
----------------------------------
1 10 A
2 20 B
3 20 A
4 10 C
5 10 A
6 20 C
7 10 B
8 20 C
I need the output as
dept_no Count_A Count_B Count_C
---------------------------------------------
10 2 1 1
20 1 1 2
I can write hard coded sql to get this output but I need the count columns to be generated dynamically as there could be new entries in the grade column later. For example if there is a entry as D for the grade column my SQL should have a column count_D.
View 3 Replies
View Related
May 30, 2012
I have two string one is comma separated values as a column name and another string which is having the comma separated value corresponding to the column name.
Example:
string1:='col1,col2,col3'
string2:='1,aaple,'2-jul-75'
now i have to create and run a query which will be like that
select * from emp where col1=1 and col2='apple' and col3='2-jul-75'
View 6 Replies
View Related
Oct 16, 2012
I want to be able to generate unpivot for 1 row of data dynamically.what i am trying to do is based on this linkI just need to be able to pass the table name in format : SCHEMA_NAME.TABLE_NAME and the query should unpivot the data for 1 row. (Will always be 1 row, just need to transpose the column names and the values for 1 row of data)
I made the below query so far. But I am getting an error and can't figure out a way to fix it.pass any table name from your database in the define step
define TAB_NAME='SCOTT.EMPLOYEE'
WITH sel_col AS
(
SELECT DECODE (data_type,
[code]...
ERROR at line 33:
ORA-00904: : invalid identifier
Its the last line of the code. The same seems to work in the select part but not in the IN part.
P.S: I cannot do PL/SQL - as i simply dont have access.
View 9 Replies
View Related
Oct 19, 2011
I have a question regarding the optimal way to code a dynamic SELECT INTO statement. Below are the 2 posiibilities I know of:
1. Dynamically executing the SELECT statement and making use of the INTO clause of the EXECUTE IMMEDIATE
statement
CREATE OR REPLACE FUNCTION get_num_of_employees (p_loc VARCHAR2, p_job VARCHAR2)
RETURN NUMBER
IS
v_query_str VARCHAR2(1000);
[code]...
2. Encapsulating the SELECT INTO statement in a block and dynamically exectuting the block
CREATE OR REPLACE FUNCTION get_num_of_employees (p_loc VARCHAR2, p_job VARCHAR2)
RETURN NUMBER
IS
v_query_str VARCHAR2(1000);
[code]...
which way would be preferred? I know the second method uses a bind variable for the INTO clause, but does the first one also use bind varialbes (no semi-colon)? Any differences in terms of efficiency or speed?
View 4 Replies
View Related
May 18, 2010
converting Rows to Column for a specific group.
Following is the query
SELECT Lpad(papf.employee_number, 6, '0') "File#",
papf.full_name,
Decode(ppee.processing_type, 'R', Decode(ppee.element_name,
'Regular Wages USD', peev.screen_entry_value,
'Regular Salary USD', Round(peev.screen_entry_value / 26, 2),
0),
[Code]...
Which gives me out put as
Example 1
Employee Number Name Value Rate Type Type Assignment Id
-----------------------------------------------------------------
4 Employee 1 800 N 5 Yr Bonus 64
4 Employee 1 1063 N 6 Months Bouns 64
4 Employee 1 24.04 H Reg Hourly Sal 64
5 Employee 2 6923.08 S Reg Sal 65
6 Employee 3 5961.54 S Reg Sal 66
6 Employee 3 15000 N 6 Months Bouns 66
I want to convert above out to look like following
Emp Num Name Value Rate Type Type Val 1 Rate Type 1 Type 1 Value 2 Rate Type 2 Type 2 Assignt Id
-------------------------------------------------------------------------------------------------------------------
4 Employee 1 24.04 H Reg Hourly Sal 800 N 5 Yr Bon 1063 N 6 Mon Bon 64
5 Employee 2 6923.08 S Reg Sal 65
6 Employee 3 5961.54 S Reg Sal 15000 N 6 MontBon 66
Example of Query Output 2.
Employee Number Name Value Rate Type Type Assignment Id
--------------------------------------------------------------------------------
4 Employee 1 800 N 5 Yr Bonus 64
4 Employee 1 1063 N 6 Months Bouns 64
4 Employee 1 1345 N Patent Bonus 64
4 Employee 1 24.04 H Reg Hourly Sal 64
5 Employee 2 6923.08 S Reg Sal 65
6 Employee 3 5961.54 S Reg Sal 66
6 Employee 3 15000 N 6 Months Bouns 66
Desired Output from Above Query. As you can see column have increased as one more row for same employee has increased
ENu Nm Val RTy Ty Val1 RTy1 Ty1 Val2 RTy2 Ty2 Val3 RTy3 Ty3 AsgId
-------------------------------------------------------------------------------------------------------------------
4 E1 24.04 H Reg Hour Sal 1063 N 6 Mon Bns 1345 N Pat Bon 800 N 5YB 64
5 E2 6923.08 S Reg Sal 65
6 E3 5961.54 S Reg Sal 15000 N 6 Mos Bns 66
View 7 Replies
View Related
Nov 3, 2010
I have a Strange requirement from client data is loaded from excel to Oracle Table- TST_TBL (with Header in Excel)
CREATE TABLE TST_TBL
(
JOB_DETAIL_ID NUMBER,
SHEET_NAME VARCHAR2(100 BYTE),
COL1 VARCHAR2(400 BYTE),
COL2 VARCHAR2(400 BYTE),
COL3 VARCHAR2(400 BYTE),
COL4 VARCHAR2(400 BYTE),
[Code]...
After the Data is loaded, we see data look like the above.
(1) Always COL3 column name have data value as 'Gen1' which is the indication for us from where data starts. But Gen1, Gen2, Gen3 etc... is dynamic. ie. This month we get gen1 and gen2 columns followed by null value in a column. Next month we get gen1,2,3,4 followed by null column.
(2) Null Column indicate us that there is a break in the column.
(3) Then next we need to look for next group of data (Monthly) and then insert into the same table again with different sheet_name column.
(4) Next for Quater and then YTD. None of the column Values are fixed and its all dynamic.
If you load the below data, you will come to know what i am looking for. I tried using UNPIVOT. But couldnt able to achieve it. Is there an option to do it in sigle query? or Do I need to go for Stored Procedure?
Insert into TST_TBL
(JOB_DETAIL_ID, SHEET_NAME, COL1, COL2, COL3,
COL4)
Values
(100, 'Wire_1', 'Gen1',
'Gen2', 'Gen3', 'Gen4');
Insert into TST_TBL
[Code]....
View 1 Replies
View Related