SQL & PL/SQL :: Substitution Variable With And Without Value Assigned
Jun 14, 2011
I have a table emp with columns [id,name,job_id,dept_id]. now I make a simple select query.
select id,name,job_id,dept_id
from emp
where id = &a
and name = &b
and job_id =&c
and dept_id =&d;
now in this case it will ask the values for all the columns and will according print result.
Now my questions is what will happen if I just pass the value for only id and name not for other two...?
View 35 Replies
ADVERTISEMENT
Jul 20, 2011
Here is a simple sqlplus line command with & substitution run time variable.
set verify off;
SQL> SELECT * FROM emp where sal >&SAL;
Enter value for sal:
Now as you see, oracle asks to Enter Value for substitution variable in line just below the SQL>. I wonder if there is one or more line could be left there so to improve the readability. So it should look like:
set verify off;
SQL> SELECT * FROM emp where sal >&SAL;
Enter value for sal:
View 2 Replies
View Related
May 5, 2011
Below is the code, I am trying.
I have all the bind variables in "using_stmt" variable. How can i make this work. Currently I am getting error
ORA-01008: not all variables bound
--------------------------------------
DECLARE
SQL_STMT varchar2(200);
using_stmt varchar2(200);
dept_id number := 50;
dept_name varchar2(14) := 'PERSONNEL';
loc varchar2(13) := 'DALLAS';
rec_count number;
[code]......
View 13 Replies
View Related
Oct 3, 2012
Declare a variable called sal to store the salary of an employee. In the executable part of the program, do the following:
a.Store an employee name in a substitution variable.
b.Store his or her salary in a variable.
c.If the salary is less than 5,000, give the employee a 10% raise and display the message "<Employee Name> salary updated" in the window.
d.If the salary is more Last Name Message than or equal to 3,000, print the employee's salary in the format, "<Employee Name> earns ............. No raise is given."
So the result should ask for the last name
- Himuro and message should show [Himuro's salary updated]
- Greenberg [Greenberg earns 12000. No raise is given.]
- Patel [Patel's salary updated]
Here is my PL/SQL
set serveroutput on
DECLARE
v_emp_sal employees.salary%type;
v_emp_last_name employees.last_name%type;
BEGIN
v_emp_last_name :=initcap('&emplastname');
SELECT salary
INTO v_emp_sal
[code]......
question:
How can I get the apostrophe in the dbms_output.put_line. Attached is the create employees table code.
View 4 Replies
View Related
May 24, 2012
I want to insert the value with '&'. But this is treated as substitution variable by oracle.So how can it is possible to do like this
INSERT INTO DEPT (DEPTNO, LOC, DNAME)
VALUES (50, '&NEW YORK', 'SALES');
View 3 Replies
View Related
Nov 11, 2012
Just explaining what I am trying to achieve:
1) i have a hr.departments table that was loaded in hr schema on 1st oct 2012 with 4 columns(department_id, department_name, manager_id, location_id)
2) now I have a new schema by my name 'rahul' and I have loaded departments table but now an additional column has come into picture,ie created_date, this table got loaded on 1st-Nov-2012
3) Now going forward my columns could be dropped from the departments table (it can be a case), for example might be my departments table in my schema 'rahul' one day could comprise of only 3 columns(department_id,department_name,manager_id)
4) Now in the next step, I have managed to extract common column names(in a single line where columns are delimited using a comma) from both the tables(hr.departments and rahul.departments) which are (department_id, department_name, manager_id, location_id) using all_tab_cols table and I have written a function for it which i will be pasting below.
5) now going forward, using the above column names line with column names delimited using comma, I have used a ref cursor and assigned a query to it using the line of columns that I have extracted from the above point
6) Now I want to create a record variable which refers to my ref cursor, something like we do when we create a record variable by reffering to an explicit cursor defination that we give in the declaration block.
PS:
1) I have been out of touch with plsql for a long time so I have lost a lot of mmeory regarding plsql.
2) basically I need to compare data in hr.departments table with rahul.departments table for only columns that are common to both the tables, rest new or discarded columns information will go in one of the log tables that I have created(this is done already)
Code :
===================================================================================================
create or replace procedure p_compare_data(fp_old_table_name in varchar2, fp_new_table_name in varchar2)
is
[Code].....
View 5 Replies
View Related
Apr 5, 2011
I wish to replace the string "Benutzername&Kontakt" with nothing.
SELECT REPLACE (role_owner, 'Benutzername&Kontakt', '')
FROM JC_NAME_62
WHERE jc_name LIKE 'SAP_R4_BIN5\_%' ESCAPE ''
But my Toad prompts me always to fill in the variable. I don't wish to do that, I wish to escape the &
View 5 Replies
View Related
Sep 20, 2013
How Rowids are assigned to rows by Oracle?
Is it that Rowids are assigned in an incremental manner - as in the latest record would get Maximum Rowid.(Assuming that no record has ever been deleted from that table)
View 7 Replies
View Related
May 2, 2010
I read that few privilegs can not be granted to roles like 'UNLIMITED TABLESPACE ' and they need to granted to user directly.
1. Is there any reason behind that few privileges cant be granted to roles or is it just oracle design.
2. what kind of privileges cant be assigned to roles.
View 7 Replies
View Related
Jul 22, 2010
i have exp dump of size 1gb but when i tried to imp ,it showing error of space , it asking for space of 4gb. But i have 1gb on c: drive and 32gb on d: ,can i add datafile on d: locaion and what is max size i can assign to that datafile .
View 4 Replies
View Related
Oct 11, 2011
Is it possible to have $ substitutions in Select statements ?
For example
Select * from my_table where ID in ${ID_LIST} and DAY >= to_date(${SOME_DATE})
$ID_LIST = (100,200,300)
$SOME_DATE = 10-10-2011 12:12:00
For the ID_LIST is using Prepared statements with ?,?,? the way to go ? Or are there are any Define we can do in SQL plus for this substitions ?
View 2 Replies
View Related
May 17, 2010
HOW i can use the Substitution Variables in select statement in From phrase
we need execute select statement in different users in run time.
View 15 Replies
View Related
Jul 17, 2012
I have few questions regarding PL/SQL tables
1) If I don't specify the "INDEX BY" clause, it is indexed by PLS_INTEGER by default, right?
2) Consider this package specification
CREATE OR REPLACE PACKAGE Testxyz AS
TYPE tab_Numbers IS TABLE OF PLS_INTEGER;
PROCEDURE TestNumber(ptab_Numbers IN tab_Numbers := NULL);
END Testxyz;So I created a table (I hope it is defaultly indexed by pls_integer data type) and I am passing it as a parameter to a procedure. Because I want this parameter to be optional I am assigning null into it.
Now I change the definition of the table to:
CREATE OR REPLACE PACKAGE Testxyz AS
TYPE tab_Numbers IS TABLE OF PLS_INTEGER INDEX BY PLS_INTEGER;
PROCEDURE TestNumber(ptab_Numbers IN tab_Numbers := NULL);
[code]....
3) Because I need this parameter to be optional, I use the first declaration:
CREATE OR REPLACE PACKAGE Testxyz AS
TYPE tab_Numbers IS TABLE OF PLS_INTEGER;
PROCEDURE TestNumber(ptab_Numbers IN tab_Numbers := NULL);
END Testxyz;
Now I create an anonymous block and want to assign something into the table
DECLARE
vtab_Numbers TESTXYZ.tab_Numbers;
BEGIN
vtab_Numbers(1) := 5;
END;
/When trying to run this, I got:
06531. 00000 - "Reference to uninitialized collection"
Is it possible to have input parameter of PL/SQL table type and have defaultly null assigned to it?
View 5 Replies
View Related
Feb 22, 2010
How I go about writing a query that doesn't see the '&' symbol as a substitution character. The problem I have is:
select replace
( fnd_profile.value( 'XXBPO_URL')
, '&DOCID'
, ai_dfv.bpo__document_link
) document_link
from ap_invoices_all ai
, ap_invoices_all_dfv ai_dfv
where 1=1
-- where clause
The problem above is that instead of replacing the characters &DOCID with the required value, it is prompting for input.
View 4 Replies
View Related
Sep 6, 2013
I am using Release 11.2.0.3.0 - 64bit Production version of oracle. Now we are having 3-tier architecture, (firewal/web/app/DB).Now i saw , some of the 'sql' queries, running till ~10hrs in my database and those are part of application(module JDBC THIN CLIENT). After had a talk java guys, they ask to kill the sessions specific to those queries. They are part of search TO, in which user put some large values for the date range and went to other TAB, but these queries gets running infinitely in the database, and user is not interested in the result set.
So how to avoid these things, as because in past, our database has suffered resource contention leading to application slowness. So i was planing to set different timeouts using 'database resource consumer group' for online user request and batch request depending on the app server(that is by machine names) request.
So i have done below set up in my local to test one scenario, in which i will try give a database call from difference machine, and it should get timeout after the specified duration. But its not working , as expected. The calls from the specified machine are not getting assigned to the created 'Consumer group'.
Begin
-- create the pending area
dbms_resource_manager.create_pending_area();
END;
/
BEGIN
-- Create the consumer group
[code]....
After this when i am verifying calls from machine, 'LR9XY7T8' they are belongs to the consumer group 'OTHER_GROUPS' and sql query not getting timed out within 60 seconds as mentioned.
View 9 Replies
View Related
Jul 4, 2012
I have created a list with name Test_List and 5 values in it.
I want to pass the values dynamically when i select the list values (any of the 5 values).
I tried:
For each list setting(List Details --> Static list entries --> Target) i have set the
Request as ?Test_List=#Test_List#
Note: Here Test_List is my list name.
Also i have tried
Request as ?Test_List=&Test_List.
But nothing seems to be working...
View 8 Replies
View Related
Apr 14, 2009
I have following tables:
EMPLOYEE (E-Number, Name, Department, age)
ASSIGNMENT (E-Number, P-Number )
PROJECT( P-Number, Project, Manager)
Create a view to show employee names, age and total number of projects they are assigned to
View 2 Replies
View Related
Jun 27, 2012
I was wondering if there is a substitution string ( or something else) that could be used to 'return' the name of a Form item that has cursor focus?
View 3 Replies
View Related
Oct 18, 2013
i have user with the name 'Rob' and this user has been assigned a role 'MY_SRC_ROLE' . I developed a table under rob schema and granted access to this table via role GRANT DELETE, INSERT, SELECT, UPDATE ON rob.emp TO MY_ SRC_ ROLE; I have 100 more users & they have been granted this role 'MY_SRC_ROLE'. These 100 users can now access emp table via Role 'MY_SRC_ROLE' without any issues. Now i took a datapump export & performed datapump import on target server which is also HP Unix with 11.20.3 .
On target server i have user 'JACK' and a role called 'MY_WORK_ROLE'. 5000 users have been granted 'MY_ WORK_ ROLE' on this server. I have used remap tablespace clause & remap schema clause in datapump import script. Once i performed an import , due to schema remap , i can see JACK now owns table 'emp', however grants are still not there, I tried searching on Google & oracle documentation, if somehow we can remap ROLE GRANTS also while doing datapump imp, but i couldn't find supporting syntax. can i assume datapump import is not capable to handle this particular scenario ? I was able to do it by manipulating sqlfile and replacing role name in that but i am looking for a sol. within datapump itself. how can grants assigned to ROLE 'X' be transferred to 'Role Y' via datapump import.
View 2 Replies
View Related
Jun 12, 2012
How do I set variables at the top of my code? I want to set the date as the variable.
Select * from employees where employee_dt > '2011-01-01'
View 1 Replies
View Related
Apr 24, 2013
it is possible to undeclared a variable if so how dont worry am with you to solve any problem lets we can do it
View 1 Replies
View Related
Jul 21, 2010
I have written an explicit cursor (procedure given below) and the issue I have is, when the cursor runs the sql statement
(CURSOR csr_address is
SELECT rtrn_id,
entp_abn,prog_program_cd,
sched_nbr,schd_version_yr,
litm_line_item_nbr, revise_val_text
FROM RETURN_LINE_ITEMS
WHERE sched_nbr = '000'
AND prog_program_cd = '01' AND litm_line_item_nbr in ('016','023')
AND rtrn_id = v1_rtrn_id;)
against a particular return id, it fetches 2 rows; one for line item 016 and the other one for line item 023 where in the litm_line_item_nbr for 016 is 016 and for litm_line_item_nbr for 023 is 023. Once that's done, (I have used a For loop cursor), it loops through as follows:
FOR country_rec in csr_address LOOP
v_line_item_16 := country_rec.litm_line_item_nbr;
if v_line_item_16 = '016' then
v_line_item_16 :='016'
end if;
[code]....
View 8 Replies
View Related
Jan 12, 2012
I have the below cursor 1 which is working already.For my requirement i want to use bind variable like second cursor.But its telling Bind Variable "p_col_list" is NOT DECLARED.
How to use bind variable Here.
Cursor1:
DECLARE
emp_cv sys_refcursor;
iid NUMBER := 1;
i_sql varchar2(100);
p_col_list varchar2(2000) := 'aaa,bbb,ccc,ddd';
BEGIN
i_sql := 'select '''||REPLACE(p_col_list, ',', ''',''')||''' from dual '||CHR(10) ;
dbms_output.put_line(i_sql);
OPEN emp_cv FOR i_sql ;
END;
Cursor2:
DECLARE
emp_cv sys_refcursor;
iid NUMBER := 1;
i_sql varchar2(100);
p_col_list varchar2(2000) := 'aaa,bbb,ccc,ddd';
BEGIN
i_sql := 'select '''||REPLACE(:p_col_list, ',', ''',''')||''' from dual '||CHR(10) ;
dbms_output.put_line(i_sql);
OPEN emp_cv FOR i_sql using p_col_list;
END;
View 2 Replies
View Related
Oct 31, 2013
I have some XML being returned from a web service, and it returns almost 900 variables. Whilst I am familiar with how to return these in a single row, do I can return a row for each variable? My DBA is very uncomfortable with creating a table with almost 900 columns, for obvious reasons. However, we already have plenty of tables with tens of millions of rows, so he's fine with that. I'll try and expand on the requirement. Below is some XML from the data returned to us:
<APPLICANT app_no="1">
<APPLSUMMARY>
<MAIN W="ZZ" X="{ND}"/>
<COUNTS Z="3" AB="0" BB="3" CB="0" DB="3" EB="3" FB="3" GB="0"/>
</APPLSUMMARY>
</APPLICANT>
I would like to be able to return a new row for each variable, For example:
VARIABLE | VALUE
----------------
W | ZZ
X | {ND}
Z | 3
And so on.
View 2 Replies
View Related
Mar 2, 2012
I have plsql table as out parameter in one function.From another function i called that function ,its executing perfectly but while returning to called place its saying a character to numeric conversion error.I checked all the l
Note: i can not able post all that functions here.
View 12 Replies
View Related
Jun 14, 2011
Can I assign the outcome of a select query to a defined variable
like
var=select emp id from emp where empname='ddf'
View 5 Replies
View Related
May 12, 2012
create view sample as
var varchar(100);
var:= select * from employee;
execute immediate var;
can we create like this ... my requirement is like this...
View 6 Replies
View Related
May 8, 2013
Is there a way to have a variable in the FROM clause or another way to have the table name as a variable? I'm trying to not repeat the same query three times with only the table name being different.
---the tables
create table org_a (emp_id number(5) not null, name varchar2(20));
create table org_b (emp_id number(5) not null, name varchar2(20));
create table org_c (emp_id number(5) not null, name varchar2(20));
---the records
INSERT ALL
INTO org_a (emp_id, name) VALUES (00001, 'MISTER WHITE')
INTO org_a (emp_id, name) VALUES (00002, 'MISTER ORANGE')
INTO org_b (emp_id, name) VALUES (00003, 'MISTER PINK')
INTO org_b (emp_id, name) VALUES (00004, 'MISTER BROWN')
INTO org_c (emp_id, name) VALUES (00005, 'MISTER BLUE')
INTO org_c (emp_id, name) VALUES (00006, 'MISTER BLOND')
SELECT * FROM dual;
---verify inserts
SELECT * FROM org_a
UNION ALL
SELECT * FROM org_b
UNION ALL
SELECT * FROM org_c;
---i want the table name to be dependent on a variable. eventually,
---i intend to link v_org to a form with radio buttons (values: 1, 2, 3)
---to keep this simple, i'll just assign 1 to v_org
DECLARE
v_org number(1) := 1;
v_table varchar2(5);
BEGIN
v_table :=
CASE v_org WHEN 1 THEN 'org_a'
WHEN 2 THEN 'org_b'
WHEN 3 THEN 'org_c'
END;
SELECT * FROM v_table;
END;
--this is what i receive
SQL> /
SELECT * FROM v_table;
*
ERROR at line 10:
ORA-06550: line 10, column 17:
PL/SQL: ORA-00942: table or view does not exist
ORA-06550: line 10, column 3:
PL/SQL: SQL Statement ignored
View 22 Replies
View Related
Jan 21, 2011
I HAVE DECLARED A VARIABLE
VAR1 VARCHAR2(20000);
BUT STILL WHEN I ASSIGN SOME STRINGS TO THAT VARIABLE I GET "VALUE TOO LARGE" MESSAGE. WHAT SHOULD I DO?
View 2 Replies
View Related
Mar 27, 2013
reading the value from csv file and store into a variable and then use that variable in select statement in
filter. I have tried the following ways but it is now working.
File content is
first, second, third, forth
Y, N, 001|002, abc
N, Y, 003|004|005|006, xyz
n, Y, 007|008|009, mno
[code].....
View 8 Replies
View Related