using variable in the select statement (php)
I have trouble using a variable in a select statement.The following query to manually (using a static date) works very well:
$query_Recordset1 = "SELECT * from academyClasses WHERE the classDate > ' 2006-06-01' ';"
However, if I use the following:
$dateVar = date('Y-m-d');
@mysql_select_db ($database_mw, $mw);
$query_Recordset1 = "SELECT * from academyClasses WHERE the classDate > $dateVar";
All records are returned, which means that the $dateVar variable is not recognized. I compared the values of $dateVar <? PHP echo $datetime;? > against the real value of my date field <? PHP echo $row_Recordset1 ["classDate"];? > in my results to the table and it seems that the values are indeed accurate regarding a date 2006-06-04 for example.
My date field 'classDate' is of type 'date' in the mysql database. I use Dreamweaver MX 2004 with Mac OSX 10.3.9.
I'm sure it's just a syntax problem, at least, I hope it is.
Any help is greatly appreciated.
It worked:
$query_Recordset1 = "SELECT * from academyClasses WHERE the classDate > = CURRENT_DATE;
Thank you
MW
Tags: Dreamweaver
Similar Questions
-
Set the Variable in the select statement
Hello
Can we define a variable in the select statement.
Example:
Select firstname, lastname
employees;
in this simple select statement we can define x as number?select fname,lname from employees where rownum <= 30;
-
using substr in the select statement
Hi all
I'll have a column as below from a table values.
"404-297-9559 UNLISTED."
"123 211 2345 KGTFE".
"123 293 2789 GFT.
OUTPUT should be like below... is it possible in sql oracle and my client uses the 8i version.
404-297-9559
123-211-2345
123-293-2789
Thank you
KBS
2804972 wrote:
I gave only for three values of the column as an example, there are millions of records... hard coding is not possible. Please suggest me other
Thank you
KBS
Where does show that you need to hard no matter what code?
The comment in the code indicates that the WITH clause is just used to provide sample data to the query (so I can't create a table in my database). What keeps you using the same query against your own data table? Do you really understand the basic concept of a SQL selection in a table? Did you even try and understand the code?
Is it really that hard for you to have tried to do:
Select substr (yourcolumname, 1, instr (yourcolumnname,' ', 1)-1) as txt
of yourtablename
-
How to use the variable instead of the table name in the select statement of procedure
I have a procedure with a select statement with dynamic from clause. How can I use instead of the name of the table variable.
create or replace procedure scc_chemical_analysis
is
v_table_name varchar2 (100);
Start
declare
cursor c1 is select * from v_table_name; -This is the variable name. How can I use it in the select statement.
.
.
.
.
end;Hello
something like that.
1 declare 2 vSQLString VARCHAR2(32000); 3 pTableName varchar2(1000):='EMP'; 4 BEGIN 5 vSQLSTRING := 6 'SELECT ''x'' FROM ' || DBMS_ASSERT.sql_object_name(pTableName) || ' WHERE rownum<=1 '; 7 EXECUTE IMMEDIATE vSQLSTRING; 8* END; SQL> / PL/SQL procedure successfully completed.
-
Assign the values of the two variables in a select statement
I'm trying to set two variables in a select statement in my definition of the procedure. I get the error identifier not valid "ATTRIBUTE" running the following code.
Can I not connect two different values to two different variables in the same select?create or replace procedure tbl_auth ( Email in varchar2, UserLevel out number) as v_Email varchar2(100) := lower(Email); v_login_chk number := 0; begin select UserLevel into p_UserLevel, v_login_chk into v_login_chk from tbl_User where eMail=v_Email exception when no_data_found then UserLevel := 0; end tbl_auth;
Thank you
Published by: jerry8989 on August 22, 2011 07:06
Published by: jerry8989 on August 22, 2011 07:06change as follows:
select UserLevel, v_login_chk into p_UserLevel, v_login_chk
IN ONE ALONE is enough.
BTW, don't you have "login Check" column in the "tbl_user"? If you do, your selection should be like this:
... select UserLevel, loginChk into /* check the column name in your table */ p_UserLevel, v_login_chk from tbl_User ...
-
How to pass parameter in the function using the select statement?
Hello
I had a problem. I can't pass as parameter to the function by using the select statement. But it can pass as a parameter using the "code". How can I solve this problem?
For example,.
Select * from table (SplitFunction ('HS750020, HS750021')) < < < this work.
but
Select * from table (SplitFunction (select LOT_NO in the TRACER_SEARCH_SCHEDULE where JOB_ID = '36')) < < < do not work.
Thank you for trying to help him. Thank you.Select * from table (SplitFunction (select LOT_NO in the TRACER_SEARCH_SCHEDULE where JOB_ID = '36'))< do="" not="">
Try like this
select * from table(select splitfunction(lot_no) from tracer_search_schedule where job_id='36')
Just make sure that your subquery returns only 1 row.
-
How to use the Type of Oracle Table values in the Select statement.
Hello
I get the initial set of values in the Table of Type Records of the Oracle and want to use the list of values in the Select statement.
For example, try something like the following:
TYPE t_record () IS RENDERING
ID TABLEA.ID%type,
NO TABLEA.NO%type
);
v_record t_record;
T_table TYPE IS the v_record TABLE % TYPE;
v_table t_table;
-Code to fill the values of v_table here.
SELECT ID, NO, COLLECT in BULK IN < some other table variabes here > FROM TABLEA
WHERE ID IN (i) v_table USER.USER;
I want to know how to use the Type of Oracle Table values in the Select statement.Something like this:
create or replace type t_record as object ( id number, no number ) / CREATE or replace type t_table AS TABLE OF t_record; / set serveroutput on declare v_table t_table := t_table(); v_t1 t_table := t_table(); begin v_table.extend(1); v_table(1).ID := 1; v_table(1).No := 10; v_table.extend(1); v_table(2).ID := 2; v_table(2).ID := 20; SELEC t_record (ID,NO) BULK COLLECT INTO v_t1 from TableA FROM TABLEA WHERE ID IN (select t.ID from table(v_Table) t); for i in 1..v_t1.count loop dbms_output.put_line(v_t1(i).ID); dbms_output.put_line(v_t1(i).No); end loop; end; /
No test!
P;
Published by: bluefrog on March 5, 2010 17:08
-
Why I can't use the procedure in the select statement
Why I can't use the procedure in the select statementAnd you may not usa a SQL function if it has out parameters
SQL> create function myfun(p1 in out number) return number is 2 begin 3 p1:=1; 4 return 2; 5 end; 6 / SQL> select myfun(5) from dual; select myfun(5) from dual * ERRORE alla riga 1: ORA-06572: Function MYFUN has out arguments
In fact, the problem is that an output parameter is passed 'ref' and not 'val '...
Max
-
Update using a function in the select statement
Hello
Is it possible to do the follwing.
I tabele and a custom function, the custome service will update the column (amount) of the table based on the value of going through the function of the select statement.
SELECT id, stock, where an id = get_update (id);
Now
Get_update function will return the same id I'm passing and update the column amount to a value in the
table a.
When I run the satament selection I have the updated data in the column amount in my first executtion, but if execute the same statement, again, I see the changes reflected. is it possible to get data updates to the first performance himself.
the function is of type PRAGMA AUTONOMOUS_TRANSACTION
ConcerningIndeed a strange requirement and probably not the way to go in a production environment. But anyway is a way to achieve your goal
SQL> create table a as select 12 id, 500 amount from dual union all select 13 id, 600 amount from dual / Table created. SQL> create or replace type a_typ as object (id number, amount number) / Type created. SQL> create or replace function get_id (pid number) return a_typ is pragma autonomous_transaction; l_a_typ a_typ := a_typ (null, null); begin update a set amount = 800 where id = pid returning id, amount into l_a_typ.id, l_a_typ.amount; commit; return l_a_typ; end get_id; / Function created. SQL> select id, d.a_typ.amount amount from a, (select get_id (13) a_typ from dual) d where id = d.a_typ.id / ID AMOUNT ---------- ---------- 13 800 1 row selected.
-
How to ask the user to type in the select statement
Hello
Can anyone tell me the syntax of the select statement where I can ask the user to enter the value.
for example, I try to use belowthing, but it displays error
Select * from emp where empname =: empname
SP2-0552: Bind "empname' undeclared variable.
2. is there a dictionary of data table to see all pl/sql procedures and corresponding code?
Thank you
SriTry:
select * from emp where empname='&empname';
L.
-
uniol all in the select statement
Hi I have a situation where I have to return the value based on the if statement, is it possible to put union all in the select statement
My use case is
IN the column State
If column01 > 0 to condtion 't'
IF column02 > 0 that the condition of 'Y '.
Condition IF COLUMN03 > 0 THAN 'w '.
If COLUMN04 > 0 that the condition of "Z".
Select 't'
TableName
where column01 > 0
Union of all the
Select "y".
TableName
where column02 > 0
Union of all the
Select 'W '.
TABLENAME
WHERE COLUMN03 > 0
I have what it takes to show value as it
EmpName, condition, empno
Jerry, T, 0158754585
TOM, Y, 0054789568
Am in oracle database 11 g 2
Yes you can put all THE UNION here
Select empname, 't' State, empno from tablename where column01 > 0
Union of all the
Select empname, 't' State, empno from tablename where column02 > 0
Union of all the
Select empname, condition of "W", empno FROM tablename WHERE COLUMN03 > 0
Union of all the
Select empname, condition of "Z", empno FROM tablename WHERE COLUMN04 > 0
and if you are looking for how to remove duplicates because your line might have satisfied all the conditions and my happen 4 times in your result set, you just need to give them an order and filter it.
For example, you want this
If column01 > 0 to condtion 't'
ELSE IF column02 > 0 that the condition of 'Y '.
Another condition of THAN > 0 IF COLUMN03 'w '.
otherwise if COLUMN04 > 0 that the condition of "Z".
Select empname, condition, empno, in
(
Select a.*, row_number() over (partition by empno arrested by myorder) rn
Of
(
Select empname, 't' State, empno, 1 myorder tablename where column01 > 0
Union of all the
Select empname, 't' State, empno, 2 myorder tablename where column02 > 0
Union of all the
Select empname, condition of "W", empno 3 myorder FROM tablename WHERE COLUMN03 > 0
Union of all the
Select empname, empno, condition of 'Z', 4 myorder FROM tablename WHERE COLUMN04 > 0
) a
) where rn = 1
-
mixture of column type in the select statement
Oracle 11g r2.
tab_test (name varchar2, blob... photo)
(1) select general use *.
Stored procedure: open ref_cursor to some * of table_test...
Coast of java: call.registerOutParameter (1, OracleTypes.CURSOR); Call.Execute ();
It works very well.
(2) enter the name of the column in the select such as
Stored procedure: open ref_cursor to select name, photo table_test...
Coast of java: call.registerOutParameter (1, OracleTypes.CURSOR); Call.Execute ();
ERROR: java.sql.SQLSyntaxErrorException: ORA-00932: inconsistent data types: expected - got BLOB
My question, if I specify the column names in the select statement, including the varchar2 and blob, how can I registerOutParameter (1, OracleTypes.CURSOR);?
Thank you
Scott
PS The number of returned columns, in real case schenario, is a little, so I prefer to specify column names.
Wrong forum. This forum is for questions of sql and pl/sql.
Enter the question ANSWER and the repost in the JDBC forum
When repost you provide the necessary information to help you:
1. information on the full version for Oracle DB
2 version of the JDK
3. the name and version of the JDBC jar file
4. real code that demonstrates the problem
You should also review the info re REF CURSOR in the JDBC Developer's Guide
http://docs.Oracle.com/CD/E16655_01/Java.121/e17657/oraint.htm#i1058743
-
function() nested in the select statement
Oracle 11g. Try to nest a function within the select statement. Goal: get the average customer rating for each of the qualified user.
Select user_name, f_get_avg_cust_rating() "Notation.
of u, OTHER_TABLES o TAB_USER
where u.id = o.id and another condition matched;
How Oracle would deal with the sql. Is it
(1) first of all display records based on the where clause, then call the f_get_avg_cust_rating() for each of the selected records OR
(2) for the analysis in tables, the f_get_avg_cust_rating() will be called for each record met?
Thank you
Scott
Words of Frank, I created two functions with dbms_output and used a function in where clause in select another function. See the bottom of the unit tests. Everyone says, where first clause then select...
-Where function clause
SQL > CREATE or REPLACE FUNCTION ret_empno
2 RETURN NUMBER
3 AS
4 BEGIN
5 DBMS_OUTPUT. Put_line (' where Clause Function');
6 RETURN 7839;
7 END;
8.
The function is created.
-Select the function
SQL > CREATE or REPLACE FUNCTION ret_1
2 RETURN NUMBER
3 AS
4 BEGIN
5 DBMS_OUTPUT. Put_line ('Select function');
6 RETURN 1;
7 END;
8.
The function is created.
SQL > SELECT empno, ename,ret_1
2 FROM emp
3. WHERE empno = ret_empno;
EMPNO, ENAME RET_1
---------- ---------- ----------
7839 KING 1
Where the function Clause
Select the function
-
EXTRACT function can be used directly in the CASE statement WHEN
I wrote the following SELECT statement. The function 'calc_time_diff' is a stored function that subtracts two timestamps and returns the result to the total number of seconds. My DBA does not 'calc_time_diff' as a stored function, then, I replaced the third line (in bold) in the SELECT statement with this:
COUNTY ( BOX WHEN (extract (DAY OF v_end_ts-v_st_ts) * 24 * 60 * 60) +)
(extract (HOUR FROM v_end_ts-v_st_ts) * 60 * 60) +.
(excerpt (v_end_ts-v_st_ts MINUTE) * 60) +.
extract ((DEUXIÈME à PARTIR de v_end_ts-v_st_ts) < 3600 THEN 1 END) less_than_1_hrs_count
But the CASE above does not work. It returns the same value as COUNT (*). If the total number of tickets is 32 output will be
total_tickets less_than_1_hrs_count
32 32
If I call the "calc_time_diff" then I get the correct result. What I'm doing wrong here?
**********************************************************************************************************************************************************************
SELECT
Count (*) total_tickets,
COUNTY ( CASE WHEN END of calc_time_diff (t.created_date, h.closed_date) < 3600 THEN 1) less_than_1_hrs_count
OF n01.cc_ticket_info t
JOIN IN-HOUSE
(SELECT ticket_id, MAX (created_date) closed_date
OF n01.cc_ticket_status_history
WHERE ticket_status = 'CLOSED' AND created_date > = 18 August 2013 ' AND created_date < (to_date('08/24/2013','MM/DD/YYYY') + interval '1' DAY)
GROUP BY ticket_id
) h
WE (t.ticket_id = h.ticket_id)
INNER JOIN n01.cc_ticket_notes n
WE (n.created_date = h.closed_date)
WHERE (t. ticket_status = 'NOTIFICATION' t.ticket_status 'CLOSED' = GOLD) AND t.created_date > = 18 August 2013 ' AND t.last_changed < to_date('08/24/2013','MM/DD/YYYY') + interval '1' DAY);
***********************************************************************************************************************************************************
create or replace
FUNCTION calc_time_diff)
p_st_ts N01.cc_ticket_info. Type of LAST_CHANGED %,
p_end_ts N01.cc_ticket_info. Type of LAST_CHANGED %)
RETURN NUMBER
AS
v_no_sec NUMBER;
v_st_ts N01.cc_ticket_info. Type of LAST_CHANGED %;
v_end_ts N01.cc_ticket_info. Type of LAST_CHANGED %;
BEGIN
v_st_ts: = p_st_ts;
v_end_ts: = p_end_ts;
SELECT (extract (DAY OF v_end_ts-v_st_ts) * 24 * 60 * 60) +.
(extract (HOUR FROM v_end_ts-v_st_ts) * 60 * 60) +.
(excerpt (v_end_ts-v_st_ts MINUTE) * 60) +.
excerpt ((SECOND from v_end_ts-v_st_ts)
IN v_no_sec
DOUBLE;
Return v_no_sec;
END calc_time_diff;
Hello
You don't need a function defined by the user or the EXTRACT to find the difference between two timestamps.
SELECT COUNT (*) AS total_tickets
, COUNTY ( BOX WHEN h.closed_date < t.created_date="" +="" interval="" '1'=""> )
THEN 1
END
) AS less_than_1_hrs_count
...
I hope that answers your question.
If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results desired from these data.
Point where the above query is to produce erroneous results, and explain, using specific examples, how you get the right results from data provided in these places.
If you change the query at all, post your modified version.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).See the FAQ forum: https://forums.oracle.com/message/9362002
-
Pivot will not get result in the select statement
This is the version of oracle 11g R2 on windows details 7 OS
CREATE TABLE OTBOOKINGDETAILS
(EMPNO VARCHAR2 (10 BYTE),
DATE OF OTBOOKEDDATE,
NUMBER (5.0) DAY OF THE WEEK.
DAYCEILINGHRS VARCHAR2 (10 BYTE));
Here is the data
INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 MARCH 2013', 1,' 09:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 APRIL 2013', 2' 01:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 MAY 2013', 3,' 01:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 JUNE 2013', 4' 01:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 JULY 2013', 5,' 01:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 AUGUST 2013', 6,' 01:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 SEPTEMBER 2013', 7,' 00:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (102 ', 3 MARCH 2013', 1,' 09:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (102 ', 3 APRIL 2013', 2' 01:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (102 ', 3 MAY 2013', 3,' 01:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (102 ', 3 JUNE 2013', 4,' 02:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (102 ', 3 JULY 2013', 5,' 01:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (102 ', 3 AUGUST 2013', 6,' 04:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (102 ', 3 SEPTEMBER 2013', 7' 01:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 OCTOBER 2013', 1,' 00:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 NOVEMBER 2013', 2' 01:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 DECEMBER 2013', 3,' 01:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 13 MARCH 2013', 4,' 04:45 ');
INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 14 MARCH 2013', 5,' 01:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 15 MARCH 2013', 6,' 01:00 ');
INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 16 MARCH 2013', 7' 01:00 ');
Here, I want to Dayceiling hours below the output using pivot
EMPNO OTBOOKEDDATE DAY1_HRS DAY2_HRS DAY3_HRS DAY4_HRS DAY5_HRS DAY6_HRS DAY7_HRS
101 03/03/2013 09:00 01:00 01:00 01:00 01:00 01:00 00:00
102 03/03/2013 09:00 01:00 01:00 02:00 01:00 04:00 01:00
101 03/10/2013 00:00 01:00 01:00 04:45 01:00 01:00 01:00ChakravarthyDBA wrote:
I need to include the pivot query in the select statementCan' are you use PIVOT here since you do not know from the start what values OTBOOKEDDATE. So use:
select empno, otbookeddate - weekday + 1 otbookeddate, max( case weekday when 1 then dayceilinghrs end ) day1_hrs, max( case weekday when 2 then dayceilinghrs end ) day2_hrs, max( case weekday when 3 then dayceilinghrs end ) day3_hrs, max( case weekday when 4 then dayceilinghrs end ) day4_hrs, max( case weekday when 5 then dayceilinghrs end ) day5_hrs, max( case weekday when 6 then dayceilinghrs end ) day6_hrs, max( case weekday when 7 then dayceilinghrs end ) day7_hrs from otbookingdetails group by empno, otbookeddate - weekday + 1 order by otbookeddate, empno / EMPNO OTBOOKEDDA DAY1_HRS DAY2_HRS DAY3_HRS DAY4_HRS DAY5_HRS DAY6_HRS DAY7_HRS ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 101 03-03-2013 09:00 01:00 01:00 01:00 01:00 01:00 00:00 102 03-03-2013 09:00 01:00 01:00 02:00 01:00 04:00 01:00 101 10-03-2013 00:00 01:00 01:00 04:45 01:00 01:00 01:00 SQL>
SY.
Maybe you are looking for
-
Thunderbird 31 crushing when sending e-mail - in igd10umd32.dll driver Intel graphics
I use Thunderbird version 31.7.0 and it keeps randomly crashing when usually when I try to send an e-mail. The email seems to turn off, but it is not copied in my sent folder. I can keep it is to work, I use safe mode. My Crash links are: https://cra
-
On my 2nd generation Apple TV while watching a game on MLB. TV, I can press the key downwards and scroll through the sleeves, the events of the game and the series scored. How can I do that with the 4th generation Apple TV?
-
M30X in Germany/Austria-question on the language of the OS and keyboard
Hello!I buy Toshiba M30 X (probably-124) in Germany or Austria and I have 2 question: -on Windows XP language version - there will be German? English? Is it possible to get the English version? (or maybe I can choose it at the first start of the lapt
-
Yosemite running. I want Mac Mail to issue a dump when I send a message. How?
El Capitan running... I want to Mail to a discharge sound when I send a message. How?
-
Gigaseconds [Gs] vs Gauss [Gs]
Hello world. A funny question. The unit using "convert" I try to convert a time string with the units (i.e. 1 ' g') into a double number of function represented in the corresponding basic unit. For example: Chain: 10 "ms." A simple code separates the