SQL & PL/SQL :: Chinese Zodiac Associated With Birth Years
Aug 8, 2010
I have a question to write a pl/sql for Chinese zodiac but i cant do it, even i Google it i cant find any solution..the question is as below:
The Chinese zodiac associates birth years with the following; animals:
Birth Year Animal
1924,1936.1948,1960,1972,1984,1996 Rat
1925,1937,1949,1961,1973,1985,1997 Cow
1926,1938,1950,1962,1974,1986,1998 Tiger
1927,1939,1951,1963,1975,1987,1999 Rabbit
1928,1940,1952.1964,1976,1988,2000 Dragon
1929,1941,1953,1965,1977,1989,2001 Snake
1930,1942,1954,1966.1978,1990,2002 Horse
1931,1943,1955.1967,1979,1991,2003 Sheep
1932,1944,1956,1968,1980,1992,2004 Monkey
1933,1945,1957,1969,1981,1993,2005 Chicken
1934.1946,1958,1970,1982,1994,2006 Dog
1935,1947,1959,1971,1983,1995,2007 Pig
Write a command to declare a date variable named birth_date, and assign to it your birth date. Use an IF/ELS1F structure to test every year and determine the animal associated with your birth year. Then display your birth year and the associated animal name. For example, the program would display the following output for someone born in 1984:
I was born in 1984, which is the year of the Rat. Declare and use additional variables as needed.
Im supposed to fetch first names, last names and age of some people based on their birthdate. In my code so far i manage to get the names and the birthdates but what i actually need is a name and lastname and age for example 65 years.
here is the code :
SET SERVEROUTPUT ON DECLARE CURSOR C_kundålder IS SELECT FNAMN,ENAMN,PNR FROM BILÄGARE; v_fnamn bilägare.fnamn%TYPE;
I have around 1 million users in my table. I currently have their birth date in the table and for reporting purposes i want to put them into three different columns.
For example, For User A, DOB is 01/01/2005, User B, DOB is 01/01/2002, user C,DOB is 01/01/1998. user D, DOB is 01/01/1990 I want a view like below.
Cat1. Cat2. Cat3. User "0-10" '0-5' '0-2' 'USER A' "0-10" '0-5' '3-5' 'USER B' "0-10" '6-10' '8-10' 'USER C' "11-20" '16-20' '16-17' 'USER D'
I am using Oracle 10g version and I have a database created and it contains around 9 tables and 25k records, as per my current requirement I need to add few more columns in the existing tables and those new columns are going to be filled with contents from multiple languages (as of now Chinese and English). I went through Oracle 10g globalization guide and I understood that, for my requirements I need to add my new columns with data types of either NVARCHAR or NCHAR.
With my about understanding I created the following table and tried to insert some Chinese characters as follows but it's now coming as expected and I'm getting inserted only "????" in my table columns
Find below the list of actions
>create table Employee(EmpId varchar(255), EmpName NCHAR(255)); >insert into Employee(EmpId, EmpName) values('280129','彭俊睦'); >select * from Employee; 280129 ¿¿¿
>insert into Employee(EmpId, EmpName) values('28018',N'彭俊睦'); >select * from Employee; 280129 ¿¿¿ 28018 ¿¿¿
When I run the “select * from v$nls_parameters;” query I’m getting the following data
NLS_LANGUAGE ---------à SIMPLIFIED CHINESE NLS_TERRITORY---------à AMERICA NLS_CURRENCY---------à $ NLS_ISO_CURRENCY---------à AMERICA NLS_NUMERIC_CHARACTERS---------à ., NLS_CALENDAR---------à GREGORIAN NLS_DATE_FORMAT---------à DD-MON-RR [Code] .....
I have some data in an Excel Sheet which is in Simplified Chinese, which I have to enter in oracle database. As soon as I paste the data into the insert statement on TOAD it gets converted into question marks.
Toad Version : 9.5.0.31 Oracle DBMS: 10.2.0.4.0 NLS_CHARACTERSET= UTF8
Chinese language is also installed on the instance with base language as US.
for making the query for following data,when we give start and end date then query need to calculate number of years.
if less than one year then return 0 if exact one year then return 1 if exact 1.5 years (18 months) then return 2 if exact 2 years (24 months) then also return 2 if exact 2.5 years (30 months) then return 3 if exact 3 years (36 months) then also return 3 if exact 3.5 years (42 months) then return 4 if exact 4 years (48 months) then also return 4 and so.
also we need to add leap year 1 day if exist in start and end date.
Our "client" is delivering data that contains an "age" field. However, they've put the AGE in DAYS instead of years, while our system can only work with years. So I needed to convert the age to years.
We are getting 2 parameters: LOWAGE and HIGHAGE (both in days). However, for the same "test" (laboratory test), we are also getting some other records
eg:
TEST 1 lowage = 0 upperage = 5 OTHER values = xxx TEST 1 lowage = 6 upperage = 100 OTHER values = yyy
So if the person would be 5 years or less, the values xxx would apply. If they are 6 years and older, the yyy values apply. Now, the problem is that we are not getting this data in years, but in days. And whichever function I try, the upperage from the first test also seems to be equal to the lowerage from the second test. And this gives an error, because both would apply to this person....
I am trying to generate a list of years, starting with 2010 and counting up through 5 years from the current date. For example, if it is currently 2013, the list would include 2010 through 2018. 2 years from now, I want the list to go from 2010 through 2020.
I am currently using
SELECT to_char(add_months(to_date('2010','YYYY'),12 * (rownum-1)),'YYYY') FROM dual CONNECT BY level <= 10to get a list with 10 entries.
How can I make this dynamic enough to return a variable number of records depending on the current year?
mentioned database is created with Character set = UTF8 and the National Character Set = AL16UTF16 and got the result for other languages (latin,german,french etc) but still Chinese language was not supported.
/* Formatted on 16/08/2012 21:55:39 (QP5 v5.215.12089.38647) */ CREATE OR REPLACE FUNCTION translator (p_words IN CLOB, -- words to be translated p_to IN VARCHAR2, -- language to translate to
I have a table named invoice_info(INV_NUMBER number,BILL_TO_NAME char(55),SHIP_TO_NAME char(55)) which is having chines characters in the BILL_TO_NAME & SHIP_TO_NAME fields.
If i am displaying this tables data on my sql developer it's showing data like some junk chars like ?????????¨¬???? for the fields BILL_TO_NAME & SHIP_TO_NAME .
How can i display them as chines chars on sql developer.
I have a table having data in different languages like English, Japanese and Chinese. I need to retrieve only those rows which are in Japanese. What all settings do I need to make. When am doing a normal select, rows in languages other than English are appearing as Junk data.
From the source database, the chinese characters are stored in some schema table. From the csscan result, there are convertiable, truncate, data lossy character. So, I have tried to use exp/imp for the conversion. However, all chinese characters are invalided and cannot be read anymore. How can I convert them from US7ASCCI to UTF8 database?
Also, I have tried build up another database with AMERICAN_AMERICA.ZHT16MSWIN950. The exp/imp is used for conversion again. The chinese characters are readable in AL32UTF8 database.
We have an existing db (10.2.0.4.0) and forms (11.1.2.1.0) application, that we're trying to extend to support Chinese characters. We're looking to add some unicode (nvarchar2) columns to existing tables, rather than converting the whole db charset. I've pasted my environment settings below. What I've found so far in trying to create a local (ie. running the form in Builder with local weblogic running) test form, is that I can insert the chars ok (using plsql developer) and the test form can display them correctly, but cannot write them back to the database. They appear as upside down question marks in any records the form has created.
So, how to get the form to write the characters back into the database correctly? 2) The chinese chars will only be relevant to a few forms inside the app, are there any settings local to the form that will enable unicode support, rather than setting at OS level. ie, an alter session, or equivalent? 3) Oracle Reprts doesn't appear to have an nchar datatype unlike Forms, is there anyway to get Reports (generating PDFs), to include Chinese?
I now have the chars writing back to the db ok. If you do it via an INSERT statement from inside the form, it doesn't work. It appears the value is sent to the db in the normal charset rather than the national charset, and it's written as a question mark. If you pass the value from the form into a back end stored proc though (which does the insert) it works okay.
I require to find the years between any given date range. For example what are the years between the dates '01/12/2010' and '01/02/2012'? Answer must be '2010,2011,2012'. how to code the query for this result?
I am trying to set a item to system date + 18 years. What type of formula or where to put such a thing. i tried putting- select add_months(sysdate,216) from dual; into the calculation-formula in property palette with no success.
We are getting problem with the Chinese character set. My current character set is as follows.
PARAMETER VALUE ---------------------------------------------------------------- ---------------------------------------------------------------- NLS_LANGUAGE AMERICAN NLS_TERRITORY AMERICA NLS_CURRENCY $ NLS_ISO_CURRENCY AMERICA NLS_NUMERIC_CHARACTERS ., [code]....
My column description for the table product is as follows.
when trying to insert Chinese character using the insert command below
insert into product(part_nbr,part_desc,cust_name) values('322341',unistr('功'),'test');
I am getting the value when selecting the same record using the select command
select a.part_nbr,a.part_desc,a.cust_name from product a where a.part_nbr='322341'322341¿test
When I running this command on TOAD
select a.rowid,a.part_nbr,a.part_desc,a.cust_name from product a where a.part_nbr='322341'
and manually editing/inserting '功' character in output from select command above. After that I am able to get the same Chinese character when I am running select next time.
I have two table APPLICATION_1 and APPLICATION_2, where user's login date is captured.There will be multiple records for each user.Same user may or may not be present in both tables.
The requirement is to find those users who have not logged-in in the last 3 years.
-- Test Case
DROP TABLE application_1; DROP TABLE application_2; CREATE TABLE application_1 ( seq NUMBER , user_id VARCHAR2(30),
[code].....
Using the below query I'm able to get the desired output.
SELECT user_id, MAX(login_date) last_login_date FROM ( SELECT user_id, MAX(login_date) login_date FROM application_1 GROUP BY user_id UNION ALL SELECT user_id, MAX(login_date) login_date FROM application_2 GROUP BY user_id ) GROUP BY user_id
I need to calcuate balance for last two cooprative years on input date.
example
if input date is-->"01-AUG-2012" if (month >=7) -->then i need to calculate from 01-july-2010 to 30-june-2011 and 01-july-2011 to 30-june-2012 and 01-july-2012 to input date.
if input date is-->"01-june-2012" if (month<7) -->then i need to calculate from 01-july-2009 to 30-june-2010 and 01-july-2010 to 30-june-2011 and 01-july-2011 to input date.
For Just learning purpose This is an example found in text book but while i try to execute it fails..I am trying to set Boolean flag to true if the hire_date is greater than 5 years otherwise boolean flag to false
DELARE v_Hire_date date :='12-Dec-2005'; v_five_years BOOLEAN; BEGIN IF [code].....
I'm trying to do a pivot query in oracle to get the years from a column and make a separate column for each. I found an example of the code to use on the internet and i changed it for my own tables but i'm getting errors. Namely a "FROM keyword not where expected" error at the beginning of the 'avg(...' statements.
I have copied the code used in
select stud_id, 2006, 2007, 2008, 2009 from ( select stud_id, avg(case when year=2006 then ((present/poss)*100) else null end) 2006, avg(case when year=2007 then ((present/poss)*100) else null end) 2007, avg(case when year=2008 then ((present/poss)*100) else null end) 2008, avg(case when year=2009 then ((present/poss)*100) else null end) 2009 from attendance.vw_all_attendance_perc group by stud_id );
->Col1 with experience in years entered as an integer ->Col2 with current date
I need to add another column as a date value adn for that i need to subtract Currentdate-Col1 when i tried currentdate-Col1 it just subtracted the days i need the formula to subtract years and give a date
I have worked in DB2 and all u need to do there was add the keyword years at the end but in oracle the same does not work